diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2011-01-15 08:15:00 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2011-01-15 08:15:00 +0000 |
commit | ba7c38c36adb65d66c129270b2813fd2167488ed (patch) | |
tree | 82995351f44cc9d463dfde26aa790d4ba1359401 /lib | |
parent | 6ccb5ef1b504e71b63219437f5bcf4856207949b (diff) |
Allow unnamed_addr on declarations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123529 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 6 | ||||
-rw-r--r-- | lib/Linker/LinkModules.cpp | 10 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 3 |
3 files changed, 7 insertions, 12 deletions
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index f0fb310614..04e2e601e2 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -716,9 +716,6 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc, return true; } - if (!Init && UnnamedAddr) - return Error(UnnamedAddrLoc, "only definitions can have unnamed_addr"); - if (Ty->isFunctionTy() || Ty->isLabelTy()) return Error(TyLoc, "invalid type for global variable"); @@ -2687,9 +2684,6 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) { ParseType(RetType, RetTypeLoc, true /*void allowed*/)) return true; - if (!isDefine && UnnamedAddr) - return Error(UnnamedAddrLoc, "only definitions can have unnamed_addr"); - // Verify that the linkage is ok. switch ((GlobalValue::LinkageTypes)Linkage) { case GlobalValue::ExternalLinkage: diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 4b4c72bf27..ec39c93227 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -352,8 +352,6 @@ static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) { unsigned Alignment = std::max(DestGV->getAlignment(), SrcGV->getAlignment()); DestGV->copyAttributesFrom(SrcGV); DestGV->setAlignment(Alignment); - if (SrcGV->hasUnnamedAddr()) - DestGV->setUnnamedAddr(true); } /// GetLinkageResult - This analyzes the two global values and determines what @@ -521,6 +519,8 @@ static bool LinkGlobals(Module *Dest, const Module *Src, continue; } + bool HasUnnamedAddr = SGV->hasUnnamedAddr() && DGV->hasUnnamedAddr(); + // If the visibilities of the symbols disagree and the destination is a // prototype, take the visibility of its input. if (DGV->isDeclaration()) @@ -565,6 +565,9 @@ static bool LinkGlobals(Module *Dest, const Module *Src, DGV->getName(), 0, false, SGV->getType()->getAddressSpace()); + // Set the unnamed_addr. + NewDGV->setUnnamedAddr(HasUnnamedAddr); + // Propagate alignment, section, and visibility info. CopyGVAttributes(NewDGV, SGV); DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV, @@ -609,8 +612,9 @@ static bool LinkGlobals(Module *Dest, const Module *Src, "': symbol multiple defined"); } - // Set calculated linkage + // Set calculated linkage and unnamed_addr DGV->setLinkage(NewLinkage); + DGV->setUnnamedAddr(HasUnnamedAddr); // Make sure to remember this mapping... ValueMap[SGV] = ConstantExpr::getBitCast(DGV, SGV->getType()); diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index ee62a29eee..58ec6fe88d 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -469,8 +469,6 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) { Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() || GV.hasExternalWeakLinkage(), "invalid linkage type for global declaration", &GV); - Assert1(!GV.hasUnnamedAddr(), "only definitions can have unnamed_addr", - &GV); } visitGlobalValue(GV); @@ -727,7 +725,6 @@ void Verifier::visitFunction(Function &F) { Assert1(F.hasExternalLinkage() || F.hasDLLImportLinkage() || F.hasExternalWeakLinkage(), "invalid linkage type for function declaration", &F); - Assert1(!F.hasUnnamedAddr(), "only definitions can have unnamed_addr", &F); } else { // Verify that this function (which has a body) is not named "llvm.*". It // is not legal to define intrinsics. |