]> granicus.if.org Git - llvm/commitdiff
[PGO] Fix ThinLTO crash
authorXinliang David Li <davidxl@google.com>
Wed, 16 Aug 2017 17:18:01 +0000 (17:18 +0000)
committerXinliang David Li <davidxl@google.com>
Wed, 16 Aug 2017 17:18:01 +0000 (17:18 +0000)
Differential Revsion: http://reviews.llvm.org/D36640

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311023 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Writer/BitcodeWriter.cpp
test/Transforms/FunctionImport/Inputs/funcimport_var2.ll [new file with mode: 0644]
test/Transforms/FunctionImport/funcimport_var.ll [new file with mode: 0644]

index fc58718df1f62f3aebb3a21450a6be09f25fd082..e3b43b333a19b086e286919778c6d4ab2b313502 100644 (file)
@@ -3626,6 +3626,12 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
         CallValueId = getValueId(GUID);
         if (!CallValueId)
           continue;
+        // The mapping from OriginalId to GUID may return a GUID
+        // that corresponds to a static varible. Filter it out here.
+        auto *GVSum = Index.getGlobalValueSummary(GUID, false);
+        if (GVSum &&
+            GVSum->getSummaryKind() == GlobalValueSummary::GlobalVarKind)
+          continue;
       }
       NameVals.push_back(*CallValueId);
       if (HasProfileData)
diff --git a/test/Transforms/FunctionImport/Inputs/funcimport_var2.ll b/test/Transforms/FunctionImport/Inputs/funcimport_var2.ll
new file mode 100644 (file)
index 0000000..88aa798
--- /dev/null
@@ -0,0 +1,7 @@
+@link = internal global i32 0, align 4
+
+; Function Attrs: norecurse nounwind readnone uwtable
+define nonnull i32* @get_link() local_unnamed_addr {
+  ret i32* @link
+}
+
diff --git a/test/Transforms/FunctionImport/funcimport_var.ll b/test/Transforms/FunctionImport/funcimport_var.ll
new file mode 100644 (file)
index 0000000..b749ec4
--- /dev/null
@@ -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