Skip to content

LLVM -Og leads to invalid wasm (bad drop/fallthru) #25301

@poretga99

Description

@poretga99

We have issues when compiling our source code with some debug information. If we build in Release mode without additional debugging flags, everything is working just fine.

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.13 (2659582)

Error log

[wasm-validator error in function __original_main] unexpected false: non-final block elements returning a value must be dropped, on 
(block (result i32)
 (call $__pthread_self_internal)
 (i64.const 2)
 (i32.const 0)
)
(on index 0:
0x40d0c360310
), type: i64
[wasm-validator error in function __original_main] unexpected false: non-final block elements returning a value must be dropped, on 
(block (result i32)
 (call $__pthread_self_internal)
 (i64.const 2)
 (i32.const 0)
)
(on index 1:
0x40d0c360358
), type: i64
Fatal: error validating input
em++: error: '/emsdk/upstream/bin/wasm-opt --print-function-map main.wasm --mvp-features --enable-bulk-memory --enable-bulk-memory-opt --enable-call-indirect-overlong --enable-memory64 --enable-multivalue --enable-mutable-globals --enable-nontrapping-float-to-int --enable-reference-types --enable-sign-ext' failed (returned 1)

Simple reproducer
mkdir build && cd build && emcmake cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build .

// cat main.cpp
#include <emscripten/bind.h>

int main() {
    emscripten::val a;
    return a.isNull();
}
# cat CMakeLists.txt
project(reproducer LANGUAGES CXX)
 
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
option(ENABLE_WASM64 OFF)
 
add_executable(main main.cpp)
target_compile_options(main PRIVATE -Og -sMEMORY64=1)
target_link_options(main PRIVATE -Og --bind --emit-symbol-map -sMEMORY64=1)

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