[cfe-commits] r161709 - in /cfe/trunk: lib/StaticAnalyzer/Core/CallEvent.cpp test/Analysis/inline.cpp
Jordan Rose
jordan_rose at apple.com
Fri Aug 10 15:26:43 PDT 2012
Author: jrose
Date: Fri Aug 10 17:26:43 2012
New Revision: 161709
URL: http://llvm.org/viewvc/llvm-project?rev=161709&view=rev
Log:
[analyzer] Try to devirtualize even if the static callee has no definition.
This mostly affects pure virtual methods, but would also affect parent
methods defined inline in the header when analyzing the child's source file.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
cfe/trunk/test/Analysis/inline.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=161709&r1=161708&r2=161709&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Fri Aug 10 17:26:43 2012
@@ -383,13 +383,13 @@
RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const {
- const Decl *D = SimpleCall::getRuntimeDefinition().getDecl();
+ const Decl *D = getDecl();
if (!D)
return RuntimeDefinition();
const CXXMethodDecl *MD = cast<CXXMethodDecl>(D);
if (!MD->isVirtual())
- return RuntimeDefinition(MD);
+ return SimpleCall::getRuntimeDefinition();
// If the method is virtual, see if we can find the actual implementation
// based on context-sensitivity.
Modified: cfe/trunk/test/Analysis/inline.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inline.cpp?rev=161709&r1=161708&r2=161709&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inline.cpp (original)
+++ cfe/trunk/test/Analysis/inline.cpp Fri Aug 10 17:26:43 2012
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=inlining -verify %s
void clang_analyzer_eval(bool);
+void clang_analyzer_checkInlined(bool);
class A {
public:
@@ -43,3 +44,30 @@
clang_analyzer_eval(ptr->getNum() == x); // expected-warning {{TRUE}}
}
+
+namespace PureVirtualParent {
+ class Parent {
+ public:
+ virtual int pureVirtual() const = 0;
+ int callVirtual() const {
+ return pureVirtual();
+ }
+ };
+
+ class Child : public Parent {
+ public:
+ virtual int pureVirtual() const {
+ clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
+ return 42;
+ }
+ };
+
+ void testVirtual() {
+ Child x;
+
+ clang_analyzer_eval(x.pureVirtual() == 42); // expected-warning{{TRUE}}
+ clang_analyzer_eval(x.callVirtual() == 42); // expected-warning{{TRUE}}
+ }
+}
+
+
More information about the cfe-commits
mailing list