r175913 - [analyzer] Don't canonicalize the RecordDecl used in CXXBaseObjectRegion.
Jordan Rose
jordan_rose at apple.com
Fri Feb 22 11:33:13 PST 2013
Author: jrose
Date: Fri Feb 22 13:33:13 2013
New Revision: 175913
URL: http://llvm.org/viewvc/llvm-project?rev=175913&view=rev
Log:
[analyzer] Don't canonicalize the RecordDecl used in CXXBaseObjectRegion.
This Decl shouldn't be the canonical Decl; it should be the Decl used by
the CXXBaseSpecifier in the subclass. Unfortunately, that means continuing
to throw getCanonicalDecl() on all comparisons.
This fixes MemRegion::getAsOffset's use of ASTRecordLayout when redeclarations
are involved.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
cfe/trunk/test/Analysis/derived-to-base.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=175913&r1=175912&r2=175913&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Fri Feb 22 13:33:13 2013
@@ -892,6 +892,8 @@ MemRegionManager::getCXXTempObjectRegion
static bool isValidBaseClass(const CXXRecordDecl *BaseClass,
const TypedValueRegion *Super,
bool IsVirtual) {
+ BaseClass = BaseClass->getCanonicalDecl();
+
const CXXRecordDecl *Class = Super->getValueType()->getAsCXXRecordDecl();
if (!Class)
return true;
@@ -913,8 +915,6 @@ const CXXBaseObjectRegion *
MemRegionManager::getCXXBaseObjectRegion(const CXXRecordDecl *RD,
const MemRegion *Super,
bool IsVirtual) {
- RD = RD->getCanonicalDecl();
-
if (isa<TypedValueRegion>(Super)) {
assert(isValidBaseClass(RD, dyn_cast<TypedValueRegion>(Super), IsVirtual));
(void)isValidBaseClass;
Modified: cfe/trunk/test/Analysis/derived-to-base.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/derived-to-base.cpp?rev=175913&r1=175912&r2=175913&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/derived-to-base.cpp (original)
+++ cfe/trunk/test/Analysis/derived-to-base.cpp Fri Feb 22 13:33:13 2013
@@ -333,3 +333,33 @@ namespace LazyBindings {
}
#endif
}
+
+namespace Redeclaration {
+ class Base;
+
+ class Base {
+ public:
+ virtual int foo();
+ int get() { return value; }
+
+ int value;
+ };
+
+ class Derived : public Base {
+ public:
+ virtual int bar();
+ };
+
+ void test(Derived d) {
+ d.foo(); // don't crash
+ d.bar(); // sanity check
+
+ Base &b = d;
+ b.foo(); // don't crash
+
+ d.value = 42; // don't crash
+ clang_analyzer_eval(d.get() == 42); // expected-warning{{TRUE}}
+ clang_analyzer_eval(b.get() == 42); // expected-warning{{TRUE}}
+ }
+};
+
More information about the cfe-commits
mailing list