Use fully qualified names for functions

Summary: public
Functions had unqualified names before. Fix it.

Reviewed By: dulmarod

Differential Revision: D2668647

fb-gh-sync-id: cfeddea
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-7
parent 9748502a1a
commit cb42fdcc31

@ -114,7 +114,7 @@ let method_signature_of_decl meth_decl block_data_opt =
let open Clang_ast_t in
match meth_decl, block_data_opt with
| FunctionDecl (decl_info, name_info, tp, fdi), _ ->
let name = name_info.ni_name in
let name = Ast_utils.get_qualified_name name_info in
let language = !CFrontend_config.language in
let func_decl = Func_decl_info (fdi, tp, language) in
let function_info = Some (decl_info, fdi) in

@ -303,7 +303,7 @@ struct
let open CContext in
let context = trans_state.context in
let name_info, decl_ptr, type_ptr = get_info_from_decl_ref decl_ref in
let name = name_info.Clang_ast_t.ni_name in
let name = Ast_utils.get_qualified_name name_info in
let typ = CTypes_decl.type_ptr_to_sil_type context.tenv type_ptr in
let pname =
if CTrans_models.is_modeled_builtin name then

@ -0,0 +1,26 @@
/*
* 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.
*/
namespace f1 {
int get() { return 1;}
int get0() { return 0;}
}
namespace f2 {
int get() { return -1;}
}
int div0_using() {
using namespace f1;
return 1 / get0();
}
int div0_namespace_resolution() {
return 1 / (f1::get() + f2::get());
}

@ -0,0 +1,57 @@
digraph iCFG {
15 [label="15: Return Stmt \n n$0=_fun_f1::get() [line 25]\n n$1=_fun_f2::get() [line 25]\n *&return:int =(1 / (n$0 + n$1)) [line 25]\n REMOVE_TEMPS(n$0,n$1); [line 25]\n APPLY_ABSTRACTION; [line 25]\n " shape="box"]
15 -> 14 ;
14 [label="14: Exit div0_namespace_resolution \n " color=yellow style=filled]
13 [label="13: Start div0_namespace_resolution\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 24]\n " color=yellow style=filled]
13 -> 15 ;
12 [label="12: Return Stmt \n n$0=_fun_f1::get0() [line 21]\n *&return:int =(1 / n$0) [line 21]\n REMOVE_TEMPS(n$0); [line 21]\n APPLY_ABSTRACTION; [line 21]\n " shape="box"]
12 -> 11 ;
11 [label="11: Exit div0_using \n " color=yellow style=filled]
10 [label="10: Start div0_using\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 19]\n " color=yellow style=filled]
10 -> 12 ;
9 [label="9: Return Stmt \n *&return:int =-1 [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"]
9 -> 8 ;
8 [label="8: Exit f2::get \n " color=yellow style=filled]
7 [label="7: Start f2::get\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 16]\n " color=yellow style=filled]
7 -> 9 ;
6 [label="6: Return Stmt \n *&return:int =0 [line 12]\n APPLY_ABSTRACTION; [line 12]\n " shape="box"]
6 -> 5 ;
5 [label="5: Exit f1::get0 \n " color=yellow style=filled]
4 [label="4: Start f1::get0\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 12]\n " color=yellow style=filled]
4 -> 6 ;
3 [label="3: Return Stmt \n *&return:int =1 [line 11]\n APPLY_ABSTRACTION; [line 11]\n " shape="box"]
3 -> 2 ;
2 [label="2: Exit f1::get \n " color=yellow style=filled]
1 [label="1: Start f1::get\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 11]\n " color=yellow style=filled]
1 -> 3 ;
}

@ -23,11 +23,11 @@ digraph iCFG {
19 -> 18 ;
18 [label="18: BinaryOperatorStmt: Assign \n n$2=_fun_value() [line 55]\n *&i:int =n$2 [line 55]\n REMOVE_TEMPS(n$2); [line 55]\n NULLIFY(&i,false); [line 55]\n " shape="box"]
18 [label="18: BinaryOperatorStmt: Assign \n n$2=_fun_foo::value() [line 55]\n *&i:int =n$2 [line 55]\n REMOVE_TEMPS(n$2); [line 55]\n NULLIFY(&i,false); [line 55]\n " shape="box"]
18 -> 17 ;
17 [label="17: BinaryOperatorStmt: Assign \n n$1=_fun_value() [line 56]\n *&i:int =n$1 [line 56]\n REMOVE_TEMPS(n$1); [line 56]\n NULLIFY(&i,false); [line 56]\n " shape="box"]
17 [label="17: BinaryOperatorStmt: Assign \n n$1=_fun_bar::value() [line 56]\n *&i:int =n$1 [line 56]\n REMOVE_TEMPS(n$1); [line 56]\n NULLIFY(&i,false); [line 56]\n " shape="box"]
17 -> 16 ;
@ -57,10 +57,10 @@ digraph iCFG {
10 -> 9 ;
9 [label="9: Exit value \n " color=yellow style=filled]
9 [label="9: Exit bar::value \n " color=yellow style=filled]
8 [label="8: Start value\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 29]\n " color=yellow style=filled]
8 [label="8: Start bar::value\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 29]\n " color=yellow style=filled]
8 -> 10 ;
@ -75,10 +75,10 @@ digraph iCFG {
5 -> 4 ;
4 [label="4: Exit value \n " color=yellow style=filled]
4 [label="4: Exit foo::value \n " color=yellow style=filled]
3 [label="3: Start value\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 16]\n " color=yellow style=filled]
3 [label="3: Start foo::value\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 16]\n " color=yellow style=filled]
3 -> 5 ;

@ -0,0 +1,64 @@
/*
* 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.
*/
package endtoend.cpp;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
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 NamespaceFunctionTest {
public static final String FILE =
"infer/tests/codetoanalyze/cpp/frontend/namespace/function.cpp";
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.createCPPInferCommand(folder, FILE);
}
@Test
public void whenInferRunsOnDiv0MethodsErrorIsFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferCPP(inferCmd);
String[] procedures = {
"div0_using",
"div0_namespace_resolution",
};
assertThat(
"Results should contain the expected divide by zero",
inferResults,
containsExactly(
DIVIDE_BY_ZERO,
FILE,
procedures
)
);
}
}

@ -19,15 +19,24 @@ import utils.InferException;
import utils.ClangFrontendUtils;
public class NamespaceTest {
String basePath = "infer/tests/codetoanalyze/cpp/frontend/namespace/";
@Rule
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
ClangFrontendUtils.createAndCompareCppDotFiles(folder, basePath + fileRelative);
}
@Test
public void testNamespaceDotFilesMatch()
throws InterruptedException, IOException, InferException {
frontendTest("namespace.cpp");
}
@Test
public void whenCaptureRunCommaThenDotFilesAreTheSame()
public void testFunctionDotFilesMatch()
throws InterruptedException, IOException, InferException {
String src =
"infer/tests/codetoanalyze/cpp/frontend/namespace/namespace.cpp";
ClangFrontendUtils.createAndCompareCppDotFiles(folder, src);
frontendTest("function.cpp");
}
}

Loading…
Cancel
Save