Skip to content

5.9: [IRGen] Cast fixed-size opaque globals. #67997

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
Aug 18, 2023
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
23 changes: 14 additions & 9 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2958,25 +2958,30 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) {
Address addr = IGM.getAddrOfSILGlobalVariable(var, ti,
NotForDefinition);

// Get the address of the type in context.
auto getAddressInContext = [this, &var](auto addr) -> Address {
SILType loweredTyInContext =
var->getLoweredTypeInContext(getExpansionContext());
auto &tiInContext = getTypeInfo(loweredTyInContext);
auto ptr = Builder.CreateBitOrPointerCast(
addr.getAddress(), tiInContext.getStorageType()->getPointerTo());
addr = Address(ptr, tiInContext.getStorageType(),
tiInContext.getBestKnownAlignment());
return addr;
};

// If the global is fixed-size in all resilience domains that can see it,
// we allocated storage for it statically, and there's nothing to do.
if (ti.isFixedSize(expansion)) {
addr = getAddressInContext(addr);
setLoweredAddress(i, addr);
return;
}

// Otherwise, the static storage for the global consists of a fixed-size
// buffer; project it.
addr = emitProjectValueInBuffer(*this, loweredTy, addr);


// Get the address of the type in context.
SILType loweredTyInContext = var->getLoweredTypeInContext(getExpansionContext());
auto &tiInContext = getTypeInfo(loweredTyInContext);
auto ptr = Builder.CreateBitOrPointerCast(addr.getAddress(),
tiInContext.getStorageType()->getPointerTo());
addr = Address(ptr, tiInContext.getStorageType(),
tiInContext.getBestKnownAlignment());
addr = getAddressInContext(addr);
setLoweredAddress(i, addr);
}

Expand Down
11 changes: 11 additions & 0 deletions validation-test/IRGen/rdar114013709.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %target-swift-frontend -O -primary-file %s -disable-availability-checking -emit-ir | %FileCheck %s

// CHECK: define{{( dllexport)?}}{{( protected)?}} i32 @main{{.*}} {
// CHECK: store %swift.refcounted* %{{[0-9]+}},
// CHECK-SAME: %swift.refcounted**
// CHECK-SAME: bitcast (
// CHECK-SAME: %T13rdar1140137095ActorC** @"$s13rdar1140137091xQrvp"
// CHECK-SAME: to %swift.refcounted**)
actor Actor {}
let x: some Actor = Actor()