home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gcc / bug / 1979 < prev    next >
Encoding:
Text File  |  1992-07-25  |  7.7 KB  |  280 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggert
  3. From: eggert@twinsun.COM (Paul Eggert)
  4. Subject: bugs in GCC 2.2.2 floating point range and suffix checks
  5. Message-ID: <9207241921.AA22356@farside.twinsun.com>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Fri, 24 Jul 1992 19:21:07 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 267
  12.  
  13. 1.  GCC 2.2.2 (sparc, SunOS 4.1.2) does not issue a diagnostic for the program:
  14.  
  15.     double d = 1.0fl;
  16.  
  17. even though the conflicting suffixes `f' and `l' violate C syntax.
  18.  
  19. 2.  For the program
  20.  
  21.     float f = 1e400f;
  22.  
  23. `gcc -pedantic' issues the following redundant diagnostics.
  24.  
  25.     t.c:1: warning: floating point number exceeds range of `double'
  26.     t.c:1: warning: floating point number exceeds range of `float'
  27.  
  28. Here is a patch.  This patch affects both the C and the C++ lexers, and
  29. assumes that you've already applied the patch ``gcc 2.2.2 fp constant overflow
  30. check should use REAL_VALUES_LESS'' that I reported on June 15.  The code in
  31. the two 2.2.2 lexers had diverged slightly, because some changes were applied
  32. to the C lexer but not the C++ lexer.  The patch below updates the C++ lexer
  33. to match the C lexer.
  34.  
  35. Fri Jul 24 19:09:02 1992  Paul Eggert  (eggert@twinsun.com)
  36.  
  37.     * c-lex.c, cp-lex.c (yylex): Diagnose `1.0fl'.  Issue just one
  38.     diagnostic for `1e1000000f'.
  39.  
  40. ===================================================================
  41. RCS file: c-lex.c,v
  42. retrieving revision 2.2.2.1
  43. diff -c -r2.2.2.1 c-lex.c
  44. *** c-lex.c    1992/06/15 20:45:16    2.2.2.1
  45. --- c-lex.c    1992/07/24 18:54:59
  46. ***************
  47. *** 1245,1252 ****
  48.       if (floatflag != NOT_FLOAT)
  49.         {
  50.           tree type = double_type_node;
  51. !         char f_seen = 0;
  52. !         char l_seen = 0;
  53.           REAL_VALUE_TYPE value;
  54.           jmp_buf handler;
  55.   
  56. --- 1245,1251 ----
  57.       if (floatflag != NOT_FLOAT)
  58.         {
  59.           tree type = double_type_node;
  60. !         int garbage_chars = 0, exceeds_double = 0;
  61.           REAL_VALUE_TYPE value;
  62.           jmp_buf handler;
  63.   
  64. ***************
  65. *** 1297,1348 ****
  66.           if (REAL_VALUES_LESS (dconst1, value)
  67.               || REAL_VALUES_LESS (value, dconstm1))
  68.             pedwarn ("floating point number exceeds range of `double'");
  69.             }
  70.   #endif
  71.   
  72.           /* Read the suffixes to choose a data type.  */
  73. !         while (1)
  74.             {
  75. !         if (c == 'f' || c == 'F')
  76. !           {
  77. !             if (f_seen)
  78. !               error ("two `f's in floating constant");
  79. !             else
  80. !               {
  81. !             f_seen = 1;
  82. !             type = float_type_node;
  83. !             value = REAL_VALUE_TRUNCATE (TYPE_MODE (type), value);
  84. !             if (REAL_VALUE_ISINF (value) && pedantic)
  85. !               pedwarn ("floating point number exceeds range of `float'");
  86. !               }
  87. !           }
  88. !         else if (c == 'l' || c == 'L')
  89. !           {
  90. !             if (l_seen)
  91. !               error ("two `l's in floating constant");
  92. !             l_seen = 1;
  93. !             type = long_double_type_node;
  94. !           }
  95. !         else
  96. !           {
  97. !             if (isalnum (c))
  98. !               {
  99. !             error ("garbage at end of number");
  100. !             while (isalnum (c))
  101. !               {
  102. !                 if (p >= token_buffer + maxtoken - 3)
  103. !                   p = extend_token_buffer (p);
  104. !                 *p++ = c;
  105. !                 c = getc (finput);
  106. !               }
  107. !               }
  108. !             break;
  109. !           }
  110.           if (p >= token_buffer + maxtoken - 3)
  111.             p = extend_token_buffer (p);
  112.           *p++ = c;
  113.           c = getc (finput);
  114.             }
  115.   
  116.           /* Create a node with determined type and value.  */
  117.           yylval.ttype = build_real (type, value);
  118. --- 1296,1331 ----
  119.           if (REAL_VALUES_LESS (dconst1, value)
  120.               || REAL_VALUES_LESS (value, dconstm1))
  121.             pedwarn ("floating point number exceeds range of `double'");
  122. +         exceeds_double = 1;
  123.             }
  124.   #endif
  125.   
  126.           /* Read the suffixes to choose a data type.  */
  127. !         switch (c)
  128.             {
  129. !           case 'f': case 'F':
  130. !         type = float_type_node;
  131. !         value = REAL_VALUE_TRUNCATE (TYPE_MODE (type), value);
  132. !         if (REAL_VALUE_ISINF (value) && ! exceeds_double && pedantic)
  133. !           pedwarn ("floating point number exceeds range of `float'");
  134. !         garbage_chars = -1;
  135. !         break;
  136. !           case 'l': case 'L':
  137. !         type = long_double_type_node;
  138. !         garbage_chars = -1;
  139. !         break;
  140. !           }
  141. !         while (isalnum (c))
  142. !           {
  143.           if (p >= token_buffer + maxtoken - 3)
  144.             p = extend_token_buffer (p);
  145.           *p++ = c;
  146.           c = getc (finput);
  147. +         garbage_chars++;
  148.             }
  149. +         if (garbage_chars > 0)
  150. +           error ("garbage at end of number");
  151.   
  152.           /* Create a node with determined type and value.  */
  153.           yylval.ttype = build_real (type, value);
  154. ===================================================================
  155. RCS file: cp-lex.c,v
  156. retrieving revision 2.2.2.1
  157. diff -c -r2.2.2.1 cp-lex.c
  158. *** cp-lex.c    1992/06/15 20:45:16    2.2.2.1
  159. --- cp-lex.c    1992/07/24 18:55:24
  160. ***************
  161. *** 2887,2894 ****
  162.       if (floatflag != NOT_FLOAT)
  163.         {
  164.           tree type = double_type_node;
  165. !         char f_seen = 0;
  166. !         char l_seen = 0;
  167.           REAL_VALUE_TYPE value;
  168.           jmp_buf handler;
  169.   
  170. --- 2887,2893 ----
  171.       if (floatflag != NOT_FLOAT)
  172.         {
  173.           tree type = double_type_node;
  174. !         int garbage_chars = 0, exceeds_double = 0;
  175.           REAL_VALUE_TYPE value;
  176.           jmp_buf handler;
  177.   
  178. ***************
  179. *** 2932,2985 ****
  180.           set_float_handler (0);
  181.             }
  182.   #ifdef ERANGE
  183. !         if (errno == ERANGE && !flag_traditional)
  184.             {
  185.           /* ERANGE is also reported for underflow,
  186.              so test the value to distinguish overflow from that.  */
  187. !           if (REAL_VALUES_LESS (dconst1, value)
  188. !               || REAL_VALUES_LESS (value, dconstm1))
  189. !           warning ("floating point number exceeds range of `double'");
  190.             }
  191.   #endif
  192.   
  193.           /* Read the suffixes to choose a data type.  */
  194. !         while (1)
  195.             {
  196. !         if (c == 'f' || c == 'F')
  197. !           {
  198. !             if (f_seen)
  199. !               error ("two `f's in floating constant");
  200. !             f_seen = 1;
  201. !             type = float_type_node;
  202. !             value = REAL_VALUE_TRUNCATE (TYPE_MODE (type), value);
  203. !           }
  204. !         else if (c == 'l' || c == 'L')
  205. !           {
  206. !             if (l_seen)
  207. !               error ("two `l's in floating constant");
  208. !             l_seen = 1;
  209. !             type = long_double_type_node;
  210. !           }
  211. !         else
  212. !           {
  213. !             if (isalnum (c))
  214. !               {
  215. !             error ("garbage at end of number");
  216. !             while (isalnum (c))
  217. !               {
  218. !                 if (p >= token_buffer + maxtoken - 3)
  219. !                   p = extend_token_buffer (p);
  220. !                 *p++ = c;
  221. !                 c = getch ();
  222. !               }
  223. !               }
  224. !             break;
  225. !           }
  226.           if (p >= token_buffer + maxtoken - 3)
  227.             p = extend_token_buffer (p);
  228.           *p++ = c;
  229.           c = getch ();
  230.             }
  231.   
  232.           /* Create a node with determined type and value.  */
  233.           yylval.ttype = build_real (type, value);
  234. --- 2931,2973 ----
  235.           set_float_handler (0);
  236.             }
  237.   #ifdef ERANGE
  238. !         if (errno == ERANGE && !flag_traditional && pedantic)
  239.             {
  240.           /* ERANGE is also reported for underflow,
  241.              so test the value to distinguish overflow from that.  */
  242. !         if (REAL_VALUES_LESS (dconst1, value)
  243. !             || REAL_VALUES_LESS (value, dconstm1))
  244. !           pedwarn ("floating point number exceeds range of `double'");
  245. !         exceeds_double = 1;
  246.             }
  247.   #endif
  248.   
  249.           /* Read the suffixes to choose a data type.  */
  250. !         switch (c)
  251.             {
  252. !           case 'f': case 'F':
  253. !         type = float_type_node;
  254. !         value = REAL_VALUE_TRUNCATE (TYPE_MODE (type), value);
  255. !         if (REAL_VALUE_ISINF (value) && ! exceeds_double && pedantic)
  256. !           pedwarn ("floating point number exceeds range of `float'");
  257. !         garbage_chars = -1;
  258. !         break;
  259. !           case 'l': case 'L':
  260. !         type = long_double_type_node;
  261. !         garbage_chars = -1;
  262. !         break;
  263. !           }
  264. !         while (isalnum (c))
  265. !           {
  266.           if (p >= token_buffer + maxtoken - 3)
  267.             p = extend_token_buffer (p);
  268.           *p++ = c;
  269.           c = getch ();
  270. +         garbage_chars++;
  271.             }
  272. +         if (garbage_chars > 0)
  273. +           error ("garbage at end of number");
  274.   
  275.           /* Create a node with determined type and value.  */
  276.           yylval.ttype = build_real (type, value);
  277.  
  278.