diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index f9c2c32d5..a87260265 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -189,6 +189,11 @@ struct let exp = Sil.Const (Sil.Cint (Sil.Int.zero)) in { empty_res_trans with exps = [(exp, typ)]} + let nullPtrExpr_trans trans_state stmt_info expr_info = + Printing.log_out "Passing from nullptr '%s'\n" stmt_info.Clang_ast_t.si_pointer; + let typ = CTypes_decl.get_type_from_expr_info expr_info trans_state.context.tenv in + { empty_res_trans with exps = [(Sil.exp_null, typ)]} + let objCSelectorExpr_trans trans_state stmt_info expr_info selector = stringLiteral_trans trans_state stmt_info expr_info selector @@ -1708,6 +1713,9 @@ struct | GNUNullExpr(stmt_info, stmt_list, expr_info) -> gNUNullExpr_trans trans_state stmt_info expr_info + | CXXNullPtrLiteralExpr(stmt_info, stmt_list, expr_info) -> + nullPtrExpr_trans trans_state stmt_info expr_info + | ObjCSelectorExpr(stmt_info, stmt_list, expr_info, selector) -> objCSelectorExpr_trans trans_state stmt_info expr_info selector diff --git a/infer/tests/codetoanalyze/cpp/frontend/literals/nullptr.cpp b/infer/tests/codetoanalyze/cpp/frontend/literals/nullptr.cpp new file mode 100644 index 000000000..83d09e901 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/literals/nullptr.cpp @@ -0,0 +1 @@ +int* getPtr() {return nullptr;} diff --git a/infer/tests/codetoanalyze/cpp/frontend/literals/nullptr.dot b/infer/tests/codetoanalyze/cpp/frontend/literals/nullptr.dot new file mode 100644 index 000000000..5ff3719e2 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/literals/nullptr.dot @@ -0,0 +1,13 @@ +digraph iCFG { +3 [label="3: Return Stmt \n *&return:int *=null [line 1]\n APPLY_ABSTRACTION; [line 1]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit getPtr \n " color=yellow style=filled] + + +1 [label="1: Start getPtr\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 1]\n " color=yellow style=filled] + + + 1 -> 3 ; +} diff --git a/infer/tests/frontend/cpp/LiteralsTest.java b/infer/tests/frontend/cpp/LiteralsTest.java new file mode 100644 index 000000000..0a99f98cd --- /dev/null +++ b/infer/tests/frontend/cpp/LiteralsTest.java @@ -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 LiteralsTest { + + @Rule + public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder(); + + @Test + public void whenCaptureRunCommaThenDotFilesAreTheSame() + throws InterruptedException, IOException, InferException { + String literal_src = + "infer/tests/codetoanalyze/cpp/frontend/literals/nullptr.cpp"; + + String literal_dotty = + "infer/tests/codetoanalyze/cpp/frontend/literals/nullptr.dot"; + + ImmutableList 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)); + } +} diff --git a/infer/tests/utils/InferRunner.java b/infer/tests/utils/InferRunner.java index 8cd92dac1..126e4c5d7 100644 --- a/infer/tests/utils/InferRunner.java +++ b/infer/tests/utils/InferRunner.java @@ -166,6 +166,16 @@ public class InferRunner { return langOption; } + public static String getStdParam(Language lang) { + String stdParam = ""; + switch (lang) { + case CPP: + stdParam = "-std=c++11"; + break; + } + return stdParam; + } + public static ImmutableList createClangCommand( String sourceFile, Language lang, @@ -188,6 +198,7 @@ public class InferRunner { .add("clang") .add("-x") .add(getClangLangOption(lang)) + .add(getStdParam(lang)) .addAll(isysrootOption.build()) .addAll(arcOption.build()) .add("-c")