From 637fff5247e201f23ac093c77189f2900401d210 Mon Sep 17 00:00:00 2001 From: Benno Stein Date: Fri, 20 Sep 2019 06:27:37 -0700 Subject: [PATCH] [sledge] Check for intrinsic calls in used-globals analysis Summary: Fixes a bug where are all calls are treated as intrinsics in used globals analysis, since exec_intrinsic is invoked at _all_ calls to determine which are intrinsic, not only at call sites known to target intrinsics. Reviewed By: jberdine Differential Revision: D17499406 fbshipit-source-id: 41f7621f2 --- sledge/src/domain/used_globals.ml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sledge/src/domain/used_globals.ml b/sledge/src/domain/used_globals.ml index c2fb0413a..ce7abffed 100644 --- a/sledge/src/domain/used_globals.ml +++ b/sledge/src/domain/used_globals.ml @@ -43,9 +43,20 @@ let exec_inst st inst = [%Trace.retn fun {pf} -> Result.iter ~f:(fun uses -> pf "post:{%a}" pp uses)] -let exec_intrinsic ~skip_throw:_ st _ _ actuals = - List.fold actuals ~init:st ~f:(fun s a -> used_globals ~init:s a) - |> fun res -> Some (Ok res) +let exec_intrinsic ~skip_throw:_ st _ intrinsic actuals = + let name = Var.name intrinsic in + if + List.exists + [ "malloc"; "aligned_alloc"; "calloc"; "posix_memalign"; "realloc" + ; "mallocx"; "rallocx"; "xallocx"; "sallocx"; "dallocx"; "sdallocx" + ; "nallocx"; "malloc_usable_size"; "mallctl"; "mallctlnametomib" + ; "mallctlbymib"; "malloc_stats_print"; "strlen" + ; "__cxa_allocate_exception"; "_ZN5folly13usingJEMallocEv" ] + ~f:(String.equal name) + then + List.fold actuals ~init:st ~f:(fun s a -> used_globals ~init:s a) + |> fun res -> Some (Ok res) + else None type from_call = t [@@deriving sexp_of]