NetBSD Problem Report #145

From gnats  Tue Mar  1 10:51:09 1994
Received: from forte (forte.mathematik.uni-Bremen.de [134.102.232.1]) by sun-lamp.cs.berkeley.edu (8.6.5/8.6.5) with ESMTP id KAA21493 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Tue, 1 Mar 1994 10:50:21 -0800
Message-Id: <199403011849.TAA02572@forte>
Date: Tue, 1 Mar 1994 19:49:46 +0100
From: thomas@mathematik.uni-Bremen.de
Reply-To: thomas@mathematik.uni-Bremen.de
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: gcc optimizer breaks __ieee754_hypot in libm
X-Send-Pr-Version: 3.2

>Number:         145
>Category:       bin
>Synopsis:       gcc optimizer breaks __ieee754_hypot in libm
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 01 11:05:02 +0000 1994
>Closed-Date:    Fri Mar 04 15:58:45 +0000 1994
>Last-Modified:  Thu Jan 02 18:11:20 +0000 2014
>Originator:     Thomas Eberhardt
>Release:        
>Organization:
CeVis, University of Bremen, Germany
>Environment:

System: NetBSD ed209 0.9a ED209#0 i386

Machine: i386
>Description:
	Compiling lib/libm/src/e_hypot.c with -O or -O2 gives bad code, i.e.
	it calling hypot gives wrong results.
>How-To-Repeat:
	call hypot(3.0, 4.0)
>Fix:
	Until another release of gcc becomes available that is considered
	stable, compile e_hypot.c without any optimizations:

*** lib/libm/Makefile-	Sat Feb 26 11:55:15 1994
--- lib/libm/Makefile	Tue Mar  1 19:42:52 1994
***************
*** 90,94 ****
--- 90,109 ----
  MLINKS+=lgamma.3 gamma.3
  MLINKS+=sqrt.3 cbrt.3

+ e_hypot.o:
+ 	${CC} -D_MULTI_LIBM -D_POSIX_MODE -c ${.IMPSRC}
+ 	@${LD} -x -r ${.TARGET}
+ 	@mv a.out ${.TARGET}
+ 
+ e_hypot.po:
+ 	${CC} -p -D_MULTI_LIBM -D_POSIX_MODE -c ${.IMPSRC} -o ${.TARGET}
+ 	@${LD} -X -r ${.TARGET}
+ 	@mv a.out ${.TARGET}
+ 
+ e_hypot.so:
+ 	${CC} ${PICFLAG} -DPIC -D_MULTI_LIBM -D_POSIX_MODE -c ${.IMPSRC} -o ${.TARGET}
+ 	@${LD} -x -r ${.TARGET}
+ 	@mv a.out ${.TARGET}
+ 

  .include <bsd.lib.mk>
>Release-Note:
>Audit-Trail:

State-Changed-From-To: open->feedback
State-Changed-By: jtc
State-Changed-When: Thu Mar  3 09:10:26 1994
State-Changed-Why:
GCC may be making an unwarranted optimization (or it may not be, I'll
check on this), but I fixed the bug by eliminating the run-time byte
order check (which I wanted to do anyway).  This also fixed some
accuracy problems with asin().

State-Changed-From-To: feedback->closed
State-Changed-By: jtc
State-Changed-When: Fri Mar  4 15:58:45 1994
State-Changed-Why:
It turns out that the fdlibm code used some undefined behavior, which
GCC is was within its rights to optimize away.  The version I checked
in (with a constant word offset) still uses undefined behavior, but 
GCC is smart enough to realize what I mean.

The submitter confirms that this bug was fixed.



>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.