Skip to content

-O0 + js_library + int to boolean = errorΒ #23479

@mighty1231

Description

@mighty1231

Version of emscripten/emsdk:

docker image with emscripten/emsdk:3.1.74

file test.js

addToLibrary({
  my_js_1: function() {
    return 1;
  },
  my_js_2: function() {
    return 2;
  },
});

file test.cc

#include <emscripten/console.h>

extern "C" {
  extern bool my_js_1(void);
  extern bool my_js_2(void);
}

int main() {
  if (my_js_1()) {
    emscripten_out("my_js_1 is truthy");
  } else {
    emscripten_out("my_js_1 is falsy");
  }

  if (my_js_2()) {
    emscripten_out("my_js_2 is truthy");
  } else {
    emscripten_out("my_js_2 is falsy");
  }

  return 0;
}

command

$ em++ --js-library test.js -o build/O0.js -O0 test.cc
$ em++ --js-library test.js -o build/O1.js -O1 test.cc

What I expected

$ node build/O0.js
my_js_1 is truthy
my_js_2 is truthy

$ node build/O1.js
my_js_1 is truthy
my_js_2 is truthy

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 option

emscripten_current_thread_is_wasm_worker: () => {

  emscripten_current_thread_is_wasm_worker: () => {
#if WASM_WORKERS
    return ENVIRONMENT_IS_WASM_WORKER; // <-- returns number 😭
#else
    // implicit return 0;
#endif
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions