home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / gcc / bug / 2770 < prev    next >
Encoding:
Text File  |  1992-11-17  |  6.5 KB  |  292 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!lamothe.informatik.uni-dortmund.de!schwab
  3. From: schwab@lamothe.informatik.uni-dortmund.de (Andreas Schwab)
  4. Subject: GCC 2.3.1/m68k: incorrect output
  5. Message-ID: <9211161042.AA11690@lamothe.informatik.uni-dortmund.de>
  6. Sender: gnulists@ai.mit.edu
  7. Reply-To: schwab@ls5.informatik.uni-dortmund.de (Andreas Schwab)
  8. Organization: GNUs Not Usenet
  9. Distribution: gnu
  10. Date: Mon, 16 Nov 1992 12:42:11 GMT
  11. Approved: bug-gcc@prep.ai.mit.edu
  12. Lines: 278
  13.  
  14. GCC 2.3.1/m68k (Atari ST) generates incorrect output for the file test.c
  15. (see below), if compiled with
  16.  
  17. gcc -O2 -fomit-frame-pointer -m68000 -msoft-float -S test.c
  18.  
  19. (-m68000 and -msoft-float are not generally required to trigger the
  20. bug; they only make the function more complex)
  21.  
  22. Here are the relevant parts of the output:
  23.  
  24. ---------- test.s
  25. #NO_APP
  26. gcc2_compiled.:
  27. .text
  28.     .even
  29. _ston:
  30.     addw #-24,sp
  31.     moveml #0x3f3e,sp@-
  32.     movel sp@(72),a3
  33.     clrl sp@(60)
  34.     moveb #43,sp@(59)    | char msign = '+';
  35.     moveb sp@(59),sp@(57)    | char esign = '+';
  36.  
  37. | lines deleted
  38.  
  39.     moveq #43,d7        | if (c == '+' || c == '-')
  40.     cmpl a2,d7
  41.     jeq L6
  42.     moveq #45,d7
  43.     cmpl a2,d7
  44.     jne L5
  45.  
  46. L6:
  47.     movew a2,sp@-        | msign = c;
  48.     moveb sp@(1),sp@(59)    | <---- should be sp@(61)
  49.     addqw #2,sp
  50.     moveb a3@+,d7        | c = *s++;
  51.     extw d7
  52.     movew d7,a0
  53.     movew a0,a2
  54.  
  55. | many lines deleted
  56.  
  57.     moveq #101,d7        | if (c == 'e' || c == 'E')
  58.     cmpl a2,d7
  59.     jeq L23
  60.     moveq #69,d7
  61.     cmpl a2,d7
  62.     jne L22
  63. L23:
  64.     addql #1,sp@(60)    | realflag++;
  65.     moveb a3@+,d7        | c = *s++;
  66.     extw d7
  67.     movew d7,a0
  68.     movew a0,a2
  69.     moveq #43,d7        | if (c == '+' || c == '-')
  70.     cmpl a2,d7
  71.     jeq L25
  72.     moveq #45,d7
  73.     cmpl a2,d7
  74.     jne L24
  75. L25:
  76.     movew a2,sp@-        | esign = c;
  77.     moveb sp@(1),sp@(57)    | <---- should be sp@(59)
  78.     addqw #2,sp
  79.     moveb a3@+,d7        | c = *s++;
  80.     extw d7
  81.     movew d7,a0
  82.     movew a0,a2
  83.  
  84. | rest deleted
  85. ----------
  86.  
  87. Here is the test file:
  88.  
  89. ---------- test.c
  90. double ldexp (double, int);
  91.  
  92. typedef int word;
  93. typedef struct descrip *dptr;
  94.  
  95. struct descrip
  96.   {
  97.     word dword;
  98.     word integr;
  99.   };
  100.  
  101. int makereal (double r, dptr dp);
  102. word bigradix (int sign, int r, char *s, dptr dx);
  103.  
  104. extern unsigned char *_ctype;
  105.  
  106. static int 
  107. ston (s, dp)
  108.      register char *s;
  109.      dptr dp;
  110. {
  111.   register int c;
  112.   int realflag = 0;
  113.   char msign = '+';
  114.   char esign = '+';
  115.   double mantissa = 0;
  116.   long lresult = 0;
  117.   int scale = 0;
  118.   int digits = 0;
  119.   int sdigits = 0;
  120.   int exponent = 0;
  121.   double fiveto;
  122.   double power;
  123.   int err_no;
  124.   char *ssave;
  125.  
  126.   c = *s++;
  127.   while ((_ctype[(unsigned char) (c)] & 0x10))
  128.     c = *s++;
  129.   if (c == '+' || c == '-')
  130.     {
  131.       msign = c;
  132.       c = *s++;
  133.     }
  134.   ssave = s - 1;
  135.   while ((_ctype[(unsigned char) (c)] & 0x02))
  136.     {
  137.       digits++;
  138.       if (mantissa < 9007199254740992.)
  139.     {
  140.       mantissa = mantissa * 10 + (c - '0');
  141.       lresult = lresult * 10 + (c - '0');
  142.       if (mantissa > 0.0)
  143.         sdigits++;
  144.     }
  145.       else
  146.     scale++;
  147.       c = *s++;
  148.     }
  149.   if (c == 'r' || c == 'R')
  150.     return bigradix (msign, (int) mantissa, s, dp);
  151.   if (c == '.')
  152.     {
  153.       realflag++;
  154.       c = *s++;
  155.       while ((_ctype[(unsigned char) (c)] & 0x02))
  156.     {
  157.       digits++;
  158.       if (mantissa < 9007199254740992.)
  159.         {
  160.           mantissa = mantissa * 10 + (c - '0');
  161.           lresult = lresult * 10 + (c - '0');
  162.           scale--;
  163.           if (mantissa > 0.0)
  164.         sdigits++;
  165.         }
  166.       c = *s++;
  167.     }
  168.     }
  169.   if (digits == 0)
  170.     return -2;
  171.   if (c == 'e' || c == 'E')
  172.     {
  173.       realflag++;
  174.       c = *s++;
  175.       if (c == '+' || c == '-')
  176.     {
  177.       esign = c;
  178.       c = *s++;
  179.     }
  180.       if (!(_ctype[(unsigned char) (c)] & 0x02))
  181.     return -2;
  182.       while ((_ctype[(unsigned char) (c)] & 0x02))
  183.     {
  184.       exponent = exponent * 10 + (c - '0');
  185.       c = *s++;
  186.     }
  187.       scale += (esign == '+') ? exponent : -exponent;
  188.     }
  189.   while ((_ctype[(unsigned char) (c)] & 0x10))
  190.     c = *s++;
  191.   if (c != '\0')
  192.     return -2;
  193.   if (!realflag && !scale && mantissa >= ((long int) 020000000000L)
  194.       && mantissa <= ((long int) 017777777777L))
  195.     {
  196.       dp->dword = (word) (1 | 0x80000000);
  197.       dp->integr = (msign == '+' ? lresult : -lresult);
  198.       return 1;
  199.     }
  200.   if (!realflag)
  201.     return bigradix (msign, 10, ssave, dp);
  202.   if (!realflag)
  203.     return -2;
  204.   if (sdigits + scale > 309)
  205.     return -2;
  206.   if (sdigits + scale < -309)
  207.     {
  208.       makereal (0.0, dp);
  209.       return 3;
  210.     }
  211.   exponent = (scale > 0) ? scale : -scale;
  212.   fiveto = 1.0;
  213.   power = 5.0;
  214.   for (;;)
  215.     {
  216.       if (exponent & 01)
  217.     fiveto *= power;
  218.       exponent >>= 1;
  219.       if (exponent == 0)
  220.     break;
  221.       power *= power;
  222.     }
  223.   if (scale > 0)
  224.     mantissa *= fiveto;
  225.   else
  226.     mantissa /= fiveto;
  227.   err_no = 0;
  228.   mantissa = ldexp (mantissa, scale);
  229.   if (err_no > 0 && mantissa > 0)
  230.     return -2;
  231.   if (msign == '-')
  232.     mantissa = -mantissa;
  233.   makereal (mantissa, dp);
  234.   return 3;
  235. }
  236. ----------
  237.  
  238. This patch tries to correct the bug.
  239.  
  240. --- m68k.md~    Fri Nov 13 22:16:12 1992
  241. +++ m68k.md    Sun Nov 15 18:01:18 1992
  242. @@ -921,7 +921,15 @@
  243.        && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
  244.        && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx)
  245.      {
  246. -      xoperands[1] = operands[1];
  247. +      if (GET_CODE (operands[1]) == MEM
  248. +      && (XEXP (operands[1], 0) == stack_pointer_rtx
  249. +          || (GET_CODE (XEXP (operands[1], 0)) == PLUS
  250. +          && XEXP (XEXP (operands[1], 0), 0) == stack_pointer_rtx)))
  251. +    xoperands[1]
  252. +      = gen_rtx (MEM, GET_MODE (operands[1]),
  253. +             plus_constant (XEXP (operands[1], 0), 2));
  254. +      else
  255. +    xoperands[1] = operands[1];
  256.        xoperands[2]
  257.          = gen_rtx (MEM, QImode,
  258.             gen_rtx (PLUS, VOIDmode, stack_pointer_rtx, const1_rtx));
  259. @@ -934,7 +942,14 @@
  260.  
  261.    if (ADDRESS_REG_P (operands[0]) && GET_CODE (operands[1]) == MEM)
  262.      {
  263. -      xoperands[1] = operands[1];
  264. +      if (XEXP (operands[1], 0) == stack_pointer_rtx
  265. +      || (GET_CODE (XEXP (operands[1], 0)) == PLUS
  266. +          && XEXP (XEXP (operands[1], 0), 0) == stack_pointer_rtx))
  267. +    xoperands[1]
  268. +      = gen_rtx (MEM, GET_MODE (operands[1]),
  269. +             plus_constant (XEXP (operands[1], 0), 2));
  270. +      else
  271. +    xoperands[1] = operands[1];
  272.        xoperands[2]
  273.          = gen_rtx (MEM, QImode,
  274.             gen_rtx (PLUS, VOIDmode, stack_pointer_rtx, const1_rtx));
  275. @@ -946,7 +961,14 @@
  276.      }
  277.    if (ADDRESS_REG_P (operands[1]) && GET_CODE (operands[0]) == MEM)
  278.      {
  279. -      xoperands[0] = operands[0];
  280. +      if (XEXP (operands[0], 0) == stack_pointer_rtx
  281. +      || (GET_CODE (XEXP (operands[0], 0)) == PLUS
  282. +          && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx))
  283. +    xoperands[0]
  284. +      = gen_rtx (MEM, GET_MODE (operands[0]),
  285. +             plus_constant (XEXP (operands[0], 0), 2));
  286. +      else
  287. +    xoperands[0] = operands[0];
  288.        xoperands[1] = operands[1];
  289.        xoperands[2]
  290.          = gen_rtx (MEM, QImode,
  291.  
  292.