From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 397B5385701A; Mon, 30 Aug 2021 15:00:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 397B5385701A From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/102129] -ftrapping-math is broken or badly documented Date: Mon, 30 Aug 2021 15:00:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Aug 2021 15:00:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102129 --- Comment #1 from Vincent Lef=C3=A8vre --- Additional surprising behavior... On the following C code: void g (void); double f (void) { double x =3D 0.0, y =3D 0.0; double r =3D x / y; g (); return r; } one can see with -ftrapping-math (the default) that a 0.0 / 0.0 is done bef= ore the call to g, which is the expected behavior (this time, the order of the operations has been preserved): pxor %xmm0, %xmm0 divsd %xmm0, %xmm0 movsd %xmm0, 8(%rsp) call g@PLT movsd 8(%rsp), %xmm0 (note that with -fno-trapping-math, a NaN is just generated at compile time= ). But on the following C code: void g (void); double f (void) { double x =3D 1.0, y =3D 3.0; double r =3D x / y; g (); return r; } GCC behaves as with -fno-trapping-math, i.e. g is called, then the rounded value of 1/3 is returned, while there should have been an inexact exception (the GCC manual explicitly mentions inexact as one of the possible traps).=