From 3f23dc91e45cfeab1cd2462a353a4b6708af7761 Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Mon, 22 Apr 2024 12:31:57 +0200 Subject: [PATCH] [hl] add -D hl_w_null_compare --- src/generators/genhl.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index aa60213418f..fff2c2b2489 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -95,6 +95,7 @@ type context = { cfunctions : fundecl DynArray.t; cconstants : (constval, (global * int array)) lookup; optimize : bool; + w_null_compare : bool; overrides : (string * path, bool) Hashtbl.t; defined_funs : (int,unit) Hashtbl.t; is_macro : bool; @@ -1504,6 +1505,8 @@ and jump_expr ctx e jcond = | HNull (HBool as ti1), (HBool as ti2) | (HBool as ti1), HNull (HBool as ti2) -> + if ctx.w_null_compare then + ctx.com.warning WGenerator [] (Printf.sprintf "Comparing Null with T: %s %s %s" (tstr t1) (s_binop jop) (tstr t2)) e.epos; let t1,t2,e1,e2 = if is_nullt t2 then t2,t1,e2,e1 else t1,t2,e1,e2 in let r1 = eval_expr ctx e1 in hold ctx r1; @@ -1546,6 +1549,8 @@ and jump_expr ctx e jcond = | (HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 as ti1), HNull (HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 as ti2) | HNull (HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 as ti1), HNull (HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 as ti2) -> + if ctx.w_null_compare && (is_nullt t1 && (not (is_nullt t2)) || ((not (is_nullt t1)) && is_nullt t2)) then + ctx.com.warning WGenerator [] (Printf.sprintf "Comparing Null with T: %s %s %s" (tstr t1) (s_binop jop) (tstr t2)) e.epos; let r1 = eval_expr ctx e1 in hold ctx r1; let jnull1 = if is_nullt t1 then jump ctx (fun i -> OJNull (r1, i)) else (fun i -> ()) in @@ -4113,6 +4118,7 @@ let create_context com is_macro dump = com = com; is_macro = is_macro; optimize = not (Common.raw_defined com "hl_no_opt"); + w_null_compare = Common.raw_defined com "hl_w_null_compare"; dump_out = if dump then Some (IO.output_channel (open_out_bin "dump/hlopt.txt")) else None; m = method_context 0 HVoid null_capture false; cints = new_lookup();