Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floating point formatting regression on windows with LLVM 14 upgrade #12063

Closed
andrewrk opened this issue Jul 9, 2022 · 1 comment · Fixed by #12071
Closed

floating point formatting regression on windows with LLVM 14 upgrade #12063

andrewrk opened this issue Jul 9, 2022 · 1 comment · Fixed by #12071
Labels
arch-x86_64 64-bit x86 backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior os-windows regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jul 9, 2022

This test is failing on x86_64 Windows after the LLVM 14 upgrade.

zig/lib/std/fmt.zig

Lines 2286 to 2307 in 3f11d1d

test "float.decimal" {
try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});
try expectFmt("f32: 0", "f32: {d}", .{@as(f32, 0.0)});
try expectFmt("f32: 0", "f32: {d:.0}", .{@as(f32, 0.0)});
try expectFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)});
try expectFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)});
// -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
// -11.12339... is rounded back up to -11.1234
try expectFmt("f32: -11.1234", "f32: {d:.4}", .{@as(f32, -11.1234)});
try expectFmt("f32: 91.12345", "f32: {d:.5}", .{@as(f32, 91.12345)});
try expectFmt("f64: 91.1234567890", "f64: {d:.10}", .{@as(f64, 91.12345678901235)});
try expectFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 0.0)});
try expectFmt("f64: 6", "f64: {d:.0}", .{@as(f64, 5.700)});
try expectFmt("f64: 10.0", "f64: {d:.1}", .{@as(f64, 9.999)});
try expectFmt("f64: 1.000", "f64: {d:.3}", .{@as(f64, 1.0)});
try expectFmt("f64: 0.00030000", "f64: {d:.8}", .{@as(f64, 0.0003)});
try expectFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 1.40130e-45)});
try expectFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 9.999960e-40)});
try expectFmt("f64: 10000000000000.00", "f64: {d:.2}", .{@as(f64, 9999999999999.999)});
try expectFmt("f64: 10000000000000000000000000000000000000", "f64: {d}", .{@as(f64, 1e37)});
try expectFmt("f64: 100000000000000000000000000000000000000", "f64: {d}", .{@as(f64, 1e38)});
}

255/1523 fmt.test "std-native-Debug-bare-multi-default float.decimal"... thread 5980 panic: integer part of floating point value out of bounds
D:\a\1\s\lib\std\fmt\errol.zig:305:15: 0x7ff6c3d2d232 in mt.errol.errolInt (test.obj)
    var mid = @floatToInt(u128, val);
              ^
                                    ^
D:\a\1\s\lib\std\fmt.zig:767:27: 0x7ff6c3ff4cc2 in mt.formatFloatValue (test.obj)
        formatFloatDecimal(value, options, buf_stream.writer()) catch |err| switch (err) {
                          ^
D:\a\1\s\lib\std\fmt.zig:697:58: 0x7ff6c3fc4c2e in mt.formatValue (test.obj)
        .Float, .ComptimeFloat => return formatFloatValue(value, fmt, options, writer),
                                                         ^
D:\a\1\s\lib\std\fmt.zig:463:31: 0x7ff6c3fc4ba2 in mt.formatType (test.obj)
            return formatValue(value, actual_fmt, options, writer);
                              ^
D:\a\1\s\lib\std\fmt.zig:178:23: 0x7ff6c3f0efbd in mt.format (test.obj)
        try formatType(
                      ^
D:\a\1\s\lib\std\fmt.zig:1889:11: 0x7ff6c3e2de9a in mt.count (test.obj)
    format(counting_writer.writer(), fmt, args) catch |err| switch (err) {};
          ^
D:\a\1\s\lib\std\fmt.zig:1896:40: 0x7ff6c3e2da24 in mt.allocPrint (test.obj)
    const size = math.cast(usize, count(fmt, args)) orelse return error.OutOfMemory;
                                       ^
D:\a\1\s\lib\std\testing.zig:201:42: 0x7ff6c3d7227a in esting.expectFmt (test.obj)
    const result = try std.fmt.allocPrint(allocator, template, args);
                                         ^
D:\a\1\s\lib\std\fmt.zig:2287:18: 0x7ff6c3ba139f in mt.test "std-native-Debug-bare-multi-default float.decimal" (test.obj)
    try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});
                 ^
D:\a\1\s\lib\test_runner.zig:79:28: 0x7ff6c3cfbd84 in root).main (test.obj)
        } else test_fn.func();
                           ^
D:\a\1\s\lib\std\start.zig:349:65: 0x7ff6c3cb7297 in tart.WinStartup (test.obj)
    std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain());
                                                                ^
Unable to dump stack trace: FileNotFound
error: the following test command failed with exit code 3:
D:\a\1\s\zig-cache\o\3f11261b1cc8172c23869e13e5cf0db2\test.exe D:\a\1\s\build\dist\bin\zig.exe
test...The following command exited with error code 1:
D:\a\1\s\build\dist\bin\zig.exe test D:\a\1\s\lib\std\std.zig --test-name-prefix std-native-Debug-bare-multi-default  --cache-dir D:\a\1\s\zig-cache --global-cache-dir C:\Users\VssAdministrator\AppData\Local\zig --name test -fno-single-threaded -I D:\a\1\s\test --zig-lib-dir D:\a\1\s\lib --enable-cache 

Next steps:

  • figure out why, is it an LLVM or zig bug?
  • if it's an LLVM bug, create a reduction with LLVM IR using llvm-reduce
  • report bug upstream
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-windows arch-x86_64 64-bit x86 backend-llvm The LLVM backend outputs an LLVM IR Module. regression It worked in a previous version of Zig, but stopped working. labels Jul 9, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Jul 9, 2022
andrewrk added a commit that referenced this issue Jul 9, 2022
@topolarity
Copy link
Contributor

topolarity commented Jul 10, 2022

test {
    var x: f64 = 1.52314e+29;
    const y = @floatToInt(u128, x);
    _ = y;
}

Upstream issue: llvm/llvm-project#56461 Looks like it's an ABI change in the LLVM libcall. Will open a PR soon to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86_64 64-bit x86 backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior os-windows regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants