<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143147>143147</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[WebAssembly] Crash when compiling wasm32 with strict floating point exception behaviour
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zebreus
</td>
</tr>
</table>
<pre>
When compiling C code for `wasm32`, a compiler crash occurs if the code has strict floating-point exceptions enabled.
The crash happens in the `WebAssembly Instruction Selection` pass. The issue can be reproduced directly with `llc` on the generated LLVM IR, confirming it's a backend bug and not specific to the Clang frontend. The crash does not occur when compiling for a native target like x86_64.
### Environment
* **LLVM Version**: `Ubuntu clang version 20.1.2 (0ubuntu1)`
* **Target**: `wasm32-unknown-wasi`
* **Host OS**: Ubuntu (x86_64)
### Steps to Reproduce
1. Create a C file named `repro.c` with the following content:
```c
#pragma clang fp exceptions(strict)
float a;
void b() {
0 || a;
}
```
2. Compile the file for the wasm32 target. The compiler will crash.
```sh
clang -S -emit-llvm -c --target=wasm32-wasi repro.c
```
<details>
<summary>repro.ll</summary>
```ll
; ModuleID = 'repro.c'
source_filename = "repro.c"
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20"
target triple = "wasm32-unknown-wasi"
@a = hidden global float 0.000000e+00, align 4
; Function Attrs: noinline nounwind optnone strictfp
define hidden void @b() #0 {
%1 = load float, ptr @a, align 4
%2 = call i1 @llvm.experimental.constrained.fcmp.f32(float %1, float 0.000000e+00, metadata !"une", metadata !"fpexcept.strict") #2
%3 = zext i1 %2 to i32
ret void
}
; Function Attrs: nocallback nofree nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
declare i1 @llvm.experimental.constrained.fcmp.f32(float, float, metadata, metadata) #1
attributes #0 = { noinline nounwind optnone strictfp "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+multivalue,+mutable-globals,+nontrapping-fptoint,+reference-types,+sign-ext" }
attributes #1 = { nocallback nofree nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite) }
attributes #2 = { strictfp }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"Ubuntu clang version 20.1.2 (0ubuntu1)"}
```
</details>
3. Run `llc` on the generated `repro.ll` file. It will crash with a segmentation fault.
```sh
$ llc repro.ll
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc repro.ll
1. Running pass 'Function Pass Manager' on module 'repro.ll'.
2. Running pass 'WebAssembly Instruction Selection' on function '@b'
#0 0x000079fd5d41dd1f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x101dd1f)
#1 0x000079fd5d41ba29 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x101ba29)
#2 0x000079fd5d41e430 (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x101e430)
#3 0x000079fd5bc45810 (/lib/x86_64-linux-gnu/libc.so.6+0x45810)
...
```
### Expected Behavior
The code should compile or there should be a real error message
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0WF9v2zgS_zTMy0CCRCm28-AHx2mwBXZxRbO3-1hQ1EjmlSIF_omTfvrDkLIdp929u727wqllcjj8zW_-cCjhvRoN4pbd3rPbhxsRw8G67TfsHEZ_09n-dfv7AQ1IO81KKzPCHqTtEQbrgK2qo_BTw9mqYnwPYhFDB9IJfwArZXQe1ADhgHndQXjwwSkZYNBWBGXGYrbKBMAXiXNQ1nhAIzqNfcmqHat2v9LapO8g5hmNB2WSQraqfsdu5z1OnX6Fj8YHFyWpgCfUmJ7YqoJ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