Skip to content

Commit 3a1771c

Browse files
authored
Merge pull request #24944 from jckarter/keypath-jit-workaround
IRGen: Work around JIT bug with GOT equivalents.
2 parents c0b0536 + 81c7f84 commit 3a1771c

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,8 @@ llvm::Function *IRGenModule::getAddrOfSILFunction(
23962396

23972397
static llvm::GlobalVariable *createGOTEquivalent(IRGenModule &IGM,
23982398
llvm::Constant *global,
2399-
LinkEntity entity) {
2399+
LinkEntity entity)
2400+
{
24002401
// Determine the name of this entity.
24012402
llvm::SmallString<64> globalName;
24022403
entity.mangle(globalName);
@@ -2419,7 +2420,17 @@ static llvm::GlobalVariable *createGOTEquivalent(IRGenModule &IGM,
24192420
llvm::GlobalValue::PrivateLinkage,
24202421
global,
24212422
llvm::Twine("got.") + globalName);
2422-
gotEquivalent->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2423+
2424+
// rdar://problem/50968433: Unnamed_addr constants appear to get emitted
2425+
// with incorrect alignment by the LLVM JIT in some cases. Don't use
2426+
// unnamed_addr as a workaround.
2427+
if (!IGM.getOptions().UseJIT) {
2428+
gotEquivalent->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2429+
} else {
2430+
ApplyIRLinkage(IRLinkage::InternalLinkOnceODR)
2431+
.to(gotEquivalent);
2432+
}
2433+
24232434
return gotEquivalent;
24242435
}
24252436

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-run-simple-swift
2+
// REQUIRES: executable_test
3+
4+
struct Container<Base, Value, Content>
5+
where Base: Collection
6+
{
7+
var base: Base
8+
var elementPath: KeyPath<Base.Element, Value>
9+
var content: (Value) -> Content
10+
}
11+
12+
let x = Container(base: 1...10, elementPath: \.bitWidth) {
13+
return String($0, radix: 2)
14+
}
15+
16+
// CHECK: i hope we passed the audition
17+
print("i hope we passed the audition")

0 commit comments

Comments
 (0)