From 7bd0674dea1ee3625d97bf64f6a31760af221f4a Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Wed, 31 Oct 2012 01:18:26 +0000 Subject: [PATCH] [analyzer]Don't invalidate const arguments when there is no IdentifierInfo. Ee: C++ copy constructors. llvm-svn: 167092 --- clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 2 +- clang/test/Analysis/method-call.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp index 31e4cf05d992..b1e2d78183b4 100644 --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -321,7 +321,7 @@ bool AnyFunctionCall::argumentsMayEscape() const { const IdentifierInfo *II = D->getIdentifier(); if (!II) - return true; + return false; // This set of "escaping" APIs is diff --git a/clang/test/Analysis/method-call.cpp b/clang/test/Analysis/method-call.cpp index cfb6cd55ad6c..1a2fedda33bc 100644 --- a/clang/test/Analysis/method-call.cpp +++ b/clang/test/Analysis/method-call.cpp @@ -9,6 +9,10 @@ struct A { int getx() const { return x; } }; +struct B{ + int x; +}; + void testNullObject(A *a) { clang_analyzer_eval(a); // expected-warning{{UNKNOWN}} (void)a->getx(); // assume we know what we're doing @@ -34,3 +38,10 @@ void f4() { A x = 3; clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}} } + +void checkThatCopyConstructorDoesNotInvalidateObjectBeingCopied() { + B t; + t.x = 0; + B t2(t); + clang_analyzer_eval(t.x == 0); // expected-warning{{TRUE}} +}