From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27970 invoked by alias); 25 Jul 2014 09:07:11 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 27846 invoked by uid 48); 25 Jul 2014 09:07:02 -0000 From: "ktkachov at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/61876] Converting __builtin_round + cast into __builtin_lround is not always equivalent in regards to math errno Date: Fri, 25 Jul 2014 09:07:00 -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: 4.10.0 X-Bugzilla-Keywords: missed-optimization, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: ktkachov at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ktkachov 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: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg01676.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61876 --- Comment #7 from ktkachov at gcc dot gnu.org --- (In reply to joseph@codesourcery.com from comment #6) > On Tue, 22 Jul 2014, ktkachov at gcc dot gnu.org wrote: > > > From what I understand lround can potentially set errno on a domain error > > whereas round is valid everywhere and the cast to long int could be undefined > > behaviour if the double is not valid, but undefined behaviour is not the same > > as setting errno... > > Under Annex F the cast isn't undefined behavior but raising the "invalid" > exception and returning an unspecified value (which must be a valid value > of type long, i.e. the program must behave as if each execution of the > cast in the abstract machine has some particular value of type long it > returns). In my copy at 6.3.1.4 on Real floating and integer conversions it says: If the value of the integral part cannot be represented by the integer type, the behavior is undefined. In any case, it seems to me the transformation of cast+round -> lround is only valid when: - the result is within the range of the long int - the argument is not NaN or infinity. In convert.c this transformation is already guarded by the type precision so we got the first point covered, but I think we also have to guard it by -ffinite-math-only. Is that reasonable?