[clang] fix some loops with no brackets

Summary:
When the body of the loop doesn't created a node then they don't get
wired correctly to the rest of the loop and end up dangling. Force node
creation to fix that.

Fixes https://github.com/facebook/infer/issues/1373

Reviewed By: ezgicicek

Differential Revision: D25804185

fbshipit-source-id: 85108bdd9
master
Jules Villard 4 years ago committed by Facebook GitHub Bot
parent ad45bbe28d
commit 2ac2f019df

@ -84,6 +84,7 @@ module Node = struct
| IfStmtBranch
| InitializeDynamicArrayLength
| InitListExp
| LoopBody
| MessageCall of string
| MethodBody
| MonitorEnter
@ -345,6 +346,8 @@ module Node = struct
F.pp_print_string fmt "Initialize dynamic array length"
| InitListExp ->
F.pp_print_string fmt "InitListExp"
| LoopBody ->
F.pp_print_string fmt "LoopBody"
| MessageCall selector ->
F.fprintf fmt "Message Call: %s" selector
| MethodBody ->

@ -65,6 +65,7 @@ module Node : sig
| IfStmtBranch
| InitializeDynamicArrayLength
| InitListExp
| LoopBody
| MessageCall of string
| MethodBody
| MonitorEnter

@ -2194,7 +2194,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let trans_state_body =
{trans_state with succ_nodes= body_succ_nodes; continuation= body_continuation}
in
instruction trans_state_body (Loops.get_body loop_kind)
exec_with_node_creation LoopBody ~f:instruction trans_state_body (Loops.get_body loop_kind)
in
let join_succ_nodes =
match loop_kind with

