[PATCH] D36440: [ThinLTO] Fix thinLTO crash
David Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 7 21:02:21 PDT 2017
davidxl created this revision.
Herald added subscribers: inglorion, sanjoy.
Compiling a simple program with a call to an external function with the same linkage name as a file static variable in another module with thinLTO, the compiler will crash. This patch fixed the problem.
https://reviews.llvm.org/D36440
Files:
lib/Transforms/IPO/FunctionImport.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/Transforms/IPO/FunctionImport.cpp
===================================================================
--- lib/Transforms/IPO/FunctionImport.cpp
+++ lib/Transforms/IPO/FunctionImport.cpp
@@ -129,6 +129,10 @@
CalleeSummaryList,
[&](const std::unique_ptr<GlobalValueSummary> &SummaryPtr) {
auto *GVSummary = SummaryPtr.get();
+
+ if (GVSummary->getSummaryKind() ==
+ GlobalValueSummary::SummaryKind::GlobalVarKind)
+ return false;
if (GlobalValue::isInterposableLinkage(GVSummary->linkage()))
// There is no point in importing these, we can't inline them
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36440.110131.patch
Type: text/x-patch
Size: 1917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170808/95805516/attachment.bin>
More information about the llvm-commits
mailing list