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>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208263 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2014-05-07 22:57:20 +00:00
parent c7e175a743
commit 76c17d324c
23 changed files with 199 additions and 25 deletions

View File

@ -1856,7 +1856,9 @@ error_code BitcodeReader::ParseModule(bool Resume) {
Section = SectionTable[Record[5]-1];
}
GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility;
if (Record.size() > 6)
// Local linkage must have default visibility.
if (Record.size() > 6 && !GlobalValue::isLocalLinkage(Linkage))
// FIXME: Change to an error if non-default in 4.0.
Visibility = GetDecodedVisibility(Record[6]);
GlobalVariable::ThreadLocalMode TLM = GlobalVariable::NotThreadLocal;
@ -1922,7 +1924,10 @@ error_code BitcodeReader::ParseModule(bool Resume) {
return Error(InvalidID);
Func->setSection(SectionTable[Record[6]-1]);
}
Func->setVisibility(GetDecodedVisibility(Record[7]));
// Local linkage must have default visibility.
if (!Func->hasLocalLinkage())
// FIXME: Change to an error if non-default in 4.0.
Func->setVisibility(GetDecodedVisibility(Record[7]));
if (Record.size() > 8 && Record[8]) {
if (Record[8]-1 > GCTable.size())
return Error(InvalidID);
@ -1964,7 +1969,9 @@ error_code BitcodeReader::ParseModule(bool Resume) {
GlobalAlias *NewGA = new GlobalAlias(Ty, GetDecodedLinkage(Record[2]),
"", nullptr, TheModule);
// Old bitcode files didn't have visibility field.
if (Record.size() > 3)
// Local linkage must have default visibility.
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
// FIXME: Change to an error if non-default in 4.0.
NewGA->setVisibility(GetDecodedVisibility(Record[3]));
if (Record.size() > 4)
NewGA->setDLLStorageClass(GetDecodedDLLStorageClass(Record[4]));