This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: isfinite() failure on Cygwin with gcc 3.4.1


> From:  William M. (Mike) Miller
> Sent: Friday, 4 February 2005 12:24 AM
> 
> Andrew Pinski wrote:
> > Lets look at the definition of the macros again:
> > 
> > 
> >>#define fpclassify(x) \
> >>          (__extension__ ({__typeof__(x) __x = (x); \
> >>                           (sizeof (__x) == sizeof (float)) 
>  ? __fpclassifyf(__x) : __fpclassifyd(__x);}))
> >>
> >>#define isfinite(x) \
> >>          (__extension__ ({__typeof__(x) __x = (x); \
> >>                           fpclassify(__x) != FP_INFINITE 
> && fpclassify(__x) != FP_NAN;}))
> > 
> > 
> > See how we pass __x to fpclassify, well when we 
> preprocessed the source we get in there:
> > __typeof__(x) __x = (__x); which just makes this 
> uninitialized.  The reason why we
> > don't warn about it in gcc is because int a = a; is 
> documented to have the uninitilizated
> > warnings to go away.
> > 
> > Thanks,
> > Andrew Pinski
> > a gcc developer and a gcc bug master
> 
> Aha, mystery solved!  (*smacking forehead*) I should have noticed 
> that -- would have made for a shorter bug report.  Thanks for 
> looking into it.
> 

This problem affects more than just isfinite. fpclassify is used 
elsewhere, and the expansion of isunordered() ends up with multiple
uninitilizated variables.  This patch rewrites them in the style
of the C99 standard (7.12.3.1) and winsup/mingw/include/math.h.
Tested on cygwin.  Test program available on request.

I have a cygwin copywrite assignment on file, but no CVS access.

2005-02-08  David Billinghurst <David.Billinghurst@riotinto.com>

	* libc/include/math.h (fpclassify,isfinite,isnormal,signbit,isgreater,
	isless,islessequal,islessgreater,isunordered): Rewrite to avoid
	possible uninitialized variables.
 
$ diff -u /usr/include/math.h math.h
--- /usr/include/math.h 2004-11-11 00:35:30.001000000 +1100
+++ math.h      2005-02-07 13:19:15.467014200 +1100
@@ -85,38 +85,34 @@
 extern int __signbitd (double x);
 
 #define fpclassify(x) \
-          (__extension__ ({__typeof__(x) __x = (x); \
-                           (sizeof (__x) == sizeof (float))  ? __fpclassifyf(__x) : __fpclassifyd(__x);}))
+          ((sizeof (x) == sizeof (float)) \
+          ?  __fpclassifyf (x) \
+          :  __fpclassifyd (x) )
 
 #define isfinite(x) \
-          (__extension__ ({__typeof__(x) __x = (x); \
-                           fpclassify(__x) != FP_INFINITE && fpclassify(__x) != FP_NAN;}))
+          ( (fpclassify(x) != FP_INFINITE) \
+           && (fpclassify(x) != FP_NAN) )
+
 #define isnormal(x) \
-          (__extension__ ({__typeof__(x) __x = (x); \
-                           fpclassify(__x) == FP_NORMAL;}))
+          ( fpclassify(x) == FP_NORMAL )
+
 #define signbit(x) \
-          (__extension__ ({__typeof__(x) __x = (x); \
-                           (sizeof(__x) == sizeof(float)) ? __signbitf(__x) : __signbitd(__x);}))
+          ((sizeof (x) == sizeof (float)) \
+           ? __signbitf (x) \
+          : __signbitd (x))
 
 #define isgreater(x,y) \
-          (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
-                           !isunordered(__x,__y) && (__x > __y);}))
+          ( !isunordered(x,y) && ((x) > (y)) )
 #define isgreaterequal(x,y) \
-          (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
-                           !isunordered(__x,__y) && (__x >= __y);}))
+          ( !isunordered(x,y) && ((x) >= (y)) )
 #define isless(x,y) \
-          (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
-                           !isunordered(__x,__y) && (__x < __y);}))
+          ( !isunordered(x,y) && ((x) < (y)) )
 #define islessequal(x,y) \
-          (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
-                           !isunordered(__x,__y) && (__x <= __y);}))
+          ( !isunordered(x,y) && ((x) <= (y)) )
 #define islessgreater(x,y) \
-          (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
-                           !isunordered(__x,__y) && (__x < __y || __x > __y);}))
-
+          ( !isunordered(x,y) && ((x) < (y) || (x) > (y)) )
 #define isunordered(x,y) \
-          (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
-                           fpclassify(__x) == FP_NAN || fpclassify(__y) == FP_NAN;}))
+          ( fpclassify(x) == FP_NAN || fpclassify(y) == FP_NAN )
 
 /* Non ANSI double precision functions.  */


NOTICE
This e-mail and any attachments are private and confidential and may contain privileged information. If you are not an authorised recipient, the copying or distribution of this e-mail and any attachments is prohibited and you must not read, print or act in reliance on this e-mail or attachments.
This notice should not be removed.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]