Summary: @public Translate CXXStaticCastExpr Test Plan: Add test, confirm that it gets translated. Also create example to see that infer reports null dereference with this change: struct X { int a; }; int main() { X *x = static_cast<X*>(nullptr); // <- reports now //X *x = (X*)nullptr; // <- reported before return x->a; }master
parent
7f72397999
commit
76203aa847
@ -0,0 +1,4 @@
|
||||
void stat_cast() {
|
||||
int a;
|
||||
long long la = static_cast<long long>(a);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
digraph iCFG {
|
||||
3 [label="3: DeclStmt \n n$0=*&a:int [line 3]\n *&la:long long =n$0 [line 3]\n REMOVE_TEMPS(n$0); [line 3]\n NULLIFY(&a,false); [line 3]\n NULLIFY(&la,false); [line 3]\n APPLY_ABSTRACTION; [line 3]\n " shape="box"]
|
||||
|
||||
|
||||
3 -> 2 ;
|
||||
2 [label="2: Exit stat_cast \n " color=yellow style=filled]
|
||||
|
||||
|
||||
1 [label="1: Start stat_cast\nFormals: \nLocals: a:int la:long long \n DECLARE_LOCALS(&return,&a,&la); [line 1]\n NULLIFY(&la,false); [line 1]\n " color=yellow style=filled]
|
||||
|
||||
|
||||
1 -> 3 ;
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2013- Facebook.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package frontend.cpp;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.DebuggableTemporaryFolder;
|
||||
import utils.InferException;
|
||||
import utils.InferRunner;
|
||||
|
||||
public class CastsTest {
|
||||
|
||||
@Rule
|
||||
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void whenCaptureRunCommaThenDotFilesAreTheSame()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
String literal_src =
|
||||
"infer/tests/codetoanalyze/cpp/frontend/types/casts.cpp";
|
||||
|
||||
String literal_dotty =
|
||||
"infer/tests/codetoanalyze/cpp/frontend/types/casts.dot";
|
||||
|
||||
ImmutableList<String> inferCmd =
|
||||
InferRunner.createCPPInferCommandFrontend(
|
||||
folder,
|
||||
literal_src);
|
||||
File newDotFile = InferRunner.runInferFrontend(inferCmd);
|
||||
assertThat(
|
||||
"In the capture of " + literal_src +
|
||||
" the dotty files should be the same.",
|
||||
newDotFile, dotFileEqualTo(literal_dotty));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue