[PATCH] D26880: [ThinLTO] Fix crash: transitively referenced global shouldn't be promoted

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 18 18:48:57 PST 2016


mehdi_amini created this revision.
mehdi_amini added a reviewer: tejohnson.
mehdi_amini added a subscriber: llvm-commits.

https://reviews.llvm.org/D26880

Files:
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/test/ThinLTO/X86/Inputs/reference_non_importable.ll
  llvm/test/ThinLTO/X86/reference_non_importable.ll


Index: llvm/test/ThinLTO/X86/reference_non_importable.ll
===================================================================
--- /dev/null
+++ llvm/test/ThinLTO/X86/reference_non_importable.ll
@@ -0,0 +1,28 @@
+; RUN: opt -module-summary %s -o %t1.bc
+; RUN: opt -module-summary %p/Inputs/reference_non_importable.ll -o %t2.bc
+
+; RUN: llvm-lto2 %t1.bc %t2.bc -o %t.o -save-temps \
+; RUN:     -r=%t1.bc,_foo,pxl \
+; RUN:     -r=%t1.bc,_b,pxl \
+; RUN:     -r=%t2.bc,_main,pxl \
+; RUN:     -r=%t2.bc,_foo,xl
+
+
+
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+; We shouldn't promote the private because it has a section
+; RUN: llvm-dis < %t.o.0.2.internalize.bc | FileCheck  %s --check-prefix=PROMOTE
+; PROMOTE: @a = private global i8 0, section "__TEXT,__cstring,cstring_literals"
+ at a = private global i8 0, section "__TEXT,__cstring,cstring_literals"
+ at b = global i8 *@a
+
+
+; We want foo to be imported in the main module!
+; RUN: llvm-dis < %t.o.1.3.import.bc  | FileCheck  %s --check-prefix=IMPORT
+; IMPORT: define available_externally i8** @foo()
+define i8 **@foo() {
+	ret i8 **@b
+}
Index: llvm/test/ThinLTO/X86/Inputs/reference_non_importable.ll
===================================================================
--- /dev/null
+++ llvm/test/ThinLTO/X86/Inputs/reference_non_importable.ll
@@ -0,0 +1,8 @@
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+declare i8 **@foo()
+define i32 @main() {
+    call i8 **@foo()
+	ret i32 0
+}
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -268,18 +268,6 @@
   auto GVS = dyn_cast<GlobalVarSummary>(Summary);
   if (!GVS)
     return;
-  // FunctionImportGlobalProcessing::doPromoteLocalToGlobal() will always
-  // trigger importing  the initializer for `constant unnamed addr` globals that
-  // are referenced. We conservatively export all the referenced symbols for
-  // every global to workaround this, so that the ExportList is accurate.
-  // FIXME: with a "isConstant" flag in the summary we could be more targetted.
-  for (auto &Ref : GVS->refs()) {
-    auto GUID = Ref.getGUID();
-    auto *RefSummary = FindGlobalSummaryInModule(GUID);
-    if (RefSummary)
-      // Found a ref in the current module, mark it as exported
-      ExportList.insert(GUID);
-  }
 }
 
 using EdgeInfo = std::pair<const FunctionSummary *, unsigned /* Threshold */>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26880.78611.patch
Type: text/x-patch
Size: 2610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161119/ba0a10b5/attachment.bin>


More information about the llvm-commits mailing list