[PATCH] D36440: [ThinLTO] Fix thinLTO crash

David Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 10:50:43 PDT 2017


davidxl updated this revision to Diff 110772.
davidxl added a comment.

Update the fix.


https://reviews.llvm.org/D36440

Files:
  lib/Bitcode/Writer/BitcodeWriter.cpp
  test/Transforms/FunctionImport/Inputs/funcimport_var2.ll
  test/Transforms/FunctionImport/funcimport_var.ll


Index: test/Transforms/FunctionImport/funcimport_var.ll
===================================================================
--- test/Transforms/FunctionImport/funcimport_var.ll
+++ test/Transforms/FunctionImport/funcimport_var.ll
@@ -0,0 +1,13 @@
+; This test makes sure a static var is not selected as a callee target
+; (which will crash compilation).
+; RUN: opt -module-summary %s -o %t.bc
+; RUN: opt -module-summary %p/Inputs/funcimport_var2.ll -o %t2.bc
+; RUN: llvm-lto -thinlto -thinlto-action=thinlink -o %t3 %t.bc %t2.bc
+; RUN: llvm-lto -thinlto -thinlto-action=import -thinlto-index=%t3 %t.bc %t2.bc
+define i32 @_Z4LinkPKcS0_(i8*, i8*) local_unnamed_addr  {
+  %3 = tail call i32 @link(i8* %0, i8* %1) #2
+  ret i32 %3
+}
+
+; Function Attrs: nounwind
+declare i32 @link(i8*, i8*) local_unnamed_addr 
Index: test/Transforms/FunctionImport/Inputs/funcimport_var2.ll
===================================================================
--- test/Transforms/FunctionImport/Inputs/funcimport_var2.ll
+++ test/Transforms/FunctionImport/Inputs/funcimport_var2.ll
@@ -0,0 +1,7 @@
+ at link = internal global i32 0, align 4
+
+; Function Attrs: norecurse nounwind readnone uwtable
+define nonnull i32* @get_link() local_unnamed_addr {
+  ret i32* @link
+}
+
Index: lib/Bitcode/Writer/BitcodeWriter.cpp
===================================================================
--- lib/Bitcode/Writer/BitcodeWriter.cpp
+++ lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3624,6 +3624,10 @@
         CallValueId = getValueId(GUID);
         if (!CallValueId)
           continue;
+        auto *GVSum = Index.getGlobalValueSummary(GUID, false);
+        if (GVSum &&
+            GVSum->getSummaryKind() == GlobalValueSummary::GlobalVarKind)
+          continue;
       }
       NameVals.push_back(*CallValueId);
       if (HasProfileData)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36440.110772.patch
Type: text/x-patch
Size: 1825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170811/c1cb9b6a/attachment.bin>


More information about the llvm-commits mailing list