Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect code emitted involving unreachable code. #25

Closed
ghost opened this issue Jan 24, 2016 · 2 comments
Closed

Incorrect code emitted involving unreachable code. #25

ghost opened this issue Jan 24, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 24, 2016

The following code emits a single unreachable operator which does not appear correct. When $i1 is zero this function would return 1.

(module
 (func (param $i1 i32) (result i32)
   (if_else (get_local $i1)
     (block (unreachable))
     (i32.const 1))))
0000004: 02                                         ; WASM_SECTION_FUNCTIONS
0000005: 01                                         ; num functions
; function 0
0000006: 00                                         ; func flags
0000007: 0000                                       ; func signature index
0000009: 0000                                       ; func body size
000000b: 01                                         ; OPCODE_BLOCK
000000c: 01                                         ; num expressions
000000d: 15                                         ; OPCODE_UNREACHABLE
0000009: 0300                                       ; FIXUP func body size
000000e: 06                                         ; WASM_SECTION_END

Some discussion at WebAssembly/design#527

@binji
Copy link
Member

binji commented Jan 24, 2016

Just tested this and got the following output:

0000000: 01                                         ; WASM_SECTION_SIGNATURES
0000001: 01                                         ; num signatures
; signature 0
0000002: 01                                         ; num params
0000003: 01                                         ; result_type
0000004: 01                                         ; param type
0000005: 02                                         ; WASM_SECTION_FUNCTIONS
0000006: 01                                         ; num functions
; function 0
0000007: 00                                         ; func flags
0000008: 0000                                       ; func signature index
000000a: 0000                                       ; func body size
000000c: 04                                         ; OPCODE_IF_THEN
000000d: 0e                                         ; OPCODE_GET_LOCAL
000000e: 00                                         ; remapped local index
000000f: 01                                         ; OPCODE_BLOCK
0000010: 01                                         ; num expressions
0000011: 15                                         ; OPCODE_UNREACHABLE
0000012: 09                                         ; OPCODE_I8_CONST
0000013: 01                                         ; u8 literal
000000a: 0800                                       ; FIXUP func body size
0000014: 06                                         ; WASM_SECTION_END

Looks right to me.

@ghost
Copy link
Author

ghost commented Jan 24, 2016

Sorry for the noise, my mix-up.

@ghost ghost closed this as completed Jan 24, 2016
wenyongh pushed a commit to wenyongh/wabt that referenced this issue Jan 30, 2024
* Render indirect calls directly in no-sandbox mode.

* Fix for lint error.

* Adjusted tests.

* Another try of fixing the tests.

* Fix whitespace in tests.

* Use needs_initial_comma logic to clarify things a bit.

* Implemented review suggestion.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant