Skip to content

Commit df38313

Browse files
committed
The metatype operand on AllocRefDynamicInst is not always at index 1, use getNumTailTypes()
1 parent c7a5569 commit df38313

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyAllocRefDynamic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ extension AllocRefDynamicInst : OnoneSimplifyable {
2626
/// %8 = (... some use of ...) %7 : $BaseClass
2727

2828
let type: Type
29-
if let metatypeInst = operands[1].value as? MetatypeInst {
29+
if let metatypeInst = metatypeOperand.value as? MetatypeInst {
3030
type = metatypeInst.type.loweredInstanceTypeOfMetatype(in: parentFunction)
31-
} else if let upcastInst = operands[1].value as? UpcastInst,
31+
} else if let upcastInst = metatypeOperand.value as? UpcastInst,
3232
let metatypeInst = upcastInst.operands[0].value as? MetatypeInst {
3333
type = metatypeInst.type.loweredInstanceTypeOfMetatype(in: parentFunction)
3434
} else {

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,11 @@ final public class AllocRefDynamicInst : AllocRefInstBase {
11961196
public var isDynamicTypeDeinitAndSizeKnownEquivalentToBaseType: Bool {
11971197
bridged.AllocRefDynamicInst_isDynamicTypeDeinitAndSizeKnownEquivalentToBaseType()
11981198
}
1199+
1200+
public var metatypeOperand: Operand {
1201+
let numTailTypes = bridged.AllocRefInstBase_getNumTailTypes()
1202+
return operands[numTailTypes]
1203+
}
11991204
}
12001205

12011206
final public class AllocBoxInst : SingleValueInstruction, Allocation, DebugVariableInstruction {

0 commit comments

Comments
 (0)