[PATCH] D44233: Set dso_local on external rtti GVs

Rafael Avila de Espindola via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 7 15:40:11 PST 2018


espindola created this revision.
espindola added a reviewer: rnk.

In this particular case it would be possible to just add an else with CGM.setDSOLocal(GV),  but it seems better to have as many callers as possible just call setGVProperties so that we can centralize the logic there.

This patch then makes setGVProperties able to handle null Decls.


https://reviews.llvm.org/D44233

Files:
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/windows-itanium-exceptions.cpp


Index: test/CodeGenCXX/windows-itanium-exceptions.cpp
===================================================================
--- test/CodeGenCXX/windows-itanium-exceptions.cpp
+++ test/CodeGenCXX/windows-itanium-exceptions.cpp
@@ -10,7 +10,7 @@
   try { except(); } catch (...) { }
 }
 
-// CHECK: @_ZTIi = external constant i8*
+// CHECK: @_ZTIi = external dso_local constant i8*
 
 // CHECK: define {{.*}}void @_Z6exceptv() {{.*}} {
 // CHECK:   %exception = call {{.*}}i8* @__cxa_allocate_exception(i32 4)
Index: lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -2615,10 +2615,10 @@
                                   /*Constant=*/true,
                                   llvm::GlobalValue::ExternalLinkage, nullptr,
                                   Name);
-    if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
-      const CXXRecordDecl *RD = cast<CXXRecordDecl>(RecordTy->getDecl());
-      CGM.setGVProperties(GV, RD);
-    }
+    const CXXRecordDecl *RD = nullptr;
+    if (const auto *RecordTy = dyn_cast<RecordType>(Ty))
+      RD = cast<CXXRecordDecl>(RecordTy->getDecl());
+    CGM.setGVProperties(GV, RD);
   }
 
   return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -707,7 +707,8 @@
     GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
     return;
   }
-
+  if (!D)
+    return;
   // Set visibility for definitions.
   LinkageInfo LV = D->getLinkageAndVisibility();
   if (LV.isVisibilityExplicit() || !GV->isDeclarationForLinker())
@@ -797,7 +798,7 @@
 
 void CodeGenModule::setDLLImportDLLExport(llvm::GlobalValue *GV,
                                           const NamedDecl *D) const {
-  if (D->isExternallyVisible()) {
+  if (D && D->isExternallyVisible()) {
     if (D->hasAttr<DLLImportAttr>())
       GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
     else if (D->hasAttr<DLLExportAttr>() && !GV->isDeclarationForLinker())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44233.137503.patch
Type: text/x-patch
Size: 2195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180307/f9773414/attachment.bin>


More information about the cfe-commits mailing list