zig icon indicating copy to clipboard operation
zig copied to clipboard

LLVM 14 regression: std.fmt.parseFloat gives wrong bit pattern for NaN on aarch64

Open andrewrk opened this issue 4 years ago • 2 comments

Zig Version: 0.10.0-dev.2896+fa40bddf2

Reproduce:

$ stage1/bin/zig test ../lib/std/std.zig -target aarch64-linux-none
Test [801/2198] fmt.parse_float.test "std-aarch64-linux-none-Debug-bare-multi-default f... expected 32257, found 31745
Test [801/2198] fmt.parse_float.test "std-aarch64-linux-none-Debug-bare-multi-default f... FAIL (TestExpectedEqual)
2118 passed; 79 skipped; 1 failed.
error: the following test command failed with exit code 1:
qemu-aarch64 /home/andy/dev/zig/zig-cache/o/554571ccb0691b6a5f1b1367cbe29186/test /home/andy/dev/zig/build-llvm14-debug/stage1/bin/zig
test...The following command exited with error code 1:
/home/andy/dev/zig/build-llvm14-debug/stage1/bin/zig test /home/andy/dev/zig/lib/std/std.zig --test-name-prefix std-aarch64-linux-none-Debug-bare-multi-default  --cache-dir /home/andy/dev/zig/zig-cache --global-cache-dir /home/andy/.cache/zig --name test -fno-single-threaded -target aarch64-linux-none -mcpu generic --test-cmd qemu-aarch64 --test-cmd-bin -I /home/andy/dev/zig/test -L /home/andy/local/llvm14-debug/lib -isystem /home/andy/local/llvm14-debug/include --zig-lib-dir /home/andy/dev/zig/lib --enable-cache 

Failing test case is:

https://github.com/ziglang/zig/blob/aab1284e10f962af300f495c5e3feccb54bd4964/lib/std/fmt/parse_float.zig#L43

Next steps:

  1. Create LLVM IR test case
  2. use llvm-reduce to create reduction
  3. Check if bug is present on trunk
  4. File upstream bug report

andrewrk avatar Jul 06 '22 23:07 andrewrk

Not a direct reduction, but I found what appears to be a closely related failure:

noinline fn nan(comptime T: type) T {
    return comptime std.math.nan(T);
}

test {
    const nan_const = comptime @bitCast(u16, std.math.nan(f16));
    if (nan_const != @bitCast(u16, nan(f16))) unreachable;
}

This reproduces on LLVM 13 (including Zig 0.9.1 and latest master). Bug filed here: https://github.com/llvm/llvm-project/issues/56454

topolarity avatar Jul 09 '22 18:07 topolarity

Reopened by 5ca1753ff175379c7847ae82243774c79a75879c

andrewrk avatar Dec 28 '22 03:12 andrewrk