diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2018-01-11 22:15:05 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2018-01-11 22:15:05 +0000 |
| commit | e4b0231c63d40408d06ff4c3669ded4b4ecaaa85 (patch) | |
| tree | 9e89f032c39da53ab74bd3d38a87264e2b5ceaa4 /llvm/lib/IR | |
| parent | e97654b2f28072ad9123006c05e03efd82852982 (diff) | |
| download | bcm5719-llvm-e4b0231c63d40408d06ff4c3669ded4b4ecaaa85.tar.gz bcm5719-llvm-e4b0231c63d40408d06ff4c3669ded4b4ecaaa85.zip | |
Make internal/private GVs implicitly dso_local.
While updating clang tests for having clang set dso_local I noticed
that:
- There are *a lot* of tests to update.
- Many of the updates are redundant.
They are redundant because a GV is "obviously dso_local". This patch
starts formalizing that a bit by requiring that internal and private
GVs be dso_local too. Since they all are, we don't have to print
dso_local to the textual representation, making it a bit more compact
and easier to read.
llvm-svn: 322317
Diffstat (limited to 'llvm/lib/IR')
| -rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 12 | ||||
| -rw-r--r-- | llvm/lib/IR/Verifier.cpp | 5 |
2 files changed, 12 insertions, 5 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 0fafe82404e..27a75927832 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -2497,8 +2497,10 @@ static void PrintVisibility(GlobalValue::VisibilityTypes Vis, } } -static void PrintDSOLocation(bool IsDSOLocal, formatted_raw_ostream &Out){ - if (IsDSOLocal) +static void PrintDSOLocation(const GlobalValue &GV, + formatted_raw_ostream &Out) { + // GVs with local linkage are implicitly dso_local, so we don't print it. + if (GV.isDSOLocal() && !GV.hasLocalLinkage()) Out << "dso_local "; } @@ -2572,7 +2574,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { Out << "external "; Out << getLinkagePrintName(GV->getLinkage()); - PrintDSOLocation(GV->isDSOLocal(), Out); + PrintDSOLocation(*GV, Out); PrintVisibility(GV->getVisibility(), Out); PrintDLLStorageClass(GV->getDLLStorageClass(), Out); PrintThreadLocalModel(GV->getThreadLocalMode(), Out); @@ -2619,7 +2621,7 @@ void AssemblyWriter::printIndirectSymbol(const GlobalIndirectSymbol *GIS) { Out << " = "; Out << getLinkagePrintName(GIS->getLinkage()); - PrintDSOLocation(GIS->isDSOLocal(), Out); + PrintDSOLocation(*GIS, Out); PrintVisibility(GIS->getVisibility(), Out); PrintDLLStorageClass(GIS->getDLLStorageClass(), Out); PrintThreadLocalModel(GIS->getThreadLocalMode(), Out); @@ -2731,7 +2733,7 @@ void AssemblyWriter::printFunction(const Function *F) { Out << "define "; Out << getLinkagePrintName(F->getLinkage()); - PrintDSOLocation(F->isDSOLocal(), Out); + PrintDSOLocation(*F, Out); PrintVisibility(F->getVisibility(), Out); PrintDLLStorageClass(F->getDLLStorageClass(), Out); diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index b83201f982f..1a964dfb731 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -570,6 +570,11 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) { Assert(!GV.isDSOLocal(), "GlobalValue with DLLImport Storage is dso_local!", &GV); + if (GV.hasLocalLinkage()) + Assert(GV.isDSOLocal(), + "GlobalValue with private or internal linkage must be dso_local!", + &GV); + forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool { if (const Instruction *I = dyn_cast<Instruction>(V)) { if (!I->getParent() || !I->getParent()->getParent()) |

