Author: hans Date: Wed Apr 13 15:21:15 2016 New Revision: 266242 URL: http://llvm.org/viewvc/llvm-project?rev=266242&view=rev Log: Make sure CheckDestructor gets called on dllimported classes if the vtable is used (PR27319)
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/test/CodeGenCXX/dllimport.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=266242&r1=266241&r2=266242&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Apr 13 15:21:15 2016 @@ -13314,13 +13314,20 @@ void Sema::MarkVTableUsed(SourceLocation // the deleting destructor is emitted with the vtable, not with the // destructor definition as in the Itanium ABI. // If it has a definition, we do the check at that point instead. - if (Context.getTargetInfo().getCXXABI().isMicrosoft() && - Class->hasUserDeclaredDestructor() && - !Class->getDestructor()->isDefined() && - !Class->getDestructor()->isDeleted()) { - CXXDestructorDecl *DD = Class->getDestructor(); - ContextRAII SavedContext(*this, DD); - CheckDestructor(DD); + if (Context.getTargetInfo().getCXXABI().isMicrosoft()) { + if (Class->hasUserDeclaredDestructor() && + !Class->getDestructor()->isDefined() && + !Class->getDestructor()->isDeleted()) { + CXXDestructorDecl *DD = Class->getDestructor(); + ContextRAII SavedContext(*this, DD); + CheckDestructor(DD); + } else if (Class->hasAttr<DLLImportAttr>()) { + // We always synthesize vtables on the import side. To make sure + // CheckDestructor gets called, mark the destructor referenced. + assert(Class->getDestructor() && + "The destructor has always been declared on a dllimport class"); + MarkFunctionReferenced(Loc, Class->getDestructor()); + } } } Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=266242&r1=266241&r2=266242&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original) +++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Wed Apr 13 15:21:15 2016 @@ -743,6 +743,17 @@ namespace PR21366 { inline void S::outOfClassInlineMethod() {} } +namespace PR27319 { + // Make sure we don't assert due to not having checked for operator delete on + // the destructor. + template <typename> struct A { + virtual ~A() = default; + }; + extern template struct __declspec(dllimport) A<int>; + void f() { new A<int>(); } + // MO1-DAG: @"\01??_S?$A@H@PR27319@@6B@" = linkonce_odr unnamed_addr constant [1 x i8*] +} + // MS ignores DLL attributes on partial specializations. template <typename T> struct PartiallySpecializedClassTemplate {}; template <typename T> struct __declspec(dllimport) PartiallySpecializedClassTemplate<T*> { void f(); }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits