Repository navigation
Floating-point <=> lowering correctness issues
#354
jonatanlinden
started this conversation in
Issue Triage - Compilation
Replies: 1 comment
|
I'd like to add that I have a suggested fix, that I'm on the way to create a PR for. (I'm working for Qt/IAR) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Issue Summary
The new run-time NaN handling for floating-point
<=>inlower_cpp20_spaceshiplowersx <=> yto:The generated C has two problems:
xis evaluated only inside the right operand of||. Whenyis NaN,xis never evaluated, so its side effects are lost.yhas no side effects, it is not copied to a temporary, and it is read both beforexis evaluated (in the NaN test) and after (in the<tests). Ifxmodifiesy, the NaN test and the ordering tests see different values.Reproducing Source Code
<compare>is the front end's own header (include_c++/compare.stdh).Command-line Options
cpfe --c++20 -I/include_c++ repro.cpp
Type of Issue
[Back End] There is a problem with the generated C code.
Additional Details
Generated C for the two functions (temporaries renamed
tx,ty,thandr):Problem 1: the left operand is not evaluated when the right operand is NaN. In
issue1, the only call ofx()is in the right operand of||. Ify()returns NaN,x()is never called. The order of evaluation of the two operands of<=>is unspecified, so callingy()first is allowed, but both operands must be evaluated. (The order also differs from the comment in the source, which says__isnan(temp1 = x) || __isnan(temp2 = y).)Problem 2: a side-effect-free operand is re-read after the other operand has been evaluated. In
issue2,gis read by__builtin_isnanf(g)beforeh()is called, and again by both<tests after it. Ifh()stores a NaN intogwhilegwas not NaN before, the NaN test finds no NaN, both<tests are false, and the result isEQUIVALENT. A single read ofg, before or afterh(), could only giveLESS/GREATERorUNORDERED.Godbolt: https://godbolt.org/z/KfMWorjb3 (two asserts, comment out the first one to make the second one trigger)
Reproducing (Standard) Configuration(s)
linux-gcc-release
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
LICENSE.txtfile in my.zipor.tar.gzupload. If I included aLICENSE.txtfile, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.All reactions