Skip to content

Commit f3dafbf

Browse files
committed
SIL: make unchecked_ref_cast buildable in a global variable initializer
1 parent db9232f commit f3dafbf

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,11 @@ class SILBuilder {
12791279
UncheckedRefCastInst *
12801280
createUncheckedRefCast(SILLocation Loc, SILValue Op, SILType Ty,
12811281
ValueOwnershipKind forwardingOwnershipKind) {
1282+
if (isInsertingIntoGlobal()) {
1283+
return insert(UncheckedRefCastInst::create(
1284+
getSILDebugLocation(Loc), Op, Ty, getModule(),
1285+
forwardingOwnershipKind));
1286+
}
12821287
return insert(UncheckedRefCastInst::create(
12831288
getSILDebugLocation(Loc), Op, Ty, getFunction(),
12841289
forwardingOwnershipKind));

include/swift/SIL/SILInstruction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5964,6 +5964,10 @@ class UncheckedRefCastInst final
59645964
static UncheckedRefCastInst *
59655965
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
59665966
SILFunction &F, ValueOwnershipKind forwardingOwnershipKind);
5967+
5968+
static UncheckedRefCastInst *
5969+
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
5970+
SILModule &Mod, ValueOwnershipKind forwardingOwnershipKind);
59675971
};
59685972

59695973
/// Convert a value's binary representation to a trivial type of the same size.

lib/SIL/IR/SILInstructions.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,6 +2588,17 @@ BeginCOWMutationInst::create(SILDebugLocation loc, SILValue operand,
25882588
isNative);
25892589
}
25902590

2591+
UncheckedRefCastInst *
2592+
UncheckedRefCastInst::create(SILDebugLocation DebugLoc, SILValue Operand,
2593+
SILType Ty, SILModule &Mod,
2594+
ValueOwnershipKind forwardingOwnershipKind) {
2595+
assert(Operand->getType().getCategory() == SILValueCategory::Object);
2596+
unsigned size = totalSizeToAlloc<swift::Operand>(1);
2597+
void *Buffer = Mod.allocateInst(size, alignof(UncheckedRefCastInst));
2598+
return ::new (Buffer) UncheckedRefCastInst(
2599+
DebugLoc, Operand, {}, Ty, forwardingOwnershipKind);
2600+
}
2601+
25912602
UncheckedRefCastInst *
25922603
UncheckedRefCastInst::create(SILDebugLocation DebugLoc, SILValue Operand,
25932604
SILType Ty, SILFunction &F,

0 commit comments

Comments
 (0)