diff --git a/src/engine/CodeValidator.v3 b/src/engine/CodeValidator.v3 index 8069c7a0a..54ae377e4 100644 --- a/src/engine/CodeValidator.v3 +++ b/src/engine/CodeValidator.v3 @@ -372,7 +372,7 @@ class CodeValidator(extensions: Extension.set, limits: Limits, module: Module, e ctl_stack.pop(); if (validatingInitExpr && ctl_stack.empty()) { // END finished the init expr codeptr.reset(codeptr.data, codeptr.pos, codeptr.pos); - } else { + } else if (!ctl_stack.empty()) { ctl_top = ctl_stack.peek(); } } diff --git a/test/unittest/CodeValidatorTest.v3 b/test/unittest/CodeValidatorTest.v3 index be89624a7..34c97ce07 100644 --- a/test/unittest/CodeValidatorTest.v3 +++ b/test/unittest/CodeValidatorTest.v3 @@ -100,6 +100,7 @@ def X_ = void( T("simd.binop2", test_simd_binop2), T("simd.binop3", test_simd_binop3), T("memarg_stolen_is64", test_memarg_stolen_is64), + T("end_empty_ctl", test_end_empty_ctl), () ); @@ -2418,3 +2419,8 @@ def test_memarg_stolen_is64(t: CodeValidatorTester) { if ((copy[pos] & BpConstants.MEMARG_STOLEN_IS64) == 0) return t.t.fail1("expected 0x%x flag to be set for memory64", BpConstants.MEMARG_STOLEN_IS64); } } + +def test_end_empty_ctl(t: CodeValidatorTester) { + t.sig(SigCache.v_v); + t.invalid(WasmError.OOB_LABEL, [u8.!(Opcode.END.code)], 2); +}