summaryrefslogtreecommitdiffstats
path: root/llvm/lib/AsmParser
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-05-07 22:57:20 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-05-07 22:57:20 +0000
commitb80de1012ae346786dbb019ed6bdf8ba8820d8ab (patch)
treecefe0c88c0db0714dd993397bfcc0685254cd7c1 /llvm/lib/AsmParser
parentb2becfdbaee499538f4d1c8aa514daa29e3c6b6d (diff)
downloadbcm5719-llvm-b80de1012ae346786dbb019ed6bdf8ba8820d8ab.tar.gz
bcm5719-llvm-b80de1012ae346786dbb019ed6bdf8ba8820d8ab.zip
IR: Don't allow non-default visibility on local linkage
Visibilities of `hidden` and `protected` are meaningless for symbols with local linkage. - Change the assembler to reject non-default visibility on symbols with local linkage. - Change the bitcode reader to auto-upgrade `hidden` and `protected` to `default` when the linkage is local. - Update LangRef. <rdar://problem/16141113> llvm-svn: 208263
Diffstat (limited to 'llvm/lib/AsmParser')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 56422393e46..32037df958b 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -622,6 +622,11 @@ bool LLParser::ParseStandaloneMetadata() {
return false;
}
+static bool isValidVisibilityForLinkage(unsigned V, unsigned L) {
+ return !GlobalValue::isLocalLinkage((GlobalValue::LinkageTypes)L) ||
+ (GlobalValue::VisibilityTypes)V == GlobalValue::DefaultVisibility;
+}
+
/// ParseAlias:
/// ::= GlobalVar '=' OptionalVisibility OptionalDLLStorageClass 'alias'
/// OptionalLinkage Aliasee
@@ -646,6 +651,10 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
if(!GlobalAlias::isValidLinkage(Linkage))
return Error(LinkageLoc, "invalid linkage type for alias");
+ if (!isValidVisibilityForLinkage(Visibility, L))
+ return Error(LinkageLoc,
+ "symbol with local linkage must have default visibility");
+
Constant *Aliasee;
LocTy AliaseeLoc = Lex.getLoc();
if (Lex.getKind() != lltok::kw_bitcast &&
@@ -714,6 +723,10 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
unsigned Linkage, bool HasLinkage,
unsigned Visibility, unsigned DLLStorageClass) {
+ if (!isValidVisibilityForLinkage(Visibility, Linkage))
+ return Error(NameLoc,
+ "symbol with local linkage must have default visibility");
+
unsigned AddrSpace;
bool IsConstant, UnnamedAddr, IsExternallyInitialized;
GlobalVariable::ThreadLocalMode TLM;
@@ -3014,6 +3027,10 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
return Error(LinkageLoc, "invalid function linkage type");
}
+ if (!isValidVisibilityForLinkage(Visibility, Linkage))
+ return Error(LinkageLoc,
+ "symbol with local linkage must have default visibility");
+
if (!FunctionType::isValidReturnType(RetType))
return Error(RetTypeLoc, "invalid function return type");
OpenPOWER on IntegriCloud