emscripten-core / emscripten-core/emscripten

Argument replaced with default in function call when switching from emscripten 4.0.1 to latter versions

Open
#24,325 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

When switching from emcc 4.0.1 to 4.0.2, the simple following program no longer works using c++23.
However, it works as expected using c++20, and c++17 .
(The same issue arise from emcc 4.0.2 to 4.0.8)

It seems that part of the default argument in the function "compute_area" signature is kept instead of being replaced in the main.

In the following program, the member "m1" of the argument "val" is replaced with its default value in the function call.
The problem disappear when replacing MyStruct with a scalar.

```cpp
// main.cpp
#include "A.hpp"
#include
#include

auto main() -> int {
MyStruct in_val{.m0 = 2.0, .m1 = 1};
std::cout << "main : in_val.m0 : " << in_val.m0 << "\n";
std::cout << "main : in_val.m1 : " << in_val.m1 << " \n\n";
double val = compute_area(1.0, in_val);
std::cout << "result = " << val << std::endl;
assert(val == 2.0);
return 0;
}
```

```cpp
// A.hpp
#pragma once
#include
struct MyStruct {
double m0{-9999.0};
int m1{-12345};
};

constexpr MyStruct default_val;

auto compute_area(double l, const MyStruct &val = default_val) -> double {
std::cout << "compute_area : val.m0 : " << val.m0 << "\n";
std::cout << "compute_area : val.m1 : " << val.m1 << " \n";
if (val.m1 != -12345) {
return val.m0 * l;
}
return -9999;
}
```

Output :
```
main : in_val.m0 : 2
main : in_val.m1 : 1

compute_area : val.m0 : 2
compute_area : val.m1 : -12345
result = -9999

Aborted(Assertion failed: val == 2.0, at: main.cpp,12,main)
```

**Version of emscripten/emsdk:**
```
emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.2 (7591f1c5ea0adf6f4293cfba2995ee9700aa0d93)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 9534d27e3321a3b9e6e79fe6328445575bf26b7b)
Target: wasm32-unknown-emscripten
Thread model: posix
```

**Full link command and output with `-v` appended:**
emcc main.cpp -std=c++23 -v -o main.html
/home/User0/emsdk/upstream/bin/clang -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/home/User0/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -std=c++23 -v -c main.cpp -o /tmp/emscripten_temp_srqc64ku/main_0.o
clang version 21.0.0git (https:/github.com/llvm/llvm-project 9534d27e3321a3b9e6e79fe6328445575bf26b7b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/User0/emsdk/upstream/bin
(in-process)
"/home/User0/emsdk/upstream/bin/clang-21" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/home/User0/embug -v -fcoverage-compilation-dir=/home/User0/embug -resource-dir /home/User0/emsdk/upstream/lib/clang/21 -D EMSCRIPTEN -isysroot /home/User0/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /home/User0/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /home/User0/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /home/User0/emsdk/upstream/lib/clang/21/include -internal-isystem /home/User0/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /home/User0/emsdk/upstream/emscripten/cache/sysroot/include -std=c++23 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fignore-exceptions -fexceptions -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/emscripten_temp_srqc64ku/main_0.o -x c++ main.cpp
clang -cc1 version 21.0.0git based upon LLVM 21.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/User0/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/home/User0/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
/home/User0/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
/home/User0/emsdk/upstream/emscripten/cache/sysroot/include/compat
/home/User0/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1
/home/User0/emsdk/upstream/lib/clang/21/include
/home/User0/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
/home/User0/emsdk/upstream/bin/clang --version
/home/User0/emsdk/upstream/bin/wasm-ld -o main.wasm /tmp/emscripten_temp_srqc64ku/main_0.o -L/home/User0/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -L/home/User0/emsdk/upstream/emscripten/src/lib -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc-debug -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmp2enyv1ahlibemscripten_js_symbols.so --strip-debug --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__wasm_call_ctors --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --stack-first --table-base=1
/home/User0/emsdk/upstream/bin/llvm-objcopy main.wasm main.wasm --remove-section=.debug* --remove-section=producers --remove-section=name
/home/User0/emsdk/node/20.18.0_64bit/bin/node /home/User0/emsdk/upstream/emscripten/src/compiler.mjs /tmp/tmpn5435n35.json
/home/User0/emsdk/node/20.18.0_64bit/bin/node /home/User0/emsdk/upstream/emscripten/tools/preprocessor.mjs /tmp/emscripten_temp_srqc64ku/settings.js shell.html

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.