diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 41e27cfc2..fc09dafc5 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -940,7 +940,14 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s (* translating the operands. *) let res_trans_e1 = instruction trans_state' s1 in let (exp1, typ1) as exp_typ1 = res_trans_e1.return in - let trans_state'' = {trans_state' with var_exp_typ= Some exp_typ1} in + let var_exp_typ = + match binary_operator_info.Clang_ast_t.boi_kind with + | `Assign -> + Some exp_typ1 + | _ -> + None + in + let trans_state'' = {trans_state' with var_exp_typ} in let res_trans_e2 = (* translation of s2 is done taking care of block special case *) exec_with_block_priority_exception instruction trans_state'' s2 stmt_info diff --git a/infer/tests/codetoanalyze/cpp/frontend/initialization/init_list.cpp b/infer/tests/codetoanalyze/cpp/frontend/initialization/init_list.cpp index f96654ff8..9e1ced4cb 100644 --- a/infer/tests/codetoanalyze/cpp/frontend/initialization/init_list.cpp +++ b/infer/tests/codetoanalyze/cpp/frontend/initialization/init_list.cpp @@ -47,4 +47,7 @@ void list_init() { Y& yref = y; Y ty[3] = {{1, {2, nullptr}}, y, yref}; } + +void init_in_binop(int x) { x = -x & ~int{0}; } + } // namespace init_list diff --git a/infer/tests/codetoanalyze/cpp/frontend/initialization/init_list.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/initialization/init_list.cpp.dot index 9a220f7b3..5260cc145 100644 --- a/infer/tests/codetoanalyze/cpp/frontend/initialization/init_list.cpp.dot +++ b/infer/tests/codetoanalyze/cpp/frontend/initialization/init_list.cpp.dot @@ -1,5 +1,16 @@ /* @generated */ digraph cfg { +"init_in_binop#init_list#8348250075128359911.7adaa67964536570064366a92056cf46_1" [label="1: Start init_list::init_in_binop\nFormals: x:int\nLocals: 0$?%__sil_tmpSIL_init_list__n$2:int \n DECLARE_LOCALS(&return,&0$?%__sil_tmpSIL_init_list__n$2); [line 51, column 1]\n " color=yellow style=filled] + + + "init_in_binop#init_list#8348250075128359911.7adaa67964536570064366a92056cf46_1" -> "init_in_binop#init_list#8348250075128359911.7adaa67964536570064366a92056cf46_3" ; +"init_in_binop#init_list#8348250075128359911.7adaa67964536570064366a92056cf46_2" [label="2: Exit init_list::init_in_binop \n " color=yellow style=filled] + + +"init_in_binop#init_list#8348250075128359911.7adaa67964536570064366a92056cf46_3" [label="3: BinaryOperatorStmt: Assign \n n$1=*&x:int [line 51, column 34]\n *&0$?%__sil_tmpSIL_init_list__n$2:int=0 [line 51, column 42]\n *&x:int=(-n$1 & ~&0$?%__sil_tmpSIL_init_list__n$2) [line 51, column 29]\n " shape="box"] + + + "init_in_binop#init_list#8348250075128359911.7adaa67964536570064366a92056cf46_3" -> "init_in_binop#init_list#8348250075128359911.7adaa67964536570064366a92056cf46_2" ; "list_init#init_list#18348854466346904105.0126b9f1f80f91b73d5fbdbf2bc60754_1" [label="1: Start init_list::list_init\nFormals: \nLocals: ty:init_list::Y[3*24] yref:init_list::Y& y:init_list::Y ti:int[4*4] \n DECLARE_LOCALS(&return,&ty,&yref,&y,&ti); [line 44, column 1]\n " color=yellow style=filled] diff --git a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp index 921d94212..efc618953 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp +++ b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp @@ -476,4 +476,6 @@ class Exceptions { } }; +void init_in_binop_bad(int x) { x = -x & ~int{0}; } + } // namespace dead_stores diff --git a/infer/tests/codetoanalyze/cpp/liveness/issues.exp b/infer/tests/codetoanalyze/cpp/liveness/issues.exp index d7cd4428e..067a2fd94 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/issues.exp +++ b/infer/tests/codetoanalyze/cpp/liveness/issues.exp @@ -10,6 +10,7 @@ codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_then_live_bad, 1, codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::easy_bad, 0, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_capture_no_call_bad, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_capture_reassign_bad, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_in_binop_bad, 0, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::lambda_bad::lambda_dead_stores.cpp:145:11_operator(), 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus1_bad, 2, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus2_bad, 2, DEAD_STORE, no_bucket, ERROR, [Write of unused value]