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

Avoid the -Os option when generating WebAssembly #2378

Merged
merged 1 commit into from
Sep 21, 2023
Merged

Conversation

lukaszcz
Copy link
Collaborator

@lukaszcz lukaszcz commented Sep 21, 2023

With -Os ill-typed code is generated for the following:

module wasmcrash.juvix;

import Stdlib.Prelude open;

{-# inline: false #-}
I {A} (x : A) : A := x;

{-# inline: false #-}
I' {A} (x : A) : A := x;

main : Nat := I' (I I 1);

Running the generated WASM file with wasmer or wasmtime gives an error:

Validation error: type mismatch: expected i32 but nothing on stack (at offset 740)

The issue occurs with clang version 16.0.5 but not 16.0.0. The issue does not occur with any other optimization option (-O1, -O2, -O3). There is no issue with -Os used with the native target.

This is thus likely a bug in a specific version of LLVM. It could be theoretically some very subtle non-conformance to the C standard in our generated code, but this seems less likely. Creating a minimum C file exposing the bug would be very time-consuming, so I propose to just avoid using the -Os option for now.

@lukaszcz lukaszcz added this to the 0.5.2 milestone Sep 21, 2023
@lukaszcz lukaszcz self-assigned this Sep 21, 2023
@paulcadman paulcadman merged commit 6c08cbb into main Sep 21, 2023
4 checks passed
@paulcadman paulcadman deleted the fix-wasm-opt branch September 21, 2023 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants