Summary: public Add qualifiers to global varible names. It affects both normal global vars and class static fields Reviewed By: dulmarod Differential Revision: D2699927 fb-gh-sync-id: 1471fafmaster
parent
a06ce9ca0e
commit
9353c7bbfd
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 - 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace f1 {
|
||||||
|
int val;
|
||||||
|
|
||||||
|
struct A {
|
||||||
|
static int v;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace f2 {
|
||||||
|
int val;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct B {
|
||||||
|
static int v;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct C : public B { };
|
||||||
|
|
||||||
|
int div0_namepace_res() {
|
||||||
|
f1::val = 1;
|
||||||
|
f2::val = -2;
|
||||||
|
return 1 / (f1::val + f2::val + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int div0_static_field() {
|
||||||
|
B::v= 1;
|
||||||
|
f1::A::v = -2;
|
||||||
|
return 1 / (f1::A::v + B::v + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int div0_static_field_member_access(f1::A *a, C *b) {
|
||||||
|
a->v = 1;
|
||||||
|
b->v = -2;
|
||||||
|
return 1 / (f1::A::v + B::v + 1);
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
digraph iCFG {
|
||||||
|
15 [label="15: BinaryOperatorStmt: Assign \n *&#GB$f1::A::v:int =1 [line 42]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
15 -> 14 ;
|
||||||
|
14 [label="14: BinaryOperatorStmt: Assign \n *&#GB$B::v:int =-2 [line 43]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
14 -> 13 ;
|
||||||
|
13 [label="13: Return Stmt \n n$0=*&#GB$f1::A::v:int [line 44]\n n$1=*&#GB$B::v:int [line 44]\n *&return:int =(1 / ((n$0 + n$1) + 1)) [line 44]\n REMOVE_TEMPS(n$0,n$1); [line 44]\n APPLY_ABSTRACTION; [line 44]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
13 -> 12 ;
|
||||||
|
12 [label="12: Exit div0_static_field_member_access \n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
11 [label="11: Start div0_static_field_member_access\nFormals: a:class f1::A * b:class C *\nLocals: \n DECLARE_LOCALS(&return); [line 41]\n NULLIFY(&a,false); [line 41]\n NULLIFY(&b,false); [line 41]\n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
11 -> 15 ;
|
||||||
|
10 [label="10: BinaryOperatorStmt: Assign \n *&#GB$B::v:int =1 [line 36]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
10 -> 9 ;
|
||||||
|
9 [label="9: BinaryOperatorStmt: Assign \n *&#GB$f1::A::v:int =-2 [line 37]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
9 -> 8 ;
|
||||||
|
8 [label="8: Return Stmt \n n$0=*&#GB$f1::A::v:int [line 38]\n n$1=*&#GB$B::v:int [line 38]\n *&return:int =(1 / ((n$0 + n$1) + 1)) [line 38]\n REMOVE_TEMPS(n$0,n$1); [line 38]\n APPLY_ABSTRACTION; [line 38]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
8 -> 7 ;
|
||||||
|
7 [label="7: Exit div0_static_field \n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
6 [label="6: Start div0_static_field\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 35]\n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
6 -> 10 ;
|
||||||
|
5 [label="5: BinaryOperatorStmt: Assign \n *&#GB$f1::val:int =1 [line 30]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
5 -> 4 ;
|
||||||
|
4 [label="4: BinaryOperatorStmt: Assign \n *&#GB$f2::val:int =-2 [line 31]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
4 -> 3 ;
|
||||||
|
3 [label="3: Return Stmt \n n$0=*&#GB$f1::val:int [line 32]\n n$1=*&#GB$f2::val:int [line 32]\n *&return:int =(1 / ((n$0 + n$1) + 1)) [line 32]\n REMOVE_TEMPS(n$0,n$1); [line 32]\n APPLY_ABSTRACTION; [line 32]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
3 -> 2 ;
|
||||||
|
2 [label="2: Exit div0_namepace_res \n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
1 [label="1: Start div0_namepace_res\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 29]\n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
1 -> 5 ;
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 - 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package endtoend.cpp;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import utils.DebuggableTemporaryFolder;
|
||||||
|
import utils.InferException;
|
||||||
|
import utils.InferResults;
|
||||||
|
import utils.InferRunner;
|
||||||
|
|
||||||
|
public class NamespaceGlobalVariableTest {
|
||||||
|
|
||||||
|
public static final String FILE =
|
||||||
|
"infer/tests/codetoanalyze/cpp/frontend/namespace/global_variable.cpp";
|
||||||
|
|
||||||
|
private static ImmutableList<String> inferCmd;
|
||||||
|
|
||||||
|
public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO";
|
||||||
|
|
||||||
|
@ClassRule
|
||||||
|
public static DebuggableTemporaryFolder folder =
|
||||||
|
new DebuggableTemporaryFolder();
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void runInfer() throws InterruptedException, IOException {
|
||||||
|
inferCmd = InferRunner.createCPPInferCommand(folder, FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenInferRunsOnDiv0MethodsErrorIsFound()
|
||||||
|
throws InterruptedException, IOException, InferException {
|
||||||
|
InferResults inferResults = InferRunner.runInferCPP(inferCmd);
|
||||||
|
String[] procedures = {
|
||||||
|
"div0_namepace_res",
|
||||||
|
"div0_static_field",
|
||||||
|
"div0_static_field_member_access",
|
||||||
|
};
|
||||||
|
assertThat(
|
||||||
|
"Results should contain the expected divide by zero",
|
||||||
|
inferResults,
|
||||||
|
containsExactly(
|
||||||
|
DIVIDE_BY_ZERO,
|
||||||
|
FILE,
|
||||||
|
procedures
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue