Skip to content

Commit 7855d6e

Browse files
dulmarodfacebook-github-bot-1
authored andcommitted
Fix the order of the translated stmts inside compound stmt
Reviewed By: akotulski Differential Revision: D2834462 fb-gh-sync-id: d7c2ba6
1 parent a7371d5 commit 7855d6e

5 files changed

Lines changed: 108 additions & 6 deletions

File tree

infer/src/clang/cTrans.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ struct
917917
res_state
918918

919919
and compoundStmt_trans trans_state stmt_info stmt_list =
920-
instructions trans_state (IList.rev stmt_list)
920+
instructions trans_state stmt_list
921921

922922
and conditionalOperator_trans trans_state stmt_info stmt_list expr_info =
923923
let context = trans_state.context in
@@ -2057,8 +2057,8 @@ struct
20572057
{ root_nodes = res_trans_tail.root_nodes;
20582058
leaf_nodes = [];
20592059
ids = res_trans_s.ids @ res_trans_tail.ids;
2060-
instrs = res_trans_s.instrs @ res_trans_tail.instrs;
2061-
exps = res_trans_s.exps @ res_trans_tail.exps }
2060+
instrs = res_trans_tail.instrs @ res_trans_s.instrs;
2061+
exps = res_trans_tail.exps @ res_trans_s.exps }
20622062

20632063
and get_clang_stmt_trans stmt_list =
20642064
let instruction' = fun stmt -> fun trans_state -> instruction trans_state stmt in
@@ -2073,7 +2073,8 @@ struct
20732073

20742074
(** Given a translation state, this function translates a list of clang statements. *)
20752075
and instructions trans_state stmt_list =
2076-
exec_trans_instrs trans_state (get_clang_stmt_trans stmt_list)
2076+
let rev_stmt_list = IList.rev stmt_list in
2077+
exec_trans_instrs trans_state (get_clang_stmt_trans rev_stmt_list)
20772078

20782079
and expression_trans context stmt warning =
20792080
let trans_state = {

infer/tests/codetoanalyze/c/frontend/nestedoperators/gnuexpr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ int main() {
1313
y = ({int X = 4; X;});
1414
return 0;
1515
}
16+
17+
int test(int* p) {
18+
return ({
19+
int x = *p;
20+
int y = 1;
21+
x + y;
22+
});
23+
}

infer/tests/codetoanalyze/c/frontend/nestedoperators/gnuexpr.c.dot

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
digraph iCFG {
2+
8 [label="8: Return Stmt \n n$2=*&p:int * [line 19]\n n$3=*n$2:int [line 19]\n *&x:int =n$3 [line 19]\n *&y:int =1 [line 20]\n n$0=*&x:int [line 21]\n n$1=*&y:int [line 21]\n n$4=*(n$0 + n$1):int [line 18]\n *&return:int =n$4 [line 18]\n REMOVE_TEMPS(n$4,n$0,n$1,n$2,n$3); [line 18]\n NULLIFY(&p,false); [line 18]\n NULLIFY(&x,false); [line 18]\n NULLIFY(&y,false); [line 18]\n APPLY_ABSTRACTION; [line 18]\n " shape="box"]
3+
4+
5+
8 -> 7 ;
6+
7 [label="7: Exit test \n " color=yellow style=filled]
7+
8+
9+
6 [label="6: Start test\nFormals: p:int *\nLocals: y:int x:int \n DECLARE_LOCALS(&return,&y,&x); [line 17]\n NULLIFY(&x,false); [line 17]\n NULLIFY(&y,false); [line 17]\n " color=yellow style=filled]
10+
11+
12+
6 -> 8 ;
213
5 [label="5: DeclStmt \n *&y:int =3 [line 11]\n NULLIFY(&y,false); [line 11]\n " shape="box"]
314

415

516
5 -> 4 ;
6-
4 [label="4: BinaryOperatorStmt: Assign \n n$0=*&X:int [line 13]\n *&X:int =4 [line 13]\n n$1=*&X:int [line 13]\n *&y:int =n$1 [line 13]\n REMOVE_TEMPS(n$1,n$0); [line 13]\n NULLIFY(&X,false); [line 13]\n NULLIFY(&y,false); [line 13]\n " shape="box"]
17+
4 [label="4: BinaryOperatorStmt: Assign \n *&X:int =4 [line 13]\n n$0=*&X:int [line 13]\n n$1=*n$0:int [line 13]\n *&y:int =n$1 [line 13]\n REMOVE_TEMPS(n$1,n$0); [line 13]\n NULLIFY(&X,false); [line 13]\n NULLIFY(&y,false); [line 13]\n " shape="box"]
718

819

920
4 -> 3 ;
@@ -14,7 +25,7 @@ digraph iCFG {
1425
2 [label="2: Exit main \n " color=yellow style=filled]
1526

1627

17-
1 [label="1: Start main\nFormals: \nLocals: X:int y:int \n DECLARE_LOCALS(&return,&X,&y); [line 10]\n NULLIFY(&y,false); [line 10]\n " color=yellow style=filled]
28+
1 [label="1: Start main\nFormals: \nLocals: X:int y:int \n DECLARE_LOCALS(&return,&X,&y); [line 10]\n NULLIFY(&X,false); [line 10]\n NULLIFY(&y,false); [line 10]\n " color=yellow style=filled]
1829

1930

2031
1 -> 5 ;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2016 - present Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <Foundation/Foundation.h>
11+
12+
13+
#define INITIALIZE_AND_RETURN_STATIC(...) ({ \
14+
static __typeof__(__VA_ARGS__) static_storage; \
15+
static dispatch_once_t once_token; \
16+
dispatch_once(&once_token, ^{ static_storage = (__VA_ARGS__); }); \
17+
static_storage; \
18+
})
19+
20+
id test() {
21+
return INITIALIZE_AND_RETURN_STATIC([NSObject new]);
22+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2016 - present Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
package endtoend.objc;
11+
12+
import static org.hamcrest.MatcherAssert.assertThat;
13+
import static utils.matchers.ResultContainsExactly.containsExactly;
14+
15+
import com.google.common.collect.ImmutableList;
16+
17+
import org.junit.BeforeClass;
18+
import org.junit.ClassRule;
19+
import org.junit.Test;
20+
21+
import java.io.IOException;
22+
23+
import utils.DebuggableTemporaryFolder;
24+
import utils.InferException;
25+
import utils.InferResults;
26+
import utils.InferRunner;
27+
28+
public class DispatchInMacroTest {
29+
30+
public static final String FILE =
31+
"infer/tests/codetoanalyze/objc/frontend/block/dispatch_in_macro.m";
32+
33+
34+
private static ImmutableList<String> inferCmd;
35+
36+
public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE";
37+
38+
@ClassRule
39+
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
40+
41+
@BeforeClass
42+
public static void runInfer() throws InterruptedException, IOException {
43+
inferCmd = InferRunner.createObjCInferCommand(folder, FILE);
44+
}
45+
46+
@Test
47+
public void whenInferRunsOnAtomicProperty()
48+
throws InterruptedException, IOException, InferException {
49+
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
50+
assertThat(
51+
"Results should not contain null dereference",
52+
inferResults,
53+
containsExactly(
54+
NULL_DEREFERENCE,
55+
FILE,
56+
new String[]{}
57+
)
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)