Issue 170678
Summary clang-21 --target=wasm32 -Og miscompilation
Labels new issue
Assignees
Reporter TerrorJack
    ```c
void f(void) {
    int i = -1;
    do { i++; } while (i != 0);
}
```

when the above example is compiled with `clang-21 --target=wasm32 -Og`, the resulting object fails validation:

```
error: func 0 failed to validate

Caused by:
    0: type mismatch: values remaining on stack at end of block (at offset 0x43)
```

the disassembled wat content points out that `f` is mis-compiled, missing a `drop` instruction:

```wat
(module
  (type (;0;) (func))
  (import "env" "__linear_memory" (memory (;0;) 0))
  (func (;0;) (type 0)
    i32.const 0
  )
  (@custom "linking" (after code) "\02\08\86\80\80\80\00\01\00\04\00\01f")
  (@producers
 (processed-by "Ubuntu clang" "21.1.7 (++20251127113503+9ed1927442a4-1~exp1~20251127113518.64)")
  )
  (@custom "target_features" (after code) "\08+\0bbulk-memory+\0fbulk-memory-opt+\16call-indirect-overlong+\0amultivalue+\0fmutable-globals+\13nontrapping-fptoint+\0freference-types+\08sign-ext")
)
```

this issue doesn't reproduce on `clang-22`, so it might be the case that it's a duplicate issue that's been fixed earlier. still reporting this since 21 is the active release at the moment.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to