-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
-O0 + js_library + int to boolean = error #23479
Comments
I think this is undefined behaviour in C/C++ due the valid values for The C/C++ compiler (if it chose too) could just compare with You can reproduce in native clang too without emscripten:
|
Are you seeing an issue with |
In C or C++, if you call a function in your code with a prototype like |
Sure, I'm playing tricks with the linker in my example above and that is another kind of undefined behaviour, but the undefined behaviour that is the root of the problem at hand is that bool can only hold 0 or 1. |
From the JS bridge POV the Its true that returning a boolean value (JS will convert the boolean to an i32 before it returns to wasm) would help prevent this kind of error, returning a value of 1 or 0 also works just fine. |
you may create two wasm workers, then the value is defined with Module['$ww']. It's value be given with the wasm worker id that increases from 1. 1, 2, 3, ... |
Ah, yes that does indeed look like a bug. We should probably changed: Does that mean that |
This function was ENVIRONMENT_IS_WASM_WORKER which was being initialized to Module['$ww'], i.e. the worker id. Because emscripten_current_thread_is_wasm_worker, is defined to return the `bool` type its only valid values are 0 and 1. Returning values larger than 1 will result in undefined behaviour. Fixes: emscripten-core#23479
This function was ENVIRONMENT_IS_WASM_WORKER which was being initialized to Module['$ww'], i.e. the worker id. Because emscripten_current_thread_is_wasm_worker, is defined to return the `bool` type its only valid values are 0 and 1. Returning values larger than 1 will result in undefined behaviour. Fixes: emscripten-core#23479
This function was ENVIRONMENT_IS_WASM_WORKER which was being initialized to Module['$ww'], i.e. the worker id. Because emscripten_current_thread_is_wasm_worker, is defined to return the `bool` type its only valid values are 0 and 1. Returning values larger than 1 will result in undefined behaviour. Fixes: emscripten-core#23479
Actually, 1, 3, 5, 7, ... gives truthy and 2, 4, 6, 8, ... gives falsy. It seems it depends on the last bit of int, with whatever settings - clang or emscripten+js.
I have found the issue with my personal project, using |
Version of emscripten/emsdk:
docker image with emscripten/emsdk:3.1.74
file
test.js
file
test.cc
command
What I expected
But the result for actual run is
$ node build/O0.js my_js_1 is truthy my_js_2 is falsy // <--- 😲 $ node build/O1.js my_js_1 is truthy my_js_2 is truthy
-O2
,-O3
work same as-O1
Severity: flakiness on wasm worker +
-O0
optionemscripten/src/library_wasm_worker.js
Line 239 in 1092ec3
The text was updated successfully, but these errors were encountered: