OSDN Git Service

(parse_number): Warn about '9' in octal constants.
authorrms <rms@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Sep 1992 02:46:36 +0000 (02:46 +0000)
committerrms <rms@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Sep 1992 02:46:36 +0000 (02:46 +0000)
Commonize overflow detection for various radices.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@2139 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cexp.y

index 4cb3674..c0fbca5 100644 (file)
@@ -347,6 +347,7 @@ parse_number (olen)
   register int base = 10;
   register int len = olen;
   register int overflow = 0;
   register int base = 10;
   register int len = olen;
   register int overflow = 0;
+  register int digit, largest_digit = 0;
   int spec_long = 0;
 
   for (c = 0; c < len; c++)
   int spec_long = 0;
 
   for (c = 0; c < len; c++)
@@ -370,19 +371,14 @@ parse_number (olen)
 
   for (; len > 0; len--) {
     c = *p++;
 
   for (; len > 0; len--) {
     c = *p++;
-    if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
-
-    if (c >= '0' && c <= '9') {
-      overflow |= ULONG_MAX_over_base < n;
-      nd = n * base + c - '0';
-      overflow |= nd < n;
-      n = nd;
-    } else if (base == 16 && c >= 'a' && c <= 'f') {
-      overflow |= ULONG_MAX_over_base < n;
-      nd = n * 16 + c - 'a' + 10;
-      overflow |= nd < n;
-      n = nd;
-    } else {
+
+    if (c >= '0' && c <= '9')
+      digit = c - '0';
+    else if (base == 16 && c >= 'a' && c <= 'f')
+      digit = c - 'a' + 10;
+    else if (base == 16 && c >= 'A' && c <= 'F')
+      digit = c - 'A' + 10;
+    else {
       /* `l' means long, and `u' means unsigned.  */
       while (1) {
        if (c == 'l' || c == 'L')
       /* `l' means long, and `u' means unsigned.  */
       while (1) {
        if (c == 'l' || c == 'L')
@@ -407,6 +403,11 @@ parse_number (olen)
       /* Don't look for any more digits after the suffixes.  */
       break;
     }
       /* Don't look for any more digits after the suffixes.  */
       break;
     }
+    if (largest_digit < digit)
+      largest_digit = digit;
+    nd = n * base + digit;
+    overflow |= ULONG_MAX_over_base < n | nd < n;
+    n = nd;
   }
 
   if (len != 0) {
   }
 
   if (len != 0) {
@@ -414,6 +415,9 @@ parse_number (olen)
     return ERROR;
   }
 
     return ERROR;
   }
 
+  if (base <= largest_digit)
+    warning ("integer constant contains digits beyond the radix");
+
   if (overflow)
     warning ("integer constant out of range");
 
   if (overflow)
     warning ("integer constant out of range");