r221511 - CodeGen, Itanium: Properly dllimport RTTI data

David Majnemer david.majnemer at gmail.com
Thu Nov 6 23:26:39 PST 2014


Author: majnemer
Date: Fri Nov  7 01:26:38 2014
New Revision: 221511

URL: http://llvm.org/viewvc/llvm-project?rev=221511&view=rev
Log:
CodeGen, Itanium: Properly dllimport RTTI data

We would blindly assume that RTTI data should have the same linkage as
the vtable because we didn't think the RTTI data was external.  This
oversight stemmed because we didn't take dllimport into account.

This fixes PR21512.

Modified:
    cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
    cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=221511&r1=221510&r2=221511&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Fri Nov  7 01:26:38 2014
@@ -2190,6 +2190,11 @@ ItaniumRTTIBuilder::GetAddrOfExternalRTT
                                   /*Constant=*/true,
                                   llvm::GlobalValue::ExternalLinkage, nullptr,
                                   Name);
+    if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
+      const CXXRecordDecl *RD = cast<CXXRecordDecl>(RecordTy->getDecl());
+      if (RD->hasAttr<DLLImportAttr>())
+        GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
+    }
   }
 
   return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
@@ -2312,7 +2317,11 @@ static bool ShouldUseExternalRTTIDescrip
 
     // FIXME: this may need to be reconsidered if the key function
     // changes.
-    return CGM.getVTables().isVTableExternal(RD);
+    if (CGM.getVTables().isVTableExternal(RD))
+      return true;
+
+    if (RD->hasAttr<DLLImportAttr>())
+      return true;
   }
 
   return false;

Modified: cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp?rev=221511&r1=221510&r2=221511&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp Fri Nov  7 01:26:38 2014
@@ -1,13 +1,17 @@
-// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++1y -O1 -disable-llvm-optzns -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++1y -O1 -disable-llvm-optzns -o - %s | FileCheck %s --check-prefix=MSVC
+// RUN: %clang_cc1 -triple i686-windows-gnu  -emit-llvm -std=c++1y -O1 -disable-llvm-optzns -o - %s | FileCheck %s --check-prefix=GNU
 
 struct __declspec(dllimport) S {
-  virtual void f();
+  virtual void f() {}
 } s;
-// CHECK-DAG: @"\01??_7S@@6B@" = available_externally dllimport
-// CHECK-DAG: @"\01??_R0?AUS@@@8" = linkonce_odr
-// CHECK-DAG: @"\01??_R1A@?0A at EA@S@@8" = linkonce_odr
-// CHECK-DAG: @"\01??_R2S@@8" = linkonce_odr
-// CHECK-DAG: @"\01??_R3S@@8" = linkonce_odr
+// MSVC-DAG: @"\01??_7S@@6B@" = available_externally dllimport
+// MSVC-DAG: @"\01??_R0?AUS@@@8" = linkonce_odr
+// MSVC-DAG: @"\01??_R1A@?0A at EA@S@@8" = linkonce_odr
+// MSVC-DAG: @"\01??_R2S@@8" = linkonce_odr
+// MSVC-DAG: @"\01??_R3S@@8" = linkonce_odr
+
+// GNU-DAG: @_ZTV1S = available_externally dllimport
+// GNU-DAG: @_ZTI1S = external dllimport
 
 struct U : S {
 } u;





More information about the cfe-commits mailing list