WebAssembly / wabt

The WebAssembly Binary Toolkit
Apache License 2.0
6.73k stars 687 forks source link

Module fails to compile without a proper error message #2453

Open Janrupf opened 4 weeks ago

Janrupf commented 4 weeks ago

The following module fails to compile:

(module
    (func (param externref) (result i32)
        (ref.is_null)
    )
)

Running wat2wasm on this leads to an exit code if 1, but no proper error message. Debugging with GDB shows that the typechecker throws an error here: https://github.com/WebAssembly/wabt/blob/1edeaf2948b4afd711e50ba2007ee44503cd80fe/src/type-checker.cc#L814

The problem is, that even though the result is now set to an error, no error message is printed, as the PeekType function doesn't do so. This code is obviously not valid WASM (its missing a local.get 0 in front of ref.is_null), but I still would expect a proper error message.

Example with `i32.add` ```wasm (module (func (param i32) (result i32) (i32.add) ) ) ``` Gives a proper error message: ``` simple.wat:3:10: error: type mismatch in i32.add, expected [i32, i32] but got [] (i32.add) ^^^^^^^ ```

(NOTE: After looking at the at the following the PeekType call, I assume the condition should have been type == Type::Any || !type.IsRef())

AG-597 commented 3 weeks ago

I have this same issue, it simply runs, then returns no output, no error message.

sbc100 commented 3 weeks ago

I think think assumption looks correct. Would you be able to send a PR to fix that line?

Janrupf commented 3 weeks ago

Currently on vacation, but sadly the fix isn't as simple as I thought (it can cause miscompilation in other cases if applied the way I suggested). I'll take a look when I'm home again