Article View: gnu.gcc.bug
Article #1500fabs seems to be "broken" in 2.3.2...
From: Przemek Skoskiewicz
Date: Tue, 29 Dec 1992 20:38
Date: Tue, 29 Dec 1992 20:38
95 lines
2673 bytes
2673 bytes
The following is a program that recreates the problem. Basically, calling
fabs directly on any double number works fine. But calling it the way I do
produces negative numbers for positive input. This happens only with the
optimization; the debug version works fine. This code has been around since
1.x versions of GCC and stopped working when we updated to 2.3.2 last week.
We've been using 2.2.2 for some time and I recompiled with that version and it
worked fine. So, I suspect that the problem is with the new GCC version.
I've ran the code through cpp and all the parenthesis and macro substitutions
seemed all right.
I've compiled this code with `gcc foo.c -O4'.
#include "stdio.h"
#include "math.h"
typedef struct
{
unsigned short line_number;
union
{
struct
{
double data;
} flonum;
struct
{
long data;
} fixnum;
} storage_as;
} sexp, *sexpID;
#define FLONM(x) ((*x).storage_as.flonum.data)
static sexpID test(sexpID);
extern sexpID make_sexp(double);
sexpID make_sexp(number)
double number;
{
sexpID x;
x = (sexpID) malloc (sizeof (sexp));
FLONM (x) = number;
return (x);
}
static sexpID test(z)
sexpID z;
{
return (make_sexp (fabs (FLONM (z))));
}
/*
* This macro is used very frequently in the code and originally caught the
* problem--I thought that it was because it's a macro. But then I wrote a
* real function above, test, and it does the same thing.
*/
#define MATHLIB(proc, mathproc) \
static sexpID proc(x) \
sexpID x; \
{ \
return (make_sexp (mathproc (FLONM (x)))); \
}
MATHLIB (test1, fabs);
main()
{
sexpID xx;
xx = (sexpID) malloc (sizeof (sexp));
FLONM (xx) = 5;
/*
* Instead of printing `One: 5', both of these calls print `One: -5'.
* Way too strange.
*/
printf ("One: %g\n", FLONM (test1 (xx)));
printf ("Two: %g\n", FLONM (test (xx)));
}
Viewlogic Systems, Inc. Przemek Skoskiewicz
293 Boston Post Road West
Marlborough, MA 01752-4615, USA
email: przemek@viewlogic.com
Technical Details
Message-ID:
<9212292038.AA24854@elvis>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!viewlogic.COM!przemekShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!viewlogic.COM!przemek From: przemek@viewlogic.COM (Przemek Skoskiewicz) Subject: fabs seems to be "broken" in 2.3.2... Message-ID: <9212292038.AA24854@elvis> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Tue, 29 Dec 1992 20:38:20 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 96