[llvm] [WebAssembly] Print instructions with type checking errors (PR #111067)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 15:21:39 PDT 2024
https://github.com/aheejin created https://github.com/llvm/llvm-project/pull/111067
When there was a type checking error, we didn't run `InstPrinter`. This can be confusing because when there is an error in, say, block parameter type, `InstPrinter` doesn't run even if it has nothing to do with block parameter types, and all those updates to `ControlFlowStack` or `TryStack` do not happen:
https://github.com/llvm/llvm-project/blob/c20b90ab8557b38efe8e8e993d41d8c08b798267/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp#L135-L151
For example,
```wast
block (i32) -> () ;; Block input parameter error
end_block ;; Now this errors out as "End marker mismatch"
```
This is confusing because there is a `block` and the `end_block` is not a mismatch. Only that `block` has a type checking error, but that's not an end marker mismatch.
I think we can just print the instruction whether we had a type checking error or not, and this will be less confusing.
>From 3a0bf83f441d4427680f871032052448fb92961f Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Thu, 3 Oct 2024 22:08:45 +0000
Subject: [PATCH] [WebAssembly] Print instructions with type checking errors
When there was a type checking error, we didn't run `InstPrinter`. This
can be confusing because when there is an error in, say, block parameter
type, `InstPrinter` doesn't run even if it has nothing to do with block
parameter types, and all those updates to `ControlFlowStack` or
`TryStack` do not happen:
https://github.com/llvm/llvm-project/blob/c20b90ab8557b38efe8e8e993d41d8c08b798267/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp#L135-L151
For example,
```wast
block (i32) -> () ;; Block input parameter error
end_block ;; Now this errors out as "End marker mismatch"
```
This is confusing because there is a `block` and the `end_block` is not
a mismatch. Only that `block` has a type checking error, but that's not
an end marker mismatch.
I think we can just print the instruction whether we had a type checking
error or not, and this will be less confusing.
---
.../WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 4 ++--
llvm/test/MC/WebAssembly/annotations-typecheck.s | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/MC/WebAssembly/annotations-typecheck.s
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 5ea6c6bc0758b9..ee8686d1166a5b 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -1157,8 +1157,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
Inst.setOpcode(Opc64);
}
}
- if (!SkipTypeCheck && TC.typeCheck(IDLoc, Inst, Operands))
- return true;
+ if (!SkipTypeCheck)
+ TC.typeCheck(IDLoc, Inst, Operands);
Out.emitInstruction(Inst, getSTI());
if (CurrentState == EndFunction) {
onEndOfFunction(IDLoc);
diff --git a/llvm/test/MC/WebAssembly/annotations-typecheck.s b/llvm/test/MC/WebAssembly/annotations-typecheck.s
new file mode 100644
index 00000000000000..1fcdb9c0e35878
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/annotations-typecheck.s
@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
+
+# This tests annotations are handled correctly even if there is a type checking
+# error (which are unrelated to the block annotations).
+test_annotation:
+ .functype test_annotation () -> ()
+ block (i32) -> ()
+ drop
+# CHECK-NOT: # End marker mismatch!
+ end_block
+ end_function
More information about the llvm-commits
mailing list