Author: andersca
Date: Mon Mar 29 14:49:09 2010
New Revision: 99829

URL: http://llvm.org/viewvc/llvm-project?rev=99829&view=rev
Log:
When collecting virtual bases it's very important to use the canonical type of 
the base class. Otherwise, we might add the same virtual base class twice if 
the virtual base is an instantiated template. Fixes PR6251.

Modified:
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/test/CodeGenCXX/virtual-bases.cpp

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=99829&r1=99828&r2=99829&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Mon Mar 29 14:49:09 2010
@@ -84,7 +84,7 @@
     C.Deallocate(data().Bases);
 
   // The set of seen virtual base types.
-  llvm::SmallPtrSet<QualType, 8> SeenVBaseTypes;
+  llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes;
   
   // The virtual bases of this class.
   llvm::SmallVector<const CXXBaseSpecifier *, 8> VBases;
@@ -107,13 +107,13 @@
           BaseClassDecl->vbases_begin(),
          E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) {
       // Add this base if it's not already in the list.
-      if (SeenVBaseTypes.insert(VBase->getType()))
+      if (SeenVBaseTypes.insert(C.getCanonicalType(VBase->getType())))
         VBases.push_back(VBase);
     }
 
     if (Base->isVirtual()) {
       // Add this base if it's not already in the list.
-      if (SeenVBaseTypes.insert(BaseType))
+      if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)))
           VBases.push_back(Base);
     }
 

Modified: cfe/trunk/test/CodeGenCXX/virtual-bases.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-bases.cpp?rev=99829&r1=99828&r2=99829&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-bases.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-bases.cpp Mon Mar 29 14:49:09 2010
@@ -23,3 +23,26 @@
 // CHECK: define void @_ZN1CC1Eb(%struct.B* %this, i1 zeroext)
 // CHECK: define void @_ZN1CC2Eb(%struct.B* %this, i8** %vtt, i1 zeroext)
 C::C(bool) { }
+
+// PR6251
+namespace PR6251 {
+
+// Test that we don't call the A<char> constructor twice.
+
+template<typename T>
+struct A { A(); };
+
+struct B : virtual A<char> { };
+struct C : virtual A<char> { };
+
+struct D : B, C  {
+  D();
+};
+
+// CHECK: define void @_ZN6PR62511DC1Ev
+// CHECK: call void @_ZN6PR62511AIcEC2Ev
+// CHECK-NOT: call void @_ZN6PR62511AIcEC2Ev
+// CHECK: ret void
+D::D() { }
+
+}


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to