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

Different behavior between native and WASM #16154

Open
MCMocoder opened this issue Jan 30, 2022 · 1 comment
Open

Different behavior between native and WASM #16154

MCMocoder opened this issue Jan 30, 2022 · 1 comment

Comments

@MCMocoder
Copy link

Version:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.2-git
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 1a929525e86a20d0b3455a400d0dbed40b325a13)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/opt/emscripten/libexec/llvm/bin

Platform: MacOS Big Sur 11.0.1

Native Compiler Version:

clang version 13.0.0
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /usr/local/bin

When I compile the following code with my compiler,I get different results.

i=0
j=0
DO
IF i<j THEN 
i=i+1
END IF
LOOP UNTIL i>j
END

If I use native executable as the compiler , it can be successfully compiled.
If I use WASM to compile , it will throw errors.
I used this command to compile:

em++ ../src/compile.cc ../src/lex/lexer.cc ../src/parse/parse.cc ../src/bm3.cc -O3 --no-entry -I../include -o -WASM=0 -o compiler.js -fwasm-exceptions -s EXPORTED_FUNCTIONS=_main

The repo is here:github.com/MCMocoder/BM3-Mathbasic

@kripken
Copy link
Member

kripken commented Jan 31, 2022

it will throw errors.

Internal errors in your program? Or wasm ones - if so, which?

Overall the first thing I would try for a situation like this is the sanitizers. The program may be affected by undefined behavior.

https://emscripten.org/docs/debugging/Sanitizers.html

If that doesn't help, debugging the program to where it diverges from a native build is the next step.

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