Summary: Translate `OffsetOfExpr` (http://clang.llvm.org/doxygen/classclang_1_1OffsetOfExpr.html) into an expression that has an undefined value. Reviewed By: dulmarod Differential Revision: D3534392 fbshipit-source-id: be3dd6amaster
parent
f40033fc5f
commit
4ba864780e
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
struct address {
|
||||||
|
char v1[2];
|
||||||
|
char v2[5];
|
||||||
|
int v3;
|
||||||
|
};
|
||||||
|
|
||||||
|
int test() {
|
||||||
|
int i = offsetof(struct address, v2);
|
||||||
|
if (i == 9) {
|
||||||
|
return 9 / 0;
|
||||||
|
} else {
|
||||||
|
return 4 / 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/* @generated */
|
||||||
|
digraph iCFG {
|
||||||
|
10 [label="10: DeclStmt \n *&i:int =n$1 [line 19]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
10 -> 5 ;
|
||||||
|
9 [label="9: Return Stmt \n *&return:int =(4 / 0) [line 23]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
9 -> 2 ;
|
||||||
|
8 [label="8: Return Stmt \n *&return:int =(9 / 0) [line 21]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
8 -> 2 ;
|
||||||
|
7 [label="7: Prune (false branch) \n PRUNE(((n$0 == 9) == 0), false); [line 20]\n " shape="invhouse"]
|
||||||
|
|
||||||
|
|
||||||
|
7 -> 9 ;
|
||||||
|
6 [label="6: Prune (true branch) \n PRUNE(((n$0 == 9) != 0), true); [line 20]\n " shape="invhouse"]
|
||||||
|
|
||||||
|
|
||||||
|
6 -> 8 ;
|
||||||
|
5 [label="5: BinaryOperatorStmt: EQ \n n$0=*&i:int [line 20]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
5 -> 6 ;
|
||||||
|
5 -> 7 ;
|
||||||
|
4 [label="4: between_join_and_exit \n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
4 -> 2 ;
|
||||||
|
3 [label="3: + \n " ]
|
||||||
|
|
||||||
|
|
||||||
|
3 -> 4 ;
|
||||||
|
2 [label="2: Exit test \n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
1 [label="1: Start test\nFormals: \nLocals: i:int \n DECLARE_LOCALS(&return,&i); [line 18]\n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
1 -> 10 ;
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package endtoend.c;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static utils.matchers.ResultContainsLineNumbers.containsLines;
|
||||||
|
|
||||||
|
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 OffsetOfExprTest {
|
||||||
|
|
||||||
|
public static final String FILE =
|
||||||
|
"infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c";
|
||||||
|
|
||||||
|
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.createCInferCommand(
|
||||||
|
folder,
|
||||||
|
FILE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void matchErrors()
|
||||||
|
throws InterruptedException, IOException, InferException {
|
||||||
|
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
|
||||||
|
assertThat(
|
||||||
|
"Results should contain the correct " + DIVIDE_BY_ZERO,
|
||||||
|
inferResults,
|
||||||
|
containsLines(new int[] {21, 23}));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package frontend.c;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import utils.ClangFrontendUtils;
|
||||||
|
import utils.DebuggableTemporaryFolder;
|
||||||
|
import utils.InferException;
|
||||||
|
|
||||||
|
public class OffsetOfExprTest {
|
||||||
|
String FILE = "infer/tests/codetoanalyze/c/frontend/offsetof_expr/offsetof_expr.c";
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void frontendTest() throws InterruptedException, IOException, InferException {
|
||||||
|
ClangFrontendUtils.createAndCompareCDotFiles(folder, FILE);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue