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

"Unreachable" exception not thrown correctly on llvm-jit mode #2646

Closed
unicornt opened this issue Oct 16, 2023 · 5 comments
Closed

"Unreachable" exception not thrown correctly on llvm-jit mode #2646

unicornt opened this issue Oct 16, 2023 · 5 comments

Comments

@unicornt
Copy link

Test Case

code.zip

Result

fast-jit mode can throw unreachable exception correctly while llvm-jit will throw a segmentation fault

image

I also ran the same code on other wasm runtimes. They all can report unreachable exception correctly.

Versions and Environment

wamr version : 1.2.3

Operating system: Ubuntu 20.04

Architecture: x86_64

@wenyongh
Copy link
Contributor

wenyongh commented Nov 1, 2023

Hi, thanks for reporting the issue! I submitted patch set for PR #2697 to fix, could you please apply it, re-compile wamrc and test again?

@unicornt
Copy link
Author

unicornt commented Nov 1, 2023

Hi, thanks for reporting the issue! I submitted patch set for PR #2697 to fix, could you please apply it, re-compile wamrc and test again?

I tested it with llvm-jit mode and it really works. By the way, issue #2698 I just reported can also be fixed.
And I'm asking for the cause of this bug again. Could you tell me? Thanks a lot!

@wenyongh
Copy link
Contributor

wenyongh commented Nov 1, 2023

It is related to change in aot_emit_control.c, invalid llvm phi value may be used into the else basic block (use wamrc --format=llvmir-unopt -o test.ll test.wasm):

  %and53 = and i32 %or, %and52
  br label %if0_else

if0_else:                                         ; preds = %func_begin
  %else0_phi0 = phi i32 [ %"local0#", %func_begin ]
  %else0_phi1 = phi i32 [ %add, %func_begin ]
  call void @"aot_func#41"(ptr %exec_env, i32 %if0_phi0, i32 %if0_phi1)   => should use %else0_phi0 and %else0_phi1 but not %if0_phi0 and %if0_phi1
  br label %if0_end

@unicornt
Copy link
Author

unicornt commented Nov 1, 2023

What is llvm_entry_block variable meaning in the code? Is it used to distinguish block like if0_else and other type of block?

@wenyongh
Copy link
Contributor

wenyongh commented Nov 2, 2023

llvm_entry_block is the basic block for the wasm opcode BLOCK, LOOP and the first branch of opcode IF, if_else is the basic block of the else branch of opcode IF. Somewhat like:

BLOCK/LOOP                        block0_begin/loop0_begin:   (llvm_entry_block)
  ...                      =>        ...
END                               block0_end/loop0_end:       (llvm_end_block)
IF                        if0_begin:   (llvm_entry_block)
  ...                        ...
ELSE                =>    if0_else:    (llvm_else_block)
  ...                         ...
END                       if0_end:     (llvm_end_block)

@unicornt unicornt closed this as completed Nov 2, 2023
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

2 participants