home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / gcc / bug / 3081 < prev    next >
Encoding:
Text File  |  1992-12-30  |  2.5 KB  |  109 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!viewlogic.COM!przemek
  3. From: przemek@viewlogic.COM (Przemek Skoskiewicz)
  4. Subject: fabs seems to be "broken" in 2.3.2...
  5. Message-ID: <9212292038.AA24854@elvis>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Tue, 29 Dec 1992 20:38:20 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 96
  12.  
  13. The following is a program that recreates the problem.  Basically, calling
  14. fabs directly on any double number works fine.  But calling it the way I do
  15. produces negative numbers for positive input.  This happens only with the
  16. optimization; the debug version works fine.  This code has been around since
  17. 1.x versions of GCC and stopped working when we updated to 2.3.2 last week.
  18. We've been using 2.2.2 for some time and I recompiled with that version and it
  19. worked fine.  So, I suspect that the problem is with the new GCC version.
  20.  
  21. I've ran the code through cpp and all the parenthesis and macro substitutions
  22. seemed all right.
  23.  
  24. I've compiled this code with `gcc foo.c -O4'.
  25.  
  26.  
  27. #include "stdio.h"
  28. #include "math.h"
  29.  
  30. typedef struct 
  31. {
  32.     unsigned short  line_number;
  33.     union
  34.     {
  35.         struct
  36.         {
  37.             double data;
  38.         } flonum;
  39.         struct
  40.         {
  41.             long data;
  42.         } fixnum;
  43.     } storage_as;
  44. } sexp, *sexpID;
  45.  
  46. #define FLONM(x)                    ((*x).storage_as.flonum.data)
  47.  
  48.  
  49. static sexpID test(sexpID);
  50. extern sexpID make_sexp(double);
  51.  
  52.  
  53. sexpID make_sexp(number)
  54.     double number;
  55. {
  56.     sexpID  x;
  57.  
  58.     x = (sexpID) malloc (sizeof (sexp));
  59.     FLONM (x) = number;
  60.     return (x);
  61. }
  62.  
  63.  
  64. static sexpID test(z)
  65.     sexpID z;
  66. {
  67.     return (make_sexp (fabs (FLONM (z))));
  68. }
  69.  
  70. /*
  71.  * This macro is used very frequently in the code and originally caught the
  72.  * problem--I thought that it was because it's a macro.  But then I wrote a
  73.  * real function above, test, and it does the same thing.
  74.  */
  75. #define MATHLIB(proc, mathproc) \
  76.     static sexpID proc(x) \
  77.         sexpID x; \
  78.     { \
  79.           return (make_sexp (mathproc (FLONM (x)))); \
  80.     }
  81.  
  82.  
  83. MATHLIB (test1, fabs);
  84.  
  85.  
  86. main()
  87. {
  88.     sexpID  xx;
  89.  
  90.     xx = (sexpID) malloc (sizeof (sexp));
  91.  
  92.     FLONM (xx) = 5;
  93.  
  94.     /*
  95.      * Instead of printing `One: 5', both of these calls print `One: -5'.
  96.      * Way too strange.
  97.      */
  98.     printf ("One: %g\n", FLONM (test1 (xx)));
  99.     printf ("Two: %g\n", FLONM (test (xx)));
  100. }
  101.  
  102.  
  103.  
  104. Viewlogic Systems, Inc.                         Przemek Skoskiewicz
  105. 293 Boston Post Road West
  106. Marlborough, MA 01752-4615, USA
  107. email: przemek@viewlogic.com
  108.  
  109.