Skip to content

IRGen: Work around JIT bug with GOT equivalents. #24944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,8 @@ llvm::Function *IRGenModule::getAddrOfSILFunction(

static llvm::GlobalVariable *createGOTEquivalent(IRGenModule &IGM,
llvm::Constant *global,
LinkEntity entity) {
LinkEntity entity)
{
// Determine the name of this entity.
llvm::SmallString<64> globalName;
entity.mangle(globalName);
Expand All @@ -2419,7 +2420,17 @@ static llvm::GlobalVariable *createGOTEquivalent(IRGenModule &IGM,
llvm::GlobalValue::PrivateLinkage,
global,
llvm::Twine("got.") + globalName);
gotEquivalent->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);

// rdar://problem/50968433: Unnamed_addr constants appear to get emitted
// with incorrect alignment by the LLVM JIT in some cases. Don't use
// unnamed_addr as a workaround.
if (!IGM.getOptions().UseJIT) {
gotEquivalent->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
} else {
ApplyIRLinkage(IRLinkage::InternalLinkOnceODR)
.to(gotEquivalent);
}

return gotEquivalent;
}

Expand Down
17 changes: 17 additions & 0 deletions test/Interpreter/external_key_path_ref.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test

struct Container<Base, Value, Content>
where Base: Collection
{
var base: Base
var elementPath: KeyPath<Base.Element, Value>
var content: (Value) -> Content
}

let x = Container(base: 1...10, elementPath: \.bitWidth) {
return String($0, radix: 2)
}

// CHECK: i hope we passed the audition
print("i hope we passed the audition")