From 5b3c2c09014d984f577a085b4bb122e7fee30ee6 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Fri, 8 Sep 2017 09:19:21 -0700 Subject: [PATCH] [clang] fix evaluation order bug discovered by building with OCaml 4.05.0 Summary: The behaviour of infer was observed to be different in 4.04.2 vs (4.05.0 or 4.04.2+flambda). Investigating further, the behaviour is also different in byte vs native versions of infer under 4.04.2. Looking at the Changelog of 4.05.0 (thanks mbouaziz), there are fixes for inconsistent behaviours between byte and native relative to evaluation order. Lots of debugging later, this 1 line patch is born. Also use `List.concat_map` instead of re-implementing it. Reviewed By: jberdine Differential Revision: D5793809 fbshipit-source-id: 374fb4c --- infer/src/clang/cTrans.ml | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index af20dd830..82c478feb 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -173,21 +173,18 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s (Exp.Var id, typ) in let make_arg typ (id, _, _) = (id, typ) in - let rec f es = - match es with - | [] - -> [] - | (Exp.Closure {name; captured_vars}, ({Typ.desc= Tptr ({Typ.desc= Tfun _}, _)} as t)) :: es' - -> let app = - let function_name = make_function_name t name in - let args = List.map ~f:(make_arg t) captured_vars in - function_name :: args - in - app @ f es' - | e :: es' - -> e :: f es' - in - (f exps, !insts) + let f = function + | Exp.Closure {name; captured_vars}, ({Typ.desc= Tptr ({Typ.desc= Tfun _}, _)} as t) + -> let function_name = make_function_name t name in + let args = List.map ~f:(make_arg t) captured_vars in + function_name :: args + | e + -> [e] + in + (* evaluation order matters here *) + let exps' = List.concat_map ~f exps in + let insts' = !insts in + (exps', insts') let collect_exprs res_trans_list = List.concat_map ~f:(fun res_trans -> res_trans.exps) res_trans_list