summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Analysis/ModuleSummaryAnalysis.cpp6
-rw-r--r--llvm/test/Transforms/FunctionImport/unnamed-globals.ll10
2 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 70b55674c07..950b8987c5b 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -447,6 +447,12 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
auto &Summary = GlobalList.second[0];
bool AllRefsCanBeExternallyReferenced =
llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
+ // If a global value definition references an unnamed global,
+ // be conservative. They're valid IR so we don't want to crash
+ // when we encounter any of them but they're infrequent enough
+ // that we don't bother optimizing them.
+ if (!VI.getValue()->hasName())
+ return false;
return !CantBePromoted.count(VI.getValue()->getGUID());
});
if (!AllRefsCanBeExternallyReferenced) {
diff --git a/llvm/test/Transforms/FunctionImport/unnamed-globals.ll b/llvm/test/Transforms/FunctionImport/unnamed-globals.ll
new file mode 100644
index 00000000000..167fad28f43
--- /dev/null
+++ b/llvm/test/Transforms/FunctionImport/unnamed-globals.ll
@@ -0,0 +1,10 @@
+; Make sure we don't crash when referencing an unnamed global.
+; RUN: opt %s -module-summary-analysis -S
+
+@0 = external global [1 x { i64 }]
+
+define internal void @tinkywinky() {
+ call void @patatino(i64 ptrtoint ([1 x { i64 }]* @0 to i64), i64 4)
+ ret void
+}
+declare void @patatino(i64, i64)
OpenPOWER on IntegriCloud