From 2ca2abc801226101e575a9ee911d3b5fb2e97c41 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 23 Oct 2014 22:40:46 +0000 Subject: [PATCH] Don't emit strong vtable definitions for imported classes with key functions (PR21355) Clang would previously assert on the following code when targeting MinGW: struct __declspec(dllimport) S { virtual ~S(); }; S::~S() {} Because ~S is a key function and the class is dllimport, we would try to emit a strong definition of the vtable, with dllimport - which is a conflict. We should not emit strong vtable definitions for imported classes. Differential Revision: http://reviews.llvm.org/D5944 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220532 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGVTables.cpp | 3 ++- test/CodeGenCXX/dllimport.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index a1a820aed4..51c29fe171 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -677,7 +677,8 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) { // We're at the end of the translation unit, so the current key // function is fully correct. - if (const CXXMethodDecl *keyFunction = Context.getCurrentKeyFunction(RD)) { + const CXXMethodDecl *keyFunction = Context.getCurrentKeyFunction(RD); + if (keyFunction && !RD->hasAttr()) { // If this class has a key function, use that to determine the // linkage of the vtable. const FunctionDecl *def = nullptr; diff --git a/test/CodeGenCXX/dllimport.cpp b/test/CodeGenCXX/dllimport.cpp index a0703d6eef..d1e376bf4b 100644 --- a/test/CodeGenCXX/dllimport.cpp +++ b/test/CodeGenCXX/dllimport.cpp @@ -672,6 +672,18 @@ namespace PR19933 { // MSC-DAG: @"\01?y@?$D@$0CK@@PR19933@@2HA" = available_externally dllimport global i32 0 } +namespace PR21355 { + struct __declspec(dllimport) S { + virtual ~S(); + }; + S::~S() {} + + // S::~S is a key function, so we would ordinarily emit a strong definition for + // the vtable. However, S is imported, so the vtable should be too. + + // GNU-DAG: @_ZTVN7PR213551SE = available_externally dllimport unnamed_addr constant [4 x i8*] +} + // MS ignores DLL attributes on partial specializations. template struct PartiallySpecializedClassTemplate {}; template struct __declspec(dllimport) PartiallySpecializedClassTemplate { void f() {} }; -- 2.50.1