]> granicus.if.org Git - clang/commitdiff
[analyzer] Don't canonicalize the RecordDecl used in CXXBaseObjectRegion.
authorJordan Rose <jordan_rose@apple.com>
Fri, 22 Feb 2013 19:33:13 +0000 (19:33 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 22 Feb 2013 19:33:13 +0000 (19:33 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175913 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/MemRegion.cpp
test/Analysis/derived-to-base.cpp

index e67297d86bb999e0acfb69dce912c18791675b8f..a3e42eaa46dd54744ba9b91b27923b84c718033d 100644 (file)
@@ -892,6 +892,8 @@ MemRegionManager::getCXXTempObjectRegion(Expr const *E,
 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;
index 6e4a3fa87a87bb856e51474be380b22ef91d758b..b846d2c28bb280b445f59a2bdae9c8530f68bc28 100644 (file)
@@ -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}}
+  }
+};
+