Skip to content

Miscompiled program with --target=wasm32 #115186

@zack-alex

Description

@zack-alex

UPD: here is a slightly improved example.

Here is a simple C++ program:

struct BigClass {
  char data[400000];
};

struct Class {
  char big_data[400000];
  int value{33};
};

Class glob{};

extern "C" int _start() {
  glob.value = 42;
  BigClass s1{};
  return glob.value;
}

When compiled and ran with wasmer runtime, it outputs "0" instead of expected "42":

+ clang-17 --version
clang version 17.0.6
Target: aarch64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /nix/store/glzjy0xq2xhmwg6pc8c1pdk7gln127wj-clang-17.0.6/bin
+ clang-17 -std=c++20 -pedantic -Wall -Wno-unused-variable --target=wasm32 --no-standard-libraries -mbulk-memory -O0 -o main.wasm main.cpp
+ wasmer main.wasm
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend:WebAssemblyquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions