From owner-freebsd-bugs@freebsd.org Thu Nov 19 06:41:51 2015 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 267FBA32467 for ; Thu, 19 Nov 2015 06:41:51 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 125061B08 for ; Thu, 19 Nov 2015 06:41:51 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id tAJ6fot9025898 for ; Thu, 19 Nov 2015 06:41:50 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 204671] clang floating point wrong around Inf (i386) Date: Thu, 19 Nov 2015 06:41:50 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 10.2-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: netch@segfault.kiev.ua X-Bugzilla-Status: New X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Nov 2015 06:41:51 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204671 Bug ID: 204671 Summary: clang floating point wrong around Inf (i386) Product: Base System Version: 10.2-RELEASE Hardware: i386 OS: Any Status: New Severity: Affects Some People Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: netch@segfault.kiev.ua Created attachment 163320 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=163320&action=edit source files The test program, being called as "./t ", performs a single arithmetic operator with the specified rounding and prints its results. In some cases, output is wrong. Conditions to reproduce: 1. Clang of any available version (confirmed on 3.4 from base, clang36-3.6.2, clang37-3.7.2 from ports). I can't get this issue with gcc-4.8.5, gcc-5.2.0_1 from ports. 2. i386 (amd64 isn't affected, I guess, because the issue is bound to FPU variant). 3. no high -march= ("native" causes issues to disappear, I guess, for the same connection to FPU; clang starts emitting SSE for this CPU). 4. -O or higher optimization level (-O0 isn't affected). The OS is: FreeBSD 10.2-RELEASE-p7 i386. The CPU on the test machine is: AMD Athlon(tm) 64 Processor 3500+ (Origin="AuthenticAMD" Id=0x50ff2 Family=0xf Model=0x5f Stepping=2). The proper results are (as I see from available IEEE754 documents): $ ./t1 1e308 + 1e308 0 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t1 1e308 + 1e308 1 r=1.797693134862316e+308 ( 7F EF FF FF FF FF FF FF) $ ./t1 1e308 + 1e308 2 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t1 1e308 + 1e308 3 r=1.797693134862316e+308 ( 7F EF FF FF FF FF FF FF) This satisties the standard requirement that, e.g., "roundTowardZero, the result shall be the format's floating-point number closest to and no greater in magnitude than the infinitely precise result." The variant with t1.c from attachment when the issue is exposed (compiled as "cc -o t1 t1.c -g -Wall -W -lm -O"): $ ./t1 1e308 + 1e308 0 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t1 1e308 + 1e308 1 r=inf ( 7F EF FF FF FF FF FF FF) $ ./t1 1e308 + 1e308 2 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t1 1e308 + 1e308 3 r=inf ( 7F EF FF FF FF FF FF FF) So, the binary representation of result is correct, but the printf output is not. The same compilation with -DNO_HEX always prints "inf" (so, it rejects a guess of an aliasing issue): $ ./t1 1e308 + 1e308 0 r=inf () $ ./t1 1e308 + 1e308 1 r=inf () $ ./t1 1e308 + 1e308 2 r=inf () $ ./t1 1e308 + 1e308 3 r=inf () The variant in t2.c uses global union instead of local on-stack one for binary printing. The behavior differs so binary representation always shows "inf": $ ./t2 1e308 + 1e308 0 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t2 1e308 + 1e308 1 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t2 1e308 + 1e308 2 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t2 1e308 + 1e308 3 r=inf ( 7F F0 00 00 00 00 00 00) Again, adding -DNO_HEX causes "inf" still printed in all cases. But: a variant with "r" declared as global variable instead of local one (-DR_GLOBAL for both source versions) stops the issue. -- You are receiving this mail because: You are the assignee for the bug.