diff options
author | Duncan Sands <baldrick@free.fr> | 2009-03-07 15:45:40 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2009-03-07 15:45:40 +0000 |
commit | 19d161f714b83cd850fe489aa3fdaa3d3744157b (patch) | |
tree | 7c3eab01e7683698c4818410c678d6af0ebfa56b /lib/AsmParser/LLParser.cpp | |
parent | 7fc2b3595c3891ea9d5c0951a9005db232d3e47e (diff) | |
download | external_llvm-19d161f714b83cd850fe489aa3fdaa3d3744157b.zip external_llvm-19d161f714b83cd850fe489aa3fdaa3d3744157b.tar.gz external_llvm-19d161f714b83cd850fe489aa3fdaa3d3744157b.tar.bz2 |
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser/LLParser.cpp')
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 19f8415..90dd507 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -116,12 +116,16 @@ bool LLParser::ParseTopLevelEntities() { case lltok::kw_private: // OptionalLinkage case lltok::kw_internal: // OptionalLinkage case lltok::kw_weak: // OptionalLinkage + case lltok::kw_weak_odr: // OptionalLinkage case lltok::kw_linkonce: // OptionalLinkage + case lltok::kw_linkonce_odr: // OptionalLinkage case lltok::kw_appending: // OptionalLinkage case lltok::kw_dllexport: // OptionalLinkage case lltok::kw_common: // OptionalLinkage + case lltok::kw_common_odr: // OptionalLinkage case lltok::kw_dllimport: // OptionalLinkage case lltok::kw_extern_weak: // OptionalLinkage + case lltok::kw_extern_weak_odr: // OptionalLinkage case lltok::kw_external: { // OptionalLinkage unsigned Linkage, Visibility; if (ParseOptionalLinkage(Linkage) || @@ -377,7 +381,8 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc, return true; if (Linkage != GlobalValue::ExternalLinkage && - Linkage != GlobalValue::WeakLinkage && + Linkage != GlobalValue::WeakAnyLinkage && + Linkage != GlobalValue::WeakODRLinkage && Linkage != GlobalValue::InternalLinkage && Linkage != GlobalValue::PrivateLinkage) return Error(LinkageLoc, "invalid linkage type for alias"); @@ -461,7 +466,8 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc, // present. Constant *Init = 0; if (!HasLinkage || (Linkage != GlobalValue::DLLImportLinkage && - Linkage != GlobalValue::ExternalWeakLinkage && + Linkage != GlobalValue::ExternalWeakAnyLinkage && + Linkage != GlobalValue::ExternalWeakODRLinkage && Linkage != GlobalValue::ExternalLinkage)) { if (ParseGlobalValue(Ty, Init)) return true; @@ -576,10 +582,10 @@ GlobalValue *LLParser::GetGlobalVal(const std::string &Name, const Type *Ty, return 0; } - FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M); + FwdVal = Function::Create(FT, GlobalValue::ExternalWeakAnyLinkage, Name, M); } else { FwdVal = new GlobalVariable(PTy->getElementType(), false, - GlobalValue::ExternalWeakLinkage, 0, Name, M); + GlobalValue::ExternalWeakAnyLinkage, 0, Name, M); } ForwardRefVals[Name] = std::make_pair(FwdVal, Loc); @@ -620,10 +626,10 @@ GlobalValue *LLParser::GetGlobalVal(unsigned ID, const Type *Ty, LocTy Loc) { Error(Loc, "function may not return opaque type"); return 0; } - FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M); + FwdVal = Function::Create(FT, GlobalValue::ExternalWeakAnyLinkage, "", M); } else { FwdVal = new GlobalVariable(PTy->getElementType(), false, - GlobalValue::ExternalWeakLinkage, 0, "", M); + GlobalValue::ExternalWeakAnyLinkage, 0, "", M); } ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc); @@ -746,27 +752,36 @@ bool LLParser::ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind) { /// ::= 'private' /// ::= 'internal' /// ::= 'weak' +/// ::= 'weak_odr' /// ::= 'linkonce' +/// ::= 'linkonce_odr' /// ::= 'appending' /// ::= 'dllexport' /// ::= 'common' +/// ::= 'common_odr' /// ::= 'dllimport' /// ::= 'extern_weak' +/// ::= 'extern_weak_odr' /// ::= 'external' bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) { HasLinkage = false; switch (Lex.getKind()) { - default: Res = GlobalValue::ExternalLinkage; return false; - case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break; - case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break; - case lltok::kw_weak: Res = GlobalValue::WeakLinkage; break; - case lltok::kw_linkonce: Res = GlobalValue::LinkOnceLinkage; break; - case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break; - case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break; - case lltok::kw_common: Res = GlobalValue::CommonLinkage; break; - case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break; - case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakLinkage; break; - case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break; + default: Res = GlobalValue::ExternalLinkage; return false; + case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break; + case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break; + case lltok::kw_weak: Res = GlobalValue::WeakAnyLinkage; break; + case lltok::kw_weak_odr: Res = GlobalValue::WeakODRLinkage; break; + case lltok::kw_linkonce: Res = GlobalValue::LinkOnceAnyLinkage; break; + case lltok::kw_linkonce_odr: Res = GlobalValue::LinkOnceODRLinkage; break; + case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break; + case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break; + case lltok::kw_common: Res = GlobalValue::CommonAnyLinkage; break; + case lltok::kw_common_odr: Res = GlobalValue::CommonODRLinkage; break; + case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break; + case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakAnyLinkage; break; + case lltok::kw_extern_weak_odr: + Res = GlobalValue::ExternalWeakODRLinkage; break; + case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break; } Lex.Lex(); HasLinkage = true; @@ -2074,21 +2089,25 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) { case GlobalValue::ExternalLinkage: break; // always ok. case GlobalValue::DLLImportLinkage: - case GlobalValue::ExternalWeakLinkage: + case GlobalValue::ExternalWeakAnyLinkage: + case GlobalValue::ExternalWeakODRLinkage: if (isDefine) return Error(LinkageLoc, "invalid linkage for function definition"); break; case GlobalValue::PrivateLinkage: case GlobalValue::InternalLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: case GlobalValue::DLLExportLinkage: if (!isDefine) return Error(LinkageLoc, "invalid linkage for function declaration"); break; case GlobalValue::AppendingLinkage: case GlobalValue::GhostLinkage: - case GlobalValue::CommonLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: return Error(LinkageLoc, "invalid function linkage type"); } |