zig
zig copied to clipboard
WASM LLVM crash on std.math.atan2(0, 1)
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
With the following file test.zig
const std = @import("std");
pub export fn some_function() f32 {
return std.math.atan2(0, @as(f32, 1.0));
}
Compiled with
zig build-exe -target wasm32-freestanding test.zig -OReleaseSmall
I see a variant of the error
LLVM ERROR: Cannot select: 0x3268c000: i32 = ConstantPool<float 0.000000e+00> 0
In function: some_function
Aborted
This manifests in more complex cases. This was first encountered while calculating the rotation of a line with some code that more resembles
const std = @import("std");
pub export fn some_fn() f32 {
const ax = 0.3;
const ay = 0.3;
const bx = 0.5;
const by = 0.3;
const dx: f32 = bx - ax;
const dy: f32 = by - ay;
const len = @sqrt(dx * dx + dy * dy);
return std.math.atan2(dy / len, dx / len);
}
First encountered on zig 0.13.0, but also observed on 0.14.0-dev.311+c50f30038 and 0.12.1
AFAICT this does not manifest on x86_64 (compiling the same function and calling from main), and does not seem to happen unless I turn on optimizations
Expected Behavior
no crash :)
It compiles successfully.