bytecodealliance / bytecodealliance/wit-bindgen

wit-bindgen C++ passes the wrong enum value in option<list<variant>>

Aperta
#1,683 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
1.5k
Fork
286
Merge medio
6h 32m
PR unite (30g)
19

Descrizione

Summary:wit-bindgen-cpp encodes wrong enum discriminant for enum payload inside variant inside option, producing incorrect values.

Bug report: C++ consumers generated by wit-bindgen-cpp lift/lower the enum case inside an option-wrapped variant with a wrong discriminant (e3 becomes e1), yielding wrong output values regardless of provider language.

## Environment

| component | version |
|---|---|
| OS | macOS 15.7 (Darwin 24.6.0), x86_64 |
| jco | 1.16.1 (source checkout, tag jco-v1.16.1) |
| Node.js | v22.22.2 |
| wac | wac-cli 0.8.1 |
| wasi-sdk | 27.0 (wasm32-wasip2-clang/clang++) |

## Steps to reproduce

The full chain is: compile the guest sources into a provider component and a consumer component, compose them with `wac`, then run the composed component. Prebuilt copies of every artifact are included (`components/provider.wasm`, `components/consumer.wasm`, `composed.wasm`), so you can also skip straight to step 5.

**Github repo:https://github.com/xiaozzzZZzzz240/G028-Cplusplus-bindings-return-e1-instead-of-e3-for-enum-payload-in-option**

1. Clone this repository:

```console
git clone
cd
```

2. Compile the provider component from the **C** sources in `src/provider-C/` (toolchain versions in the table above; the WIT package is in `wit/`):

```console
wasm32-wasip2-clang -o components/provider.wasm -mexec-model=reactor src/provider-C/world9-wi7n9u47_generated.c src/provider-C/world9_wi7n9u47.c src/provider-C/world9_wi7n9u47_component_type.o
```

3. Compile the consumer component from the **C++** sources in `src/consumer-Cpp/`:

```console
wasm32-wasip2-clang++ -std=c++23 -fno-exceptions -o components/consumer.wasm -mexec-model=reactor src/consumer-Cpp/world9b-mul38v8w_generated.cpp src/consumer-Cpp/world9b_mul38v8w.cpp src/consumer-Cpp/world9b_mul38v8w_component_type.o
```

4. Compose the two components into one runnable component with wac 0.8.1:

```console
wac plug components/consumer.wasm --plug components/provider.wasm -o composed.wasm
```

5. Run the composed component with jco:

```console
npm install -g @bytecodealliance/jco@1.16.1
jco run composed.wasm
```

## Expected result

The composed component should print exactly the following, then exit 0:

```text
"resinst0"
"resinst1"
"resinst2"
"resinst0"
resource("temres36")
"c2"
true
"c0"
resource("temres39")
(resource("temres40"), "bar")
"c2"
true
"temres39"
"temres44"
some([c1(enum(e3))])
resource("temres6")
"c0"
true
7
true
```

## Actual result

Under **jco** the same `composed.wasm` exits with rc=0. stdout:

```text
"resinst0"
"resinst1"
"resinst2"
"resinst0"
resource("temres36")
"c2"
true
"c0"
resource("temres39")
(resource("temres40"), "bar")
"c2"
true
"temres39"
"temres44"
some([c1(enum(e1))])
resource("temres6")
"c0"
true
7
true
```

stderr:

```text
(empty)
```

wasmtime on the exact same file: rc=0

```text
"resinst0"
"resinst1"
"resinst2"
"resinst0"
resource("temres36")
"c2"
true
"c0"
resource("temres39")
(resource("temres40"), "bar")
"c2"
true
"temres39"
"temres44"
some([c1(enum(e1))])
resource("temres6")
"c0"
true
7
true
```

Both executing result in jco and wasmtime are not as expected.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia con i sorgenti C++ generati del consumer in src/consumer-Cpp/ e il pacchetto WIT in wit/, quindi riproduci i comandi di build e composizione del provider e del consumer dal report. Confronta l’output annidato di option/variant del componente composto con il risultato atteso: il payload dell’enum deve rimanere e3 sia con jco sia con wasmtime, invece di diventare e1.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, wasm
Ambito
compilers, devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
52/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.