diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-06-15 14:18:37 +0100 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2025-06-15 14:15:18 -0400 |
| commit | 6ffa285fc35651cb7f4b738a0f6e84718b821fd8 (patch) | |
| tree | 5c1307e2cfc9d6becd2bbcbdcd64979ca5dab5d9 /lib/std/Thread/WaitGroup.zig | |
| parent | 6b41beb370ce62b4381396e0543e6eb7f70b18cf (diff) | |
| download | zig-6ffa285fc35651cb7f4b738a0f6e84718b821fd8.tar.gz zig-6ffa285fc35651cb7f4b738a0f6e84718b821fd8.zip | |
compiler: fix `@intFromFloat` safety check
This safety check was completely broken; it triggered unchecked illegal
behavior *in order to implement the safety check*. You definitely can't
do that! Instead, we must explicitly check the boundaries. This is a
tiny bit fiddly, because we need to make sure we do floating-point
rounding in the correct direction, and also handle the fact that the
operation truncates so the boundary works differently for min vs max.
Instead of implementing this safety check in Sema, there are now
dedicated AIR instructions for safety-checked intfromfloat (two
instructions; which one is used depends on the float mode). Currently,
no backend directly implements them; instead, a `Legalize.Feature` is
added which expands the safety check, and this feature is enabled for
all backends we currently test, including the LLVM backend.
The `u0` case is still handled in Sema, because Sema needs to check for
that anyway due to the comptime-known result. The old safety check here
was also completely broken and has therefore been rewritten. In that
case, we just check for 'abs(input) < 1.0'.
I've added a bunch of test coverage for the boundary cases of
`@intFromFloat`, both for successes (in `test/behavior/cast.zig`) and
failures (in `test/cases/safety/`).
Resolves: #24161
Diffstat (limited to 'lib/std/Thread/WaitGroup.zig')
0 files changed, 0 insertions, 0 deletions
