Skip to content
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
43 changes: 29 additions & 14 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3628,21 +3628,36 @@ visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E, SGFContext C) {
SGF.getLoweredType(UnsafeRawPointer->getDeclaredInterfaceType());
SILType BuiltinRawPtrTy = SILType::getRawPointerType(SGF.getASTContext());

SILModule &M = SGF.SGM.M;
SILBuilder &B = SGF.B;

StructInst *S = nullptr;
if (M.getASTContext().LangOpts.Target.isOSWindows()) {
auto ImageBase = M.lookUpGlobalVariable("__ImageBase");
if (!ImageBase)
ImageBase =
SILGlobalVariable::create(M, SILLinkage::Public, IsNotSerialized,
"__ImageBase", BuiltinRawPtrTy);

auto ImageBaseAddr = B.createGlobalAddr(SILLoc, ImageBase);
auto ImageBasePointer =
B.createAddressToPointer(SILLoc, ImageBaseAddr, BuiltinRawPtrTy);
S = B.createStruct(SILLoc, UnsafeRawPtrTy, { ImageBasePointer });
} else {
auto DSOGlobal = M.lookUpGlobalVariable("__dso_handle");
if (!DSOGlobal)
DSOGlobal =
SILGlobalVariable::create(M, SILLinkage::PublicExternal,
IsNotSerialized, "__dso_handle",
BuiltinRawPtrTy);

auto DSOAddr = B.createGlobalAddr(SILLoc, DSOGlobal);
auto DSOPointer =
B.createAddressToPointer(SILLoc, DSOAddr, BuiltinRawPtrTy);
S = B.createStruct(SILLoc, UnsafeRawPtrTy, { DSOPointer });
}

auto DSOGlobal = SGF.SGM.M.lookUpGlobalVariable("__dso_handle");
if (!DSOGlobal)
DSOGlobal = SILGlobalVariable::create(SGF.SGM.M,
SILLinkage::PublicExternal,
IsNotSerialized, "__dso_handle",
BuiltinRawPtrTy);
auto DSOAddr = SGF.B.createGlobalAddr(SILLoc, DSOGlobal);

auto DSOPointer = SGF.B.createAddressToPointer(SILLoc, DSOAddr,
BuiltinRawPtrTy);

auto UnsafeRawPtrStruct = SGF.B.createStruct(SILLoc, UnsafeRawPtrTy,
{ DSOPointer });
return RValue(SGF, E, ManagedValue::forUnmanaged(UnsafeRawPtrStruct));
return RValue(SGF, E, ManagedValue::forUnmanaged(S));
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/default_arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func takeDSOHandle(_ handle: UnsafeRawPointer = #dsohandle) { }

// CHECK-LABEL: sil hidden [ossa] @$s17default_arguments13testDSOHandleyyF
func testDSOHandle() {
// CHECK: [[DSO_HANDLE:%[0-9]+]] = global_addr @__dso_handle : $*Builtin.RawPointer
// CHECK: [[DSO_HANDLE:%[0-9]+]] = global_addr {{@__dso_handle|@__ImageBase}} : $*Builtin.RawPointer
takeDSOHandle()
}

Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/dso_handle.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-swift-emit-silgen -Xllvm -sil-full-demangle %s | %FileCheck %s

// CHECK: sil_global [[DSO:@__dso_handle]] : $Builtin.RawPointer
// CHECK: sil_global [[DSO:@__dso_handle|@__ImageBase]] : $Builtin.RawPointer

// CHECK-LABEL: sil [ossa] @main : $@convention(c)
// CHECK: bb0
Expand Down