[PATCH] D147837: [WebAssembly] Fix type index block type handling in type checker

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 7 21:54:24 PDT 2023


aheejin created this revision.
aheejin added reviewers: sbc100, aardappel.
Herald added subscribers: pmatos, asb, wingo, ecnelises, arphaman, sunfish, hiraditya, jgravelle-google, dschuff.
Herald added a project: All.
aheejin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147837

Files:
  llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
  llvm/test/MC/WebAssembly/type-checker-errors.s


Index: llvm/test/MC/WebAssembly/type-checker-errors.s
===================================================================
--- llvm/test/MC/WebAssembly/type-checker-errors.s
+++ llvm/test/MC/WebAssembly/type-checker-errors.s
@@ -221,13 +221,20 @@
   drop
   end_function
 
-end_block_insufficient_values_on_stack:
-  .functype end_block_insufficient_values_on_stack () -> ()
+end_block_insufficient_values_on_stack_1:
+  .functype end_block_insufficient_values_on_stack_1 () -> ()
   block i32
 # CHECK: :[[@LINE+1]]:3: error: end: insufficient values on the type stack
   end_block
   end_function
 
+end_block_insufficient_values_on_stack_2:
+  .functype end_block_insufficient_values_on_stack_2 () -> ()
+  block () -> (i32)
+# CHECK: :[[@LINE+1]]:3: error: end: insufficient values on the type stack
+  end_block
+  end_function
+
 end_block_type_mismatch:
   .functype end_block_type_mismatch () -> ()
   block i32
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -637,10 +637,10 @@
       if (parseSignature(Signature.get()))
         return true;
       // Got signature as block type, don't need more
-      ExpectBlockType = false;
       TC.setLastSig(*Signature.get());
       if (ExpectBlockType)
         NestingStack.back().Sig = *Signature.get();
+      ExpectBlockType = false;
       auto &Ctx = getContext();
       // The "true" here will cause this to be a nameless symbol.
       MCSymbol *Sym = Ctx.createTempSymbol("typeindex", true);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147837.511848.patch
Type: text/x-patch
Size: 1683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230408/e429f3a6/attachment.bin>


More information about the llvm-commits mailing list