From 81e3dc5069b105fe47ee379c41dc8430b8ad57ce Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Mon, 3 Feb 2020 05:36:16 -0800 Subject: [PATCH] [HIL] do not crash on confusing function call expressions Summary: When the expression resolving to a function to be called could not be translated to either a proc name or at least an access path, the HIL translation code would crash. However, this is perfectly possible. Moreover, no one actually uses the payload of the `Indirect` datatype so no complication arises from generilising its type to `HilExp.t`, as done in this diff. Reviewed By: ngorogiannis Differential Revision: D19691127 fbshipit-source-id: 4c0400ab7 --- infer/src/IR/HilInstr.ml | 10 ++++------ infer/src/IR/HilInstr.mli | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/infer/src/IR/HilInstr.ml b/infer/src/IR/HilInstr.ml index 57645600f..b14a20ca5 100644 --- a/infer/src/IR/HilInstr.ml +++ b/infer/src/IR/HilInstr.ml @@ -9,13 +9,13 @@ open! IStd module F = Format module L = Logging -type call = Direct of Procname.t | Indirect of HilExp.AccessExpression.t [@@deriving compare] +type call = Direct of Procname.t | Indirect of HilExp.t [@@deriving compare] let pp_call fmt = function | Direct pname -> Procname.pp fmt pname - | Indirect access_expr -> - F.fprintf fmt "*%a" HilExp.AccessExpression.pp access_expr + | Indirect expr -> + F.fprintf fmt "*%a" HilExp.pp expr type t = @@ -88,10 +88,8 @@ let of_sil ~include_array_indexes ~f_resolve_id (instr : Sil.instr) = match exp_of_sil call_exp Typ.void with | Constant (Cfun procname) | Closure (procname, _) -> Direct procname - | HilExp.AccessExpression access_expr -> - Indirect access_expr | call_exp -> - L.(die InternalError) "Unexpected call expression %a" HilExp.pp call_exp + Indirect call_exp in let formals = List.map ~f:(fun (exp, typ) -> exp_of_sil exp typ) formals in Instr (Call (hil_ret, hil_call, formals, call_flags, loc)) diff --git a/infer/src/IR/HilInstr.mli b/infer/src/IR/HilInstr.mli index 15c55bdda..349e2f4b2 100644 --- a/infer/src/IR/HilInstr.mli +++ b/infer/src/IR/HilInstr.mli @@ -9,7 +9,7 @@ open! IStd module F = Format (** type of a procedure call; either direct or via function pointer *) -type call = Direct of Procname.t | Indirect of HilExp.AccessExpression.t [@@deriving compare] +type call = Direct of Procname.t | Indirect of HilExp.t [@@deriving compare] val pp_call : F.formatter -> call -> unit [@@warning "-32"]