For inline WebAssembly, passing a numeric operand to global.get is unsupported. This causes encodeInstruction to reach an llvm_unreachable block, leading to undefined behaviors. This patch fixes the issue for this invalid instruction encoding, making it report an error by adding an MCContext field in class WebAssemblyMCCodeEmitter.
Details
Diff Detail
Event Timeline
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp | ||
---|---|---|
129 | Is this error specific to inline assembly? Looking at global_set_expected_expression_operand in llvm/test/MC/WebAssembly/type-checker-errors.s I see a different error.. so I guess maybe it fails before it gets here in the case to non-inline assembly? I wonder if we shouldn't just allow this.. even though its kind odd to want to do it.. |
Thanks. Wouldn't it be better to add the test in the same patch as the change its testing?
I followed this guide. I thought it might be better style.
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp | ||
---|---|---|
129 | Noted, I tried llvm-mc on the assembly generated from my testcase, and it is also giving a different error. I am not sure why it is behaving differently if we split up the 2 stages. |
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp | ||
---|---|---|
129 |
In other architectures there are use cases for hardcoding register names as well as using symbols and letting the regalloc choose. Some of them are for constraints in particular instructions (e.g. instruction that always leaves 2 outputs in rax/rcx), or for ABIs that specify register use. Wasm doesn't really have either one of those. So I think I'd be fine having this limitation until someone proposes a use case for it. |
Added the testcase to check for an appropriate error message when an unsupported inline WebAssembly is provided.
llvm/test/CodeGen/WebAssembly/inline-asm-failure.ll | ||
---|---|---|
3 | NIT: Can you add a space between the semi-colon and RUN:? Same thing for the ;CHECK: line below. | |
4 | It might be useful to rename this to "rust-issue-111471.c". | |
30 | Can you remove !0 and !1, as well as !llvm.module.flags and !llvm.ident? These metadata are irrelevant to the test case. Rename !2 to !0. |
Is this error specific to inline assembly?
Looking at global_set_expected_expression_operand in llvm/test/MC/WebAssembly/type-checker-errors.s I see a different error.. so I guess maybe it fails before it gets here in the case to non-inline assembly?
I wonder if we shouldn't just allow this.. even though its kind odd to want to do it..