@@ -900,8 +900,8 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
900
900
///
901
901
/// - Parameter typeHint: A type expected to be popped. Only used for diagnostic purpose.
902
902
/// - Returns: `true` if check succeed. `false` if the pop operation is going to be performed in unreachable code path.
903
- private func checkBeforePop( typeHint: ValueType ? , controlFrame: ControlStack . ControlFrame ) throws -> Bool {
904
- if _slowPath ( valueStack. height <= controlFrame. stackHeight) {
903
+ private func checkBeforePop( typeHint: ValueType ? , depth : Int = 0 , controlFrame: ControlStack . ControlFrame ) throws -> Bool {
904
+ if _slowPath ( valueStack. height - depth <= controlFrame. stackHeight) {
905
905
if controlFrame. reachable {
906
906
let message : String
907
907
if let typeHint {
@@ -916,9 +916,9 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
916
916
}
917
917
return true
918
918
}
919
- private func checkBeforePop( typeHint: ValueType ? ) throws -> Bool {
919
+ private func checkBeforePop( typeHint: ValueType ? , depth : Int = 0 ) throws -> Bool {
920
920
let controlFrame = try controlStack. currentFrame ( )
921
- return try self . checkBeforePop ( typeHint: typeHint, controlFrame: controlFrame)
921
+ return try self . checkBeforePop ( typeHint: typeHint, depth : depth , controlFrame: controlFrame)
922
922
}
923
923
private mutating func ensureOnVReg( _ source: ValueSource ) -> VReg {
924
924
// TODO: Copy to stack if source is on preg
@@ -994,7 +994,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
994
994
995
995
private func checkStackTop( _ valueTypes: [ ValueType ] ) throws {
996
996
for (stackDepth, type) in valueTypes. reversed ( ) . enumerated ( ) {
997
- guard try checkBeforePop ( typeHint: type) else { return }
997
+ guard try checkBeforePop ( typeHint: type, depth : stackDepth ) else { return }
998
998
let actual = valueStack. peekType ( depth: stackDepth)
999
999
switch actual {
1000
1000
case . some( let actualType) :
0 commit comments