From owner-freebsd-toolchain@freebsd.org Sun Mar 13 18:46:12 2016 Return-Path: Delivered-To: freebsd-toolchain@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 E2892ACF575 for ; Sun, 13 Mar 2016 18:46:12 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "troutmask", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id CB8CB1A61 for ; Sun, 13 Mar 2016 18:46:12 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id u2DIPLMe025459 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Sun, 13 Mar 2016 11:25:21 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id u2DIPL10025458 for freebsd-toolchain@freebsd.org; Sun, 13 Mar 2016 11:25:21 -0700 (PDT) (envelope-from sgk) Date: Sun, 13 Mar 2016 11:25:21 -0700 From: Steve Kargl To: freebsd-toolchain@freebsd.org Subject: clang gets numerical underflow wrong, please fix. Message-ID: <20160313182521.GA25361@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Mar 2016 18:46:13 -0000 Consider this small piece of code: #include #include float foo() { static const volatile float tiny = 1.e-30f; return (tiny * tiny); } int main(void) { float x; feclearexcept(FE_ALL_EXCEPT); x = foo(); if (fetestexcept(FE_UNDERFLOW)) printf("FE_UNDERFLOW: "); printf("x = %e\n", x); return 0; } clang seems to get the underflow condition wrong. % cc -o z a.c -lm && ./z FE_UNDERFLOW: x = 0.000000e+00 % cc -O -o z a.c -lm && ./z x = 1.000000e-60 <--- This is not a possible value! % gcc -o z a.c -lm && ./z FE_UNDERFLOW: x = 0.000000e+00 % gcc -O -o z a.c -lm && ./z FE_UNDERFLOW: x = 0.000000e+00 % uname -a FreeBSD laptop-kargl 11.0-CURRENT FreeBSD 11.0-CURRENT #1 r296724: Sun Mar 13 09:12:38 PDT 2016 % cc --version FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0) % gcc --version gcc (FreeBSD Ports Collection) 4.8.5 -- Steve