Open
Description
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
- Create a C file named
repro.c
with the following content:#pragma clang fp exceptions(strict) float a; void b() { 0 || a; }
- Compile the file for the wasm32 target. The compiler will crash.
clang -S -emit-llvm -c --target=wasm32-wasi repro.c
repro.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)"}
- Run
llc
on the generatedrepro.ll
file. It will crash with a segmentation fault.$ 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