From: Daniel Dunbar Date: Fri, 6 Mar 2009 16:20:49 +0000 (+0000) Subject: IRgen support for weak_import. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e27314eb5a9cba7997cf9f6fc82428d99667077;p=clang IRgen support for weak_import. - clang should support weak_import git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66270 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 3f930feaaa..953413d824 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -263,8 +263,12 @@ void CodeGenModule::SetGlobalValueAttributes(const Decl *D, } else GV->setLinkage(llvm::Function::DLLImportLinkage); } - } else if (D->getAttr()) + } else if (D->getAttr() || + D->getAttr()) { + // "extern_weak" is overloaded in LLVM; we probably should have + // separate linkage types for this. GV->setLinkage(llvm::Function::ExternalWeakLinkage); + } } else { if (IsInternal) { GV->setLinkage(llvm::Function::InternalLinkage); @@ -276,7 +280,8 @@ void CodeGenModule::SetGlobalValueAttributes(const Decl *D, GV->setLinkage(llvm::Function::DLLExportLinkage); } else GV->setLinkage(llvm::Function::DLLExportLinkage); - } else if (D->getAttr() || IsInline) + } else if (D->getAttr() || D->getAttr() || + IsInline) GV->setLinkage(llvm::Function::WeakLinkage); } } @@ -602,7 +607,7 @@ void CodeGenModule::EmitGlobalDefinition(const ValueDecl *D) { if (D->getStorageClass() == VarDecl::PrivateExtern) setGlobalVisibility(GV, VisibilityAttr::HiddenVisibility); - if (D->getAttr()) + if (D->getAttr() || D->getAttr()) GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); if (const AsmLabelAttr *ALA = D->getAttr()) { @@ -737,7 +742,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { GV->setLinkage(llvm::Function::DLLImportLinkage); else if (D->getAttr()) GV->setLinkage(llvm::Function::DLLExportLinkage); - else if (D->getAttr()) + else if (D->getAttr() || D->getAttr()) GV->setLinkage(llvm::GlobalVariable::WeakLinkage); else { // FIXME: This isn't right. This should handle common linkage and other diff --git a/test/CodeGen/attributes.c b/test/CodeGen/attributes.c index 171c81081a..25b9fd064d 100644 --- a/test/CodeGen/attributes.c +++ b/test/CodeGen/attributes.c @@ -13,6 +13,8 @@ // RUN: grep '@t12 =.*section "SECT"' %t && // RUN: grep '@t13 =.*section "SECT"' %t && // RUN: grep '@t14.x =.*section "SECT"' %t +// RUN: grep 'declare extern_weak i32 @t15()' %t && +// RUN: grep '@t16 = extern_weak global i32' %t void t1() __attribute__((noreturn)); void t1() {} @@ -47,3 +49,11 @@ struct s0 t13 __attribute__((section("SECT"))) = { 0 }; void t14(void) { static int x __attribute__((section("SECT"))) = 0; } + +int __attribute__((weak_import)) t15(void); +extern int t16 __attribute__((weak_import)); +int t17() { + return t15() + t16; +} + +