From: Anders Carlsson Date: Mon, 29 Mar 2010 19:49:09 +0000 (+0000) Subject: When collecting virtual bases it's very important to use the canonical type of the... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c3639351f8c252ddcc13d234cabf8780b1c235f;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99829 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 3b3bf1ba44..ed02edd394 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -84,7 +84,7 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, C.Deallocate(data().Bases); // The set of seen virtual base types. - llvm::SmallPtrSet SeenVBaseTypes; + llvm::SmallPtrSet SeenVBaseTypes; // The virtual bases of this class. llvm::SmallVector VBases; @@ -107,13 +107,13 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, 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); } diff --git a/test/CodeGenCXX/virtual-bases.cpp b/test/CodeGenCXX/virtual-bases.cpp index 6277175763..61de3153fd 100644 --- a/test/CodeGenCXX/virtual-bases.cpp +++ b/test/CodeGenCXX/virtual-bases.cpp @@ -23,3 +23,26 @@ struct C : virtual A { // 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 constructor twice. + +template +struct A { A(); }; + +struct B : virtual A { }; +struct C : virtual A { }; + +struct D : B, C { + D(); +}; + +// CHECK: define void @_ZN6PR62511DC1Ev +// CHECK: call void @_ZN6PR62511AIcEC2Ev +// CHECK-NOT: call void @_ZN6PR62511AIcEC2Ev +// CHECK: ret void +D::D() { } + +}