From 2f402708e62f89fb875442802e3d3f20fc909d33 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Fri, 26 Dec 2008 00:52:02 +0000 Subject: Add full dllimport / dllexport support: both sema checks and codegen. Patch by Ilya Okonsky git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61437 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index e83d2cd293..fc1b108b0d 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -218,17 +218,30 @@ static void SetGlobalValueAttributes(const Decl *D, // approximation of what we really want. if (!ForDefinition) { // Only a few attributes are set on declarations. - if (D->getAttr()) - GV->setLinkage(llvm::Function::DLLImportLinkage); + if (D->getAttr()) { + // The dllimport attribute is overridden by a subsequent declaration as + // dllexport. + if (!D->getAttr()) + // dllimport attribute can be applied only to function decls, not to + // definitions. + if (const FunctionDecl *FD = dyn_cast(D)) { + if (!FD->getBody()) + GV->setLinkage(llvm::Function::DLLImportLinkage); + } else + GV->setLinkage(llvm::Function::DLLImportLinkage); + } } else { if (IsInternal) { GV->setLinkage(llvm::Function::InternalLinkage); } else { - if (D->getAttr()) - GV->setLinkage(llvm::Function::DLLImportLinkage); - else if (D->getAttr()) - GV->setLinkage(llvm::Function::DLLExportLinkage); - else if (D->getAttr() || IsInline) + if (D->getAttr()) { + if (const FunctionDecl *FD = dyn_cast(D)) { + // The dllexport attribute is ignored for undefined symbols. + if (FD->getBody()) + GV->setLinkage(llvm::Function::DLLExportLinkage); + } else + GV->setLinkage(llvm::Function::DLLExportLinkage); + } else if (D->getAttr() || IsInline) GV->setLinkage(llvm::Function::WeakLinkage); } } -- cgit v1.2.3-18-g5258