Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Przemek Skoskiewicz
Tue, 29 Dec 1992 20:38
fabs seems to be "broken" in 2.3.2...
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads