Summary: @public Add support for default function arguments. As a side change - always create cmethod_signature for a function Test Plan: 1. Call function with default parameter and confirm that it gets parsed and reports null dereference (B5 but still). It didn't before. 2. Created a test casemaster
parent
d15e60ffbf
commit
9f9bc53361
@ -0,0 +1,18 @@
|
|||||||
|
int fun_default(int a = 3, int b = 5) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fun_default_decl(int a, int b = 5);
|
||||||
|
// note that b is default param, but function was declared earlier
|
||||||
|
int fun_default_decl(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test() {
|
||||||
|
fun_default(1, 2);
|
||||||
|
fun_default(1);
|
||||||
|
fun_default();
|
||||||
|
|
||||||
|
fun_default_decl(6);
|
||||||
|
fun_default_decl(6,6);
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
digraph iCFG {
|
||||||
|
13 [label="13: Call _fun_fun_default \n n$8=_fun_fun_default(1:int ,2:int ) [line 12]\n REMOVE_TEMPS(n$8); [line 12]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
13 -> 12 ;
|
||||||
|
12 [label="12: Call _fun_fun_default \n n$7=_fun_fun_default(1:int ,5:int ) [line 13]\n REMOVE_TEMPS(n$7); [line 13]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
12 -> 11 ;
|
||||||
|
11 [label="11: Call _fun_fun_default \n n$6=_fun_fun_default(3:int ,5:int ) [line 14]\n REMOVE_TEMPS(n$6); [line 14]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
11 -> 10 ;
|
||||||
|
10 [label="10: Call _fun_fun_default_decl \n n$5=_fun_fun_default_decl(6:int ,5:int ) [line 16]\n REMOVE_TEMPS(n$5); [line 16]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
10 -> 9 ;
|
||||||
|
9 [label="9: Call _fun_fun_default_decl \n n$4=_fun_fun_default_decl(6:int ,6:int ) [line 17]\n REMOVE_TEMPS(n$4); [line 17]\n APPLY_ABSTRACTION; [line 17]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
9 -> 8 ;
|
||||||
|
8 [label="8: Exit test \n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
7 [label="7: Start test\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 11]\n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
7 -> 13 ;
|
||||||
|
6 [label="6: Return Stmt \n n$2=*&a:int [line 8]\n n$3=*&b:int [line 8]\n *&return:int =(n$2 + n$3) [line 8]\n REMOVE_TEMPS(n$2,n$3); [line 8]\n NULLIFY(&a,false); [line 8]\n NULLIFY(&b,false); [line 8]\n APPLY_ABSTRACTION; [line 8]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
6 -> 5 ;
|
||||||
|
5 [label="5: Exit fun_default_decl \n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
4 [label="4: Start fun_default_decl\nFormals: a:int b:int \nLocals: \n DECLARE_LOCALS(&return); [line 7]\n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
4 -> 6 ;
|
||||||
|
3 [label="3: Return Stmt \n n$0=*&a:int [line 2]\n n$1=*&b:int [line 2]\n *&return:int =(n$0 + n$1) [line 2]\n REMOVE_TEMPS(n$0,n$1); [line 2]\n NULLIFY(&a,false); [line 2]\n NULLIFY(&b,false); [line 2]\n APPLY_ABSTRACTION; [line 2]\n " shape="box"]
|
||||||
|
|
||||||
|
|
||||||
|
3 -> 2 ;
|
||||||
|
2 [label="2: Exit fun_default \n " color=yellow style=filled]
|
||||||
|
|
||||||
|
|
||||||
|
1 [label="1: Start fun_default\nFormals: a:int b:int \nLocals: \n DECLARE_LOCALS(&return); [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 FunctionsTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCaptureRunCommaThenDotFilesAreTheSame()
|
||||||
|
throws InterruptedException, IOException, InferException {
|
||||||
|
String literal_src =
|
||||||
|
"infer/tests/codetoanalyze/cpp/frontend/types/functions.cpp";
|
||||||
|
|
||||||
|
String literal_dotty =
|
||||||
|
"infer/tests/codetoanalyze/cpp/frontend/types/functions.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