@@ -4512,6 +4512,19 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
45124512 return Resolver;
45134513}
45144514
4515+ bool CodeGenModule::shouldDropDLLAttribute (const Decl *D,
4516+ const llvm::GlobalValue *GV) const {
4517+ auto SC = GV->getDLLStorageClass ();
4518+ if (SC == llvm::GlobalValue::DefaultStorageClass)
4519+ return false ;
4520+ const Decl *MRD = D->getMostRecentDecl ();
4521+ return (((SC == llvm::GlobalValue::DLLImportStorageClass &&
4522+ !MRD->hasAttr <DLLImportAttr>()) ||
4523+ (SC == llvm::GlobalValue::DLLExportStorageClass &&
4524+ !MRD->hasAttr <DLLExportAttr>())) &&
4525+ !shouldMapVisibilityToDLLExport (cast<NamedDecl>(MRD)));
4526+ }
4527+
45154528// / GetOrCreateLLVMFunction - If the specified mangled name is not in the
45164529// / module, create and return an llvm Function with the specified type. If there
45174530// / is something in the module with the specified name, return it potentially
@@ -4564,8 +4577,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
45644577 }
45654578
45664579 // Handle dropped DLL attributes.
4567- if (D && !D->hasAttr <DLLImportAttr>() && !D->hasAttr <DLLExportAttr>() &&
4568- !shouldMapVisibilityToDLLExport (cast_or_null<NamedDecl>(D))) {
4580+ if (D && shouldDropDLLAttribute (D, Entry)) {
45694581 Entry->setDLLStorageClass (llvm::GlobalValue::DefaultStorageClass);
45704582 setDSOLocal (Entry);
45714583 }
@@ -4859,8 +4871,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
48594871 }
48604872
48614873 // Handle dropped DLL attributes.
4862- if (D && !D->hasAttr <DLLImportAttr>() && !D->hasAttr <DLLExportAttr>() &&
4863- !shouldMapVisibilityToDLLExport (D))
4874+ if (D && shouldDropDLLAttribute (D, Entry))
48644875 Entry->setDLLStorageClass (llvm::GlobalValue::DefaultStorageClass);
48654876
48664877 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
0 commit comments