diff --git a/infer/src/clang/cTrans_utils.ml b/infer/src/clang/cTrans_utils.ml index 6f9ff327a..29684bde0 100644 --- a/infer/src/clang/cTrans_utils.ml +++ b/infer/src/clang/cTrans_utils.ml @@ -621,7 +621,7 @@ let rec contains_opaque_value_expr s = (* checks if a unary operator is a logic negation applied to integers*) let is_logical_negation_of_int tenv ei uoi = match CTypes_decl.type_ptr_to_sil_type tenv ei.Clang_ast_t.ei_type_ptr, uoi.Clang_ast_t.uoi_kind with - | Typ.Tint Typ.IInt,`LNot -> true + | Typ.Tint _,`LNot -> true | _, _ -> false let rec is_block_stmt stmt = diff --git a/infer/tests/codetoanalyze/c/frontend/arithmetic/negate.c b/infer/tests/codetoanalyze/c/frontend/arithmetic/negate.c new file mode 100644 index 000000000..ff63d9a4a --- /dev/null +++ b/infer/tests/codetoanalyze/c/frontend/arithmetic/negate.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +int neg_int(int a) { return !a; } + +int neg_char(char a) { return !a; } + +int neg_bool(_Bool a) { return !a; } diff --git a/infer/tests/codetoanalyze/c/frontend/arithmetic/negate.c.dot b/infer/tests/codetoanalyze/c/frontend/arithmetic/negate.c.dot new file mode 100644 index 000000000..7870a2177 --- /dev/null +++ b/infer/tests/codetoanalyze/c/frontend/arithmetic/negate.c.dot @@ -0,0 +1,99 @@ +/* @generated */ +digraph iCFG { +24 [label="24: Return Stmt \n n$2=*&SIL_temp_conditional___n$0:int [line 14]\n *&return:int =n$2 [line 14]\n " shape="box"] + + + 24 -> 18 ; +23 [label="23: ConditinalStmt Branch \n *&SIL_temp_conditional___n$0:int =1 [line 14]\n " shape="box"] + + + 23 -> 19 ; +22 [label="22: ConditinalStmt Branch \n *&SIL_temp_conditional___n$0:int =0 [line 14]\n " shape="box"] + + + 22 -> 19 ; +21 [label="21: Prune (false branch) \n n$1=*&a:_Bool [line 14]\n PRUNE((n$1 == 0), false); [line 14]\n " shape="invhouse"] + + + 21 -> 23 ; +20 [label="20: Prune (true branch) \n n$1=*&a:_Bool [line 14]\n PRUNE((n$1 != 0), true); [line 14]\n " shape="invhouse"] + + + 20 -> 22 ; +19 [label="19: + \n " ] + + + 19 -> 24 ; +18 [label="18: Exit neg_bool \n " color=yellow style=filled] + + +17 [label="17: Start neg_bool\nFormals: a:_Bool \nLocals: SIL_temp_conditional___n$0:int \n DECLARE_LOCALS(&return,&SIL_temp_conditional___n$0); [line 14]\n " color=yellow style=filled] + + + 17 -> 20 ; + 17 -> 21 ; +16 [label="16: Return Stmt \n n$2=*&SIL_temp_conditional___n$0:int [line 12]\n *&return:int =n$2 [line 12]\n " shape="box"] + + + 16 -> 10 ; +15 [label="15: ConditinalStmt Branch \n *&SIL_temp_conditional___n$0:int =1 [line 12]\n " shape="box"] + + + 15 -> 11 ; +14 [label="14: ConditinalStmt Branch \n *&SIL_temp_conditional___n$0:int =0 [line 12]\n " shape="box"] + + + 14 -> 11 ; +13 [label="13: Prune (false branch) \n n$1=*&a:char [line 12]\n PRUNE((n$1 == 0), false); [line 12]\n " shape="invhouse"] + + + 13 -> 15 ; +12 [label="12: Prune (true branch) \n n$1=*&a:char [line 12]\n PRUNE((n$1 != 0), true); [line 12]\n " shape="invhouse"] + + + 12 -> 14 ; +11 [label="11: + \n " ] + + + 11 -> 16 ; +10 [label="10: Exit neg_char \n " color=yellow style=filled] + + +9 [label="9: Start neg_char\nFormals: a:char \nLocals: SIL_temp_conditional___n$0:int \n DECLARE_LOCALS(&return,&SIL_temp_conditional___n$0); [line 12]\n " color=yellow style=filled] + + + 9 -> 12 ; + 9 -> 13 ; +8 [label="8: Return Stmt \n n$2=*&SIL_temp_conditional___n$0:int [line 10]\n *&return:int =n$2 [line 10]\n " shape="box"] + + + 8 -> 2 ; +7 [label="7: ConditinalStmt Branch \n *&SIL_temp_conditional___n$0:int =1 [line 10]\n " shape="box"] + + + 7 -> 3 ; +6 [label="6: ConditinalStmt Branch \n *&SIL_temp_conditional___n$0:int =0 [line 10]\n " shape="box"] + + + 6 -> 3 ; +5 [label="5: Prune (false branch) \n n$1=*&a:int [line 10]\n PRUNE((n$1 == 0), false); [line 10]\n " shape="invhouse"] + + + 5 -> 7 ; +4 [label="4: Prune (true branch) \n n$1=*&a:int [line 10]\n PRUNE((n$1 != 0), true); [line 10]\n " shape="invhouse"] + + + 4 -> 6 ; +3 [label="3: + \n " ] + + + 3 -> 8 ; +2 [label="2: Exit neg_int \n " color=yellow style=filled] + + +1 [label="1: Start neg_int\nFormals: a:int \nLocals: SIL_temp_conditional___n$0:int \n DECLARE_LOCALS(&return,&SIL_temp_conditional___n$0); [line 10]\n " color=yellow style=filled] + + + 1 -> 4 ; + 1 -> 5 ; +} diff --git a/infer/tests/frontend/c/ArithmeticExpTest.java b/infer/tests/frontend/c/ArithmeticExpTest.java index 8c1ed6b4a..ec7316fa0 100644 --- a/infer/tests/frontend/c/ArithmeticExpTest.java +++ b/infer/tests/frontend/c/ArithmeticExpTest.java @@ -53,4 +53,10 @@ public class ArithmeticExpTest { frontendTest("int_const.c"); } + @Test + public void whenCaptureRunOnNegateThenDotFilesAreTheSame() + throws InterruptedException, IOException, InferException { + frontendTest("negate.c"); + } + }