[cfe-commits] r90025 - in /cfe/trunk: lib/CodeGen/CGClass.cpp test/CodeGenCXX/virtual-base-cast.cpp

Eli Friedman eli.friedman at gmail.com
Fri Nov 27 19:31:34 PST 2009


Author: efriedma
Date: Fri Nov 27 21:31:34 2009
New Revision: 90025

URL: http://llvm.org/viewvc/llvm-project?rev=90025&view=rev
Log:
Add a much more thorough test of casts to virtual bases, and fix
GetCXXBaseClassOffset to actually pass the test.


Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=90025&r1=90024&r2=90025&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Fri Nov 27 21:31:34 2009
@@ -75,7 +75,7 @@
                                           const CXXRecordDecl *ClassDecl,
                                           const CXXRecordDecl *BaseClassDecl) {
   CXXBasePaths Paths(/*FindAmbiguities=*/false,
-                     /*RecordPaths=*/true, /*DetectVirtual=*/true);
+                     /*RecordPaths=*/true, /*DetectVirtual=*/false);
   if (!const_cast<CXXRecordDecl *>(ClassDecl)->
         isDerivedFrom(const_cast<CXXRecordDecl *>(BaseClassDecl), Paths)) {
     assert(false && "Class must be derived from the passed in base class!");
@@ -84,21 +84,20 @@
 
   unsigned Start = 0;
   llvm::Value *VirtualOffset = 0;
-  if (const RecordType *RT = Paths.getDetectedVirtual()) {
-    const CXXRecordDecl *VBase = cast<CXXRecordDecl>(RT->getDecl());
-    
-    VirtualOffset = 
-      CGF.GetVirtualCXXBaseClassOffset(BaseValue, ClassDecl, VBase);
-    
-    const CXXBasePath &Path = Paths.front();
-    unsigned e = Path.size();
-    for (Start = 0; Start != e; ++Start) {
-      const CXXBasePathElement& Element = Path[Start];
-      
-      if (Element.Class == VBase)
-        break;
+
+  const CXXBasePath &Path = Paths.front();
+  const CXXRecordDecl *VBase = 0;
+  for (unsigned i = 0, e = Path.size(); i != e; ++i) {
+    const CXXBasePathElement& Element = Path[i];
+    if (Element.Base->isVirtual()) {
+      Start = i+1;
+      QualType VBaseType = Element.Base->getType();
+      VBase = cast<CXXRecordDecl>(VBaseType->getAs<RecordType>()->getDecl());
     }
   }
+  if (VBase)
+    VirtualOffset = 
+      CGF.GetVirtualCXXBaseClassOffset(BaseValue, ClassDecl, VBase);
   
   uint64_t Offset = 
     ComputeNonVirtualBaseClassOffset(CGF.getContext(), Paths, Start);

Modified: cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp?rev=90025&r1=90024&r2=90025&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp Fri Nov 27 21:31:34 2009
@@ -1,9 +1,33 @@
-// RUN: clang-cc -emit-llvm-only %s
+// RUN: clang-cc -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s
 
-struct A { virtual ~A(); };
-struct B : A { virtual ~B(); };
-struct C : virtual B { virtual ~C(); };
+struct A { int a; virtual int aa(); };
+struct B { int b; virtual int bb(); };
+struct C : virtual A, virtual B { int c; virtual int aa(); virtual int bb(); };
+struct AA { int a; virtual int aa(); };
+struct BB { int b; virtual int bb(); };
+struct CC : AA, BB { virtual int aa(); virtual int bb(); virtual int cc(); };
+struct D : virtual C, virtual CC { int e; };
 
-void f(C *c) {
-  A* a = c;
-}
+D* x;
+
+A* a() { return x; }
+// CHECK: @_Z1av() nounwind
+// CHECK: [[VBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = getelementptr i8* {{.*}}, i64 -16
+// CHECK: [[CASTVBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRA]] to i32*
+// CHECK: load i32* [[CASTVBASEOFFSETPTRA]]
+// CHECK: }
+
+B* b() { return x; }
+// CHECK: @_Z1bv() nounwind
+// CHECK: [[VBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = getelementptr i8* {{.*}}, i64 -20
+// CHECK: [[CASTVBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRA]] to i32*
+// CHECK: load i32* [[CASTVBASEOFFSETPTRA]]
+// CHECK: }
+
+BB* c() { return x; }
+// CHECK: @_Z1cv() nounwind
+// CHECK: [[VBASEOFFSETPTRC:%[a-zA-Z0-9\.]+]] = getelementptr i8* {{.*}}, i64 -24
+// CHECK: [[CASTVBASEOFFSETPTRC:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRC]] to i32*
+// CHECK: [[VBASEOFFSETC:%[a-zA-Z0-9\.]+]] = load i32* [[CASTVBASEOFFSETPTRC]]
+// CHECK: add i32 [[VBASEOFFSETC]], 8
+// CHECK: }





More information about the cfe-commits mailing list