From: Chris Lattner Date: Sun, 4 May 2008 01:44:26 +0000 (+0000) Subject: if a decl is both 'static' and weak or static and inline, its linkage X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8fabd78f1976243cb223fb3e969c6f317d1ae44d;p=clang if a decl is both 'static' and weak or static and inline, its linkage type should be internal, not weak/linkonce. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50611 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 1b94c59561..bacb610a50 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -159,14 +159,14 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD) { // TODO: Set up linkage and many other things. Note, this is a simple // approximation of what we really want. - if (FD->getAttr()) + if (FD->getStorageClass() == FunctionDecl::Static) + CurFn->setLinkage(llvm::Function::InternalLinkage); + else if (FD->getAttr()) CurFn->setLinkage(llvm::Function::DLLImportLinkage); else if (FD->getAttr()) CurFn->setLinkage(llvm::Function::DLLExportLinkage); else if (FD->getAttr() || FD->isInline()) CurFn->setLinkage(llvm::Function::WeakLinkage); - else if (FD->getStorageClass() == FunctionDecl::Static) - CurFn->setLinkage(llvm::Function::InternalLinkage); if (FD->getAttr()) CurFn->setCallingConv(llvm::CallingConv::Fast); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index bf1f0d823d..306abd120b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -459,17 +459,19 @@ void CodeGenModule::EmitGlobalVarInit(const VarDecl *D) { // FIXME: else handle -fvisibility // Set the llvm linkage type as appropriate. - if (D->getAttr()) + if (D->getStorageClass() == VarDecl::Static) + 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()) { + else if (D->getAttr()) GV->setLinkage(llvm::GlobalVariable::WeakLinkage); - - } else { + else { // FIXME: This isn't right. This should handle common linkage and other // stuff. switch (D->getStorageClass()) { + case VarDecl::Static: assert(0 && "This case handled above"); case VarDecl::Auto: case VarDecl::Register: assert(0 && "Can't have auto or register globals"); @@ -481,9 +483,6 @@ void CodeGenModule::EmitGlobalVarInit(const VarDecl *D) { case VarDecl::PrivateExtern: // todo: common break; - case VarDecl::Static: - GV->setLinkage(llvm::GlobalVariable::InternalLinkage); - break; } } }