Skip to content

Commit 98d242d

Browse files
author
git apple-llvm automerger
committed
Merge commit '16ec00eee7e3' from llvm.org/master into apple/master
2 parents 7e28ecb + 16ec00e commit 98d242d

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

llvm/lib/Transforms/Utils/FunctionImportUtils.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,22 @@ void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
239239
// propagateConstants hasn't been run. We can't internalize GV
240240
// in such case.
241241
if (!GV.isDeclaration() && VI && ImportIndex.withGlobalValueDeadStripping()) {
242-
const auto &SL = VI.getSummaryList();
243-
auto *GVS = SL.empty() ? nullptr : dyn_cast<GlobalVarSummary>(SL[0].get());
244-
// At this stage "maybe" is "definitely"
245-
if (GVS && (GVS->maybeReadOnly() || GVS->maybeWriteOnly()))
246-
cast<GlobalVariable>(&GV)->addAttribute("thinlto-internalize");
242+
if (GlobalVariable *V = dyn_cast<GlobalVariable>(&GV)) {
243+
// We can have more than one local with the same GUID, in the case of
244+
// same-named locals in different but same-named source files that were
245+
// compiled in their respective directories (so the source file name
246+
// and resulting GUID is the same). Find the one in this module.
247+
// Handle the case where there is no summary found in this module. That
248+
// can happen in the distributed ThinLTO backend, because the index only
249+
// contains summaries from the source modules if they are being imported.
250+
// We might have a non-null VI and get here even in that case if the name
251+
// matches one in this module (e.g. weak or appending linkage).
252+
auto* GVS = dyn_cast_or_null<GlobalVarSummary>(
253+
ImportIndex.findSummaryInModule(VI, M.getModuleIdentifier()));
254+
// At this stage "maybe" is "definitely"
255+
if (GVS && (GVS->maybeReadOnly() || GVS->maybeWriteOnly()))
256+
V->addAttribute("thinlto-internalize");
257+
}
247258
}
248259

249260
bool DoPromote = false;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2+
target triple = "x86_64-pc-linux-gnu"
3+
4+
; The source for the GUID for this symbol will be -:F
5+
source_filename = "-"
6+
define internal fastcc i64 @F() {
7+
ret i64 0
8+
}
9+
10+
@llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
11+
12+
define i64 @G() {
13+
;%1 = load i32, i32* @dummy2, align 4
14+
ret i64 0
15+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; Make sure LTO succeeds even if %t.bc contains a GlobalVariable F and
2+
; %t2.bc cointains a Function F with the same GUID.
3+
;
4+
; RUN: opt -module-summary %s -o %t.bc
5+
; RUN: opt -module-summary %p/Inputs/guid_collision.ll -o %t2.bc
6+
; RUN: llvm-lto2 run %t.bc %t2.bc -o %t.out -save-temps \
7+
; RUN: -r=%t.bc,H,px -r=%t.bc,G, -r=%t2.bc,G,px
8+
; RUN: llvm-dis -o - %t.out.1.3.import.bc | FileCheck %s
9+
10+
; RUN: llvm-lto2 run %t.bc %t2.bc -o %t.out -thinlto-distributed-indexes \
11+
; RUN: -r=%t.bc,H,px -r=%t.bc,G, -r=%t2.bc,G,px
12+
; RUN: opt -function-import -import-all-index -summary-file %t.bc.thinlto.bc %t.bc -o %t.out
13+
; RUN: llvm-dis -o - %t.out | FileCheck %s
14+
15+
; Sanity check that G was imported
16+
; CHECK: define available_externally i64 @G
17+
18+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19+
target triple = "x86_64-pc-linux-gnu"
20+
21+
; The source for the GUID for this symbol will be -:F
22+
source_filename = "-"
23+
24+
@F = internal constant i8 0
25+
26+
; Provide a global that has the same name as one from the module we import G
27+
; from, to test handling of a global variable with an entry in the distributed
28+
; index but not with a copy in the source module (since we can't import
29+
; appending linkage globals).
30+
@llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
31+
32+
define i64 @H() {
33+
call i64 @G()
34+
ret i64 0
35+
}
36+
37+
declare i64 @G()

0 commit comments

Comments
 (0)