diff options
author | Andrew Ng <andrew.ng@sony.com> | 2024-06-10 19:39:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 19:39:28 +0100 |
commit | baba78daf2b3a3ee9bfa21f1f8ff3584aa982ac8 (patch) | |
tree | 9bea3e65ef172574d9b03fe77d1375a3bebf9587 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 870bfad71a5bc84102374d94812cf063552493b9 (diff) | |
download | llvm-baba78daf2b3a3ee9bfa21f1f8ff3584aa982ac8.zip llvm-baba78daf2b3a3ee9bfa21f1f8ff3584aa982ac8.tar.gz llvm-baba78daf2b3a3ee9bfa21f1f8ff3584aa982ac8.tar.bz2 |
[clang] Fix loss of `dllexport` for exported template specialization (#94664)
When dropping DLL attributes, ensure that the most recent declaration is
being checked.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 75b1449..dd4a665 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4512,6 +4512,19 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) { return Resolver; } +bool CodeGenModule::shouldDropDLLAttribute(const Decl *D, + const llvm::GlobalValue *GV) const { + auto SC = GV->getDLLStorageClass(); + if (SC == llvm::GlobalValue::DefaultStorageClass) + return false; + const Decl *MRD = D->getMostRecentDecl(); + return (((SC == llvm::GlobalValue::DLLImportStorageClass && + !MRD->hasAttr<DLLImportAttr>()) || + (SC == llvm::GlobalValue::DLLExportStorageClass && + !MRD->hasAttr<DLLExportAttr>())) && + !shouldMapVisibilityToDLLExport(cast<NamedDecl>(MRD))); +} + /// GetOrCreateLLVMFunction - If the specified mangled name is not in the /// module, create and return an llvm Function with the specified type. If there /// is something in the module with the specified name, return it potentially @@ -4564,8 +4577,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction( } // Handle dropped DLL attributes. - if (D && !D->hasAttr<DLLImportAttr>() && !D->hasAttr<DLLExportAttr>() && - !shouldMapVisibilityToDLLExport(cast_or_null<NamedDecl>(D))) { + if (D && shouldDropDLLAttribute(D, Entry)) { Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass); setDSOLocal(Entry); } @@ -4859,8 +4871,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty, } // Handle dropped DLL attributes. - if (D && !D->hasAttr<DLLImportAttr>() && !D->hasAttr<DLLExportAttr>() && - !shouldMapVisibilityToDLLExport(D)) + if (D && shouldDropDLLAttribute(D, Entry)) Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass); if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D) |