Skip to content

Commit 8c0798f

Browse files
committed
[WebAssembly] Fix type index block type handling in type checker
The current code is ``` ExpectBlockType = false; TC.setLastSig(*Signature.get()); if (ExpectBlockType) NestingStack.back().Sig = *Signature.get(); ``` Because of the first line, the third line's `if (ExpectBlockType)` is always false and we don't get to update `NestingStack.back().Sig`. This results in not correctly erroring out when the types of remaining values on the stack do not match the block type if the block type is written in the form of a function type. We should set `ExpectBlockType` to false after the `if`. Reviewed By: sbc100 Differential Revision: https://reviews.llvm.org/D147837
1 parent d0027e0 commit 8c0798f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,10 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
637637
if (parseSignature(Signature.get()))
638638
return true;
639639
// Got signature as block type, don't need more
640-
ExpectBlockType = false;
641640
TC.setLastSig(*Signature.get());
642641
if (ExpectBlockType)
643642
NestingStack.back().Sig = *Signature.get();
643+
ExpectBlockType = false;
644644
auto &Ctx = getContext();
645645
// The "true" here will cause this to be a nameless symbol.
646646
MCSymbol *Sym = Ctx.createTempSymbol("typeindex", true);

llvm/test/MC/WebAssembly/type-checker-errors.s

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,20 @@ drop_empty_stack_while_popping:
221221
drop
222222
end_function
223223

224-
end_block_insufficient_values_on_stack:
225-
.functype end_block_insufficient_values_on_stack () -> ()
224+
end_block_insufficient_values_on_stack_1:
225+
.functype end_block_insufficient_values_on_stack_1 () -> ()
226226
block i32
227227
# CHECK: :[[@LINE+1]]:3: error: end: insufficient values on the type stack
228228
end_block
229229
end_function
230230

231+
end_block_insufficient_values_on_stack_2:
232+
.functype end_block_insufficient_values_on_stack_2 () -> ()
233+
block () -> (i32)
234+
# CHECK: :[[@LINE+1]]:3: error: end: insufficient values on the type stack
235+
end_block
236+
end_function
237+
231238
end_block_type_mismatch:
232239
.functype end_block_type_mismatch () -> ()
233240
block i32

0 commit comments

Comments
 (0)