[llvm] r295861 - [ModuleSummaryAnalysis] Don't crash when referencing unnamed globals.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 10:53:38 PST 2017


Author: davide
Date: Wed Feb 22 12:53:38 2017
New Revision: 295861

URL: http://llvm.org/viewvc/llvm-project?rev=295861&view=rev
Log:
[ModuleSummaryAnalysis] Don't crash when referencing unnamed globals.

Instead, just be conservative as these are unfrequent enough. Thanks
to Peter Collingbourne for the discussion about this on IRC.

Added:
    llvm/trunk/test/Transforms/FunctionImport/unnamed-globals.ll
Modified:
    llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp?rev=295861&r1=295860&r2=295861&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp Wed Feb 22 12:53:38 2017
@@ -447,6 +447,12 @@ ModuleSummaryIndex llvm::buildModuleSumm
     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) {

Added: llvm/trunk/test/Transforms/FunctionImport/unnamed-globals.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionImport/unnamed-globals.ll?rev=295861&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/FunctionImport/unnamed-globals.ll (added)
+++ llvm/trunk/test/Transforms/FunctionImport/unnamed-globals.ll Wed Feb 22 12:53:38 2017
@@ -0,0 +1,10 @@
+; Make sure we don't crash when referencing an unnamed global.
+; RUN: opt %s -module-summary-analysis -S
+
+ at 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)




More information about the llvm-commits mailing list