@ -5,10 +5,16 @@
* LICENSE file in the root directory of this source tree.
*/
int main() {
int simple_for_loop() {
int j = 0;
for (int i = 0; i < 10; i++) {
j += j;
}
return 0;
}
void for_loop_no_brackets() {
int j = 0;
for (int i = 0; i < 1; i++)
j;
}

@ -1,47 +1,87 @@
/* @generated */
digraph cfg {
"main.fad58de7366495db4650cfefac2fcd61_1" [label="1: Start main\nFormals: \nLocals: i:int j:int \n " color=yellow style=filled]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_1" [label="1: Start for_loop_no_brackets\nFormals: \nLocals: i:int j:int \n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_1" -> "main.fad58de7366495db4650cfefac2fcd61_11" ;
"main.fad58de7366495db4650cfefac2fcd61_2" [label="2: Exit main \n " color=yellow style=filled]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_1" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_10" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_2" [label="2: Exit for_loop_no_brackets \n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_3" [label="3: Return Stmt \n *&return:int=0 [line 13, column 3]\n " shape="box"]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_3" [label="3: + \n " ]
"main.fad58de7366495db4650cfefac2fcd61_3" -> "main.fad58de7366495db4650cfefac2fcd61_2" ;
"main.fad58de7366495db4650cfefac2fcd61_4" [label="4: + \n " ]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_3" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_6" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_4" [label="4: DeclStmt \n VARIABLE_DECLARED(i:int); [line 18, column 8]\n *&i:int=0 [line 18, column 8]\n " shape="box"]
"main.fad58de7366495db4650cfefac2fcd61_4" -> "main.fad58de7366495db4650cfefac2fcd61_7" ;
"main.fad58de7366495db4650cfefac2fcd61_5" [label="5: DeclStmt \n VARIABLE_DECLARED(i:int); [line 10, column 8]\n *&i:int=0 [line 10, column 8]\n " shape="box"]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_4" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_3" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_5" [label="5: UnaryOperator \n n$0=*&i:int [line 18, column 26]\n *&i:int=(n$0 + 1) [line 18, column 26]\n " shape="box"]
"main.fad58de7366495db4650cfefac2fcd61_5" -> "main.fad58de7366495db4650cfefac2fcd61_4" ;
"main.fad58de7366495db4650cfefac2fcd61_6" [label="6: UnaryOperator \n n$0=*&i:int [line 10, column 27]\n *&i:int=(n$0 + 1) [line 10, column 27]\n " shape="box"]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_5" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_3" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_6" [label="6: BinaryOperatorStmt: LT \n n$1=*&i:int [line 18, column 19]\n " shape="box"]
"main.fad58de7366495db4650cfefac2fcd61_6" -> "main.fad58de7366495db4650cfefac2fcd61_4" ;
"main.fad58de7366495db4650cfefac2fcd61_7" [label="7: BinaryOperatorStmt: LT \n n$1=*&i:int [line 10, column 19]\n " shape="box"]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_6" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_7" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_6" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_8" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_7" [label="7: Prune (true branch, for loop) \n PRUNE((n$1 < 1), true); [line 18, column 19]\n " shape="invhouse"]
"main.fad58de7366495db4650cfefac2fcd61_7" -> "main.fad58de7366495db4650cfefac2fcd61_8" ;
"main.fad58de7366495db4650cfefac2fcd61_7" -> "main.fad58de7366495db4650cfefac2fcd61_9" ;
"main.fad58de7366495db4650cfefac2fcd61_8" [label="8: Prune (true branch, for loop) \n PRUNE((n$1 < 10), true); [line 10, column 19]\n " shape="invhouse"]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_7" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_9" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_8" [label="8: Prune (false branch, for loop) \n PRUNE(!(n$1 < 1), false); [line 18, column 19]\n " shape="invhouse"]
"main.fad58de7366495db4650cfefac2fcd61_8" -> "main.fad58de7366495db4650cfefac2fcd61_10" ;
"main.fad58de7366495db4650cfefac2fcd61_9" [label="9: Prune (false branch, for loop) \n PRUNE(!(n$1 < 10), false); [line 10, column 19]\n " shape="invhouse"]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_8" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_2" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_9" [label="9: LoopBody \n n$2=*&j:int [line 19, column 5]\n " shape="box"]
"main.fad58de7366495db4650cfefac2fcd61_9" -> "main.fad58de7366495db4650cfefac2fcd61_3" ;
"main.fad58de7366495db4650cfefac2fcd61_10" [label="10: BinaryOperatorStmt: AddAssign \n n$2=*&j:int [line 11, column 10]\n n$3=*&j:int [line 11, column 5]\n *&j:int=(n$3 + n$2) [line 11, column 5]\n " shape="box"]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_9" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_5" ;
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_10" [label="10: DeclStmt \n VARIABLE_DECLARED(j:int); [line 17, column 3]\n *&j:int=0 [line 17, column 3]\n " shape="box"]
"main.fad58de7366495db4650cfefac2fcd61_10" -> "main.fad58de7366495db4650cfefac2fcd61_6" ;
"main.fad58de7366495db4650cfefac2fcd61_11" [label="11: DeclStmt \n VARIABLE_DECLARED(j:int); [line 9, column 3]\n *&j:int=0 [line 9, column 3]\n " shape="box"]
"for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_10" -> "for_loop_no_brackets.4c9da26592fb7fb2077b8ad5de66fe11_4" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_1" [label="1: Start simple_for_loop\nFormals: \nLocals: i:int j:int \n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_11" -> "main.fad58de7366495db4650cfefac2fcd61_5" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_1" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_11" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_2" [label="2: Exit simple_for_loop \n " color=yellow style=filled]
"simple_for_loop.620d527928c080a35fd7b56855111df4_3" [label="3: Return Stmt \n *&return:int=0 [line 13, column 3]\n " shape="box"]
"simple_for_loop.620d527928c080a35fd7b56855111df4_3" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_2" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_4" [label="4: + \n " ]
"simple_for_loop.620d527928c080a35fd7b56855111df4_4" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_7" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_5" [label="5: DeclStmt \n VARIABLE_DECLARED(i:int); [line 10, column 8]\n *&i:int=0 [line 10, column 8]\n " shape="box"]
"simple_for_loop.620d527928c080a35fd7b56855111df4_5" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_4" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_6" [label="6: UnaryOperator \n n$0=*&i:int [line 10, column 27]\n *&i:int=(n$0 + 1) [line 10, column 27]\n " shape="box"]
"simple_for_loop.620d527928c080a35fd7b56855111df4_6" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_4" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_7" [label="7: BinaryOperatorStmt: LT \n n$1=*&i:int [line 10, column 19]\n " shape="box"]
"simple_for_loop.620d527928c080a35fd7b56855111df4_7" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_8" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_7" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_9" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_8" [label="8: Prune (true branch, for loop) \n PRUNE((n$1 < 10), true); [line 10, column 19]\n " shape="invhouse"]
"simple_for_loop.620d527928c080a35fd7b56855111df4_8" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_10" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_9" [label="9: Prune (false branch, for loop) \n PRUNE(!(n$1 < 10), false); [line 10, column 19]\n " shape="invhouse"]
"simple_for_loop.620d527928c080a35fd7b56855111df4_9" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_3" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_10" [label="10: BinaryOperatorStmt: AddAssign \n n$2=*&j:int [line 11, column 10]\n n$3=*&j:int [line 11, column 5]\n *&j:int=(n$3 + n$2) [line 11, column 5]\n " shape="box"]
"simple_for_loop.620d527928c080a35fd7b56855111df4_10" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_6" ;
"simple_for_loop.620d527928c080a35fd7b56855111df4_11" [label="11: DeclStmt \n VARIABLE_DECLARED(j:int); [line 9, column 3]\n *&j:int=0 [line 9, column 3]\n " shape="box"]
"simple_for_loop.620d527928c080a35fd7b56855111df4_11" -> "simple_for_loop.620d527928c080a35fd7b56855111df4_5" ;
}

Loading…
Cancel
Save