Reviewed By: akotulski, sblackshear Differential Revision: D3006192 fb-gh-sync-id: a81493b shipit-source-id: a81493bmaster
parent
85747084b5
commit
c9e5d27e0d
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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 test2() {
|
||||
int* x = 0;
|
||||
int y;
|
||||
int z;
|
||||
int h;
|
||||
asm("cpuid " : "=a"(x), "=b"(y), "=c"(z), "=d"(h) : "0"(0));
|
||||
return *x;
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 test() {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int h;
|
||||
asm("cpuid " : "=a"(x), "=b"(y), "=c"(z), "=d"(h) : "0"(0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int src = 1;
|
||||
int dst;
|
||||
|
||||
asm(
|
||||
"mov %1, %0\n\t"
|
||||
"add $1, %0"
|
||||
: "=r"(dst)
|
||||
: "r"(src));
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
digraph iCFG {
|
||||
9 [label="9: DeclStmt \n *&src:int =1 [line 20]\n " shape="box"]
|
||||
|
||||
|
||||
9 -> 8 ;
|
||||
8 [label="8: GCCAstStmt \n n$0=*&src:int [line 27]\n _fun___infer_skip_gcc_ast_stmt(&dst:int &,n$0:int ) [line 23]\n REMOVE_TEMPS(n$0); [line 23]\n NULLIFY(&src,false); [line 23]\n " shape="box"]
|
||||
|
||||
|
||||
8 -> 7 ;
|
||||
7 [label="7: Return Stmt \n *&return:int =0 [line 28]\n NULLIFY(&dst,false); [line 28]\n APPLY_ABSTRACTION; [line 28]\n " shape="box"]
|
||||
|
||||
|
||||
7 -> 6 ;
|
||||
6 [label="6: Exit main \n " color=yellow style=filled]
|
||||
|
||||
|
||||
5 [label="5: Start main\nFormals: \nLocals: dst:int src:int \n DECLARE_LOCALS(&return,&dst,&src); [line 19]\n NULLIFY(&src,false); [line 19]\n " color=yellow style=filled]
|
||||
|
||||
|
||||
5 -> 9 ;
|
||||
4 [label="4: GCCAstStmt \n _fun___infer_skip_gcc_ast_stmt(&x:int &,&y:int &,&z:int &,&h:int &,0:int ) [line 15]\n " shape="box"]
|
||||
|
||||
|
||||
4 -> 3 ;
|
||||
3 [label="3: Return Stmt \n *&return:int =0 [line 16]\n NULLIFY(&h,false); [line 16]\n NULLIFY(&x,false); [line 16]\n NULLIFY(&y,false); [line 16]\n NULLIFY(&z,false); [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"]
|
||||
|
||||
|
||||
3 -> 2 ;
|
||||
2 [label="2: Exit test \n " color=yellow style=filled]
|
||||
|
||||
|
||||
1 [label="1: Start test\nFormals: \nLocals: h:int z:int y:int x:int \n DECLARE_LOCALS(&return,&h,&z,&y,&x); [line 10]\n " color=yellow style=filled]
|
||||
|
||||
|
||||
1 -> 4 ;
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 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.c;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
|
||||
public class AsmAngelismTest {
|
||||
|
||||
public static final String SOURCE_FILE = "null_dereference/asm_angelism.c";
|
||||
|
||||
public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE";
|
||||
|
||||
private static InferResults inferResults;
|
||||
|
||||
@BeforeClass
|
||||
public static void runInfer() throws InterruptedException, IOException {
|
||||
inferResults = InferResults.loadCInferResults(
|
||||
AsmAngelismTest.class,
|
||||
SOURCE_FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void angelismNPETest() throws InterruptedException, IOException, InferException {
|
||||
String[] procedures = {};
|
||||
assertThat(
|
||||
"Results should not contain null pointer dereference error",
|
||||
inferResults,
|
||||
containsExactly(
|
||||
NULL_DEREFERENCE,
|
||||
SOURCE_FILE,
|
||||
procedures
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 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 frontend.c;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.DebuggableTemporaryFolder;
|
||||
import utils.InferException;
|
||||
import utils.ClangFrontendUtils;
|
||||
|
||||
public class UnusualStmtsTest {
|
||||
|
||||
String boolBasePath = "infer/tests/codetoanalyze/c/frontend/unusual_stmts/";
|
||||
|
||||
@Rule
|
||||
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
|
||||
|
||||
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
|
||||
ClangFrontendUtils.createAndCompareCDotFiles(folder, boolBasePath + fileRelative);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenCaptureRunCommaThenDotFilesAreTheSame()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
frontendTest("asm.c");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue