Summary: Add basic translation for C++ `new` keyword. Currently, it's modeled as simple `malloc` call. Following constructs are still not working properly: - array new `new [size_expr]` - run initializer attached to `new` (such as `new int(5)`) - `delete[]`master
parent
3b22adfc15
commit
1d6873f471
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void test() {
|
||||
int x = 2;
|
||||
int* i = new int;
|
||||
new int; // this will be leak - test that it gets to cfg
|
||||
delete i;
|
||||
|
||||
//int* i_a = new int[10];
|
||||
//delete[] i_a;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
digraph iCFG {
|
||||
6 [label="6: DeclStmt \n *&x:int =2 [line 11]\n NULLIFY(&x,false); [line 11]\n " shape="box"]
|
||||
|
||||
|
||||
6 -> 5 ;
|
||||
5 [label="5: DeclStmt \n n$2=_fun___new(sizeof(int ):int *) [line 12]\n *&i:int *=n$2 [line 12]\n REMOVE_TEMPS(n$2); [line 12]\n " shape="box"]
|
||||
|
||||
|
||||
5 -> 4 ;
|
||||
4 [label="4: Call C++ new \n n$1=_fun___new(sizeof(int ):int *) [line 13]\n REMOVE_TEMPS(n$1); [line 13]\n " shape="box"]
|
||||
|
||||
|
||||
4 -> 3 ;
|
||||
3 [label="3: Call delete \n n$0=*&i:int * [line 14]\n _fun___delete(n$0:int *) [line 14]\n REMOVE_TEMPS(n$0); [line 14]\n NULLIFY(&i,false); [line 14]\n APPLY_ABSTRACTION; [line 14]\n " shape="box"]
|
||||
|
||||
|
||||
3 -> 2 ;
|
||||
2 [label="2: Exit test \n " color=yellow style=filled]
|
||||
|
||||
|
||||
1 [label="1: Start test\nFormals: \nLocals: x:int i:int * \n DECLARE_LOCALS(&return,&x,&i); [line 10]\n NULLIFY(&i,false); [line 10]\n NULLIFY(&x,false); [line 10]\n " color=yellow style=filled]
|
||||
|
||||
|
||||
1 -> 6 ;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.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 NewTest {
|
||||
|
||||
@Rule
|
||||
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void whenCaptureRunCommaThenDotFilesAreTheSame()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
String src =
|
||||
"infer/tests/codetoanalyze/cpp/frontend/builtin/new.cpp";
|
||||
|
||||
String dotty =
|
||||
"infer/tests/codetoanalyze/cpp/frontend/builtin/new.dot";
|
||||
|
||||
ImmutableList<String> inferCmd =
|
||||
InferRunner.createCPPInferCommandFrontend(
|
||||
folder,
|
||||
src);
|
||||
File newDotFile = InferRunner.runInferFrontend(inferCmd);
|
||||
assertThat(
|
||||
"In the capture of " + src +
|
||||
" the dotty files should be the same.",
|
||||
newDotFile, dotFileEqualTo(dotty));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue