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

Ignorance of exception "integer divide by zero" in llvm-jit mode #2650

Closed
unicornt opened this issue Oct 17, 2023 · 4 comments
Closed

Ignorance of exception "integer divide by zero" in llvm-jit mode #2650

unicornt opened this issue Oct 17, 2023 · 4 comments

Comments

@unicornt
Copy link

Test Case

report7.zip

Result

If I run this code on llvm-jit mode, it will exit normally. But in fast-jit mode or interp mode, it will threw an integer divide by zero exception.
By the way, I tried the same code with other runtimes. They all throw integer divide by zero exception.

image

Extra Information

If I change i32.div_s (in line 79) into i32.add, all runtimes will exit normally.
Maybe it is a problem of i32.rotl instruction because its result is different between llvm-jit mode and fast-jit mode.

image

Versions and Environment

wamr version : 1.2.3

Operating system: Ubuntu 20.04

Architecture: x86_64

@lum1n0us
Copy link
Collaborator

Because of the drop at L80, llvm-jit optimizer treats above Wasm instrctions as a kind of dead code and removes them in generation.

@unicornt
Copy link
Author

Thank you for the explanation! Please let me know when and how you fix it.

@wenyongh
Copy link
Contributor

wenyongh commented Nov 1, 2023

Hi, I checked the issue again, it seems that it is caused by the i32.rotl opcode but not the i32.div_s opcode. It runs OK after applying patch #2697. For opcode i32.div_s, the AOT compiler adds checks and generates call IR to call aot_set_exception_with_id function, normally it should not be eliminated as dead code.

For example, for the wasm function below:

(func (export "test") (param i32)
   (i32.const 1234)
   (local.get 0)
   i32.div_s
   drop
)

The drop is added after i32.div_s, but after running iwasm -f test test.aot 0, the exception integer divide by zero was thrown.

@unicornt
Copy link
Author

unicornt commented Nov 1, 2023

Hi, I checked the issue again, it seems that it is caused by the i32.rotl opcode but not the i32.div_s opcode. It runs OK after applying patch #2697. For opcode i32.div_s, the AOT compiler adds checks and generates call IR to call aot_set_exception_with_id function, normally it should not be eliminated as dead code.

For example, for the wasm function below:

(func (export "test") (param i32)
   (i32.const 1234)
   (local.get 0)
   i32.div_s
   drop
)

The drop is added after i32.div_s, but after running iwasm -f test test.aot 0, the exception integer divide by zero was thrown.

Yes, I tried it with patch #2697 and it can throw exception correctly. Thank you for the explanation about i32.div_s opcode!

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

3 participants