OSDN Git Service

PR target/33042
[pf3gnuchains/gcc-fork.git] / libcpp / expr.c
index a61ff66..f20d50c 100644 (file)
@@ -82,26 +82,41 @@ static void check_promotion (cpp_reader *, const struct op *);
 static unsigned int
 interpret_float_suffix (const uchar *s, size_t len)
 {
-  size_t f = 0, l = 0, i = 0, d = 0;
+  size_t f, l, w, q, i, d;
+
+  f = l = w = q = i = d = 0;
 
   while (len--)
     switch (s[len])
       {
-      case 'f': case 'F': f++; break;
-      case 'l': case 'L': l++; break;
-      case 'i': case 'I':
-      case 'j': case 'J': i++; break;
-      case 'd': case 'D': 
-       /* Disallow fd, ld suffixes.  */
-       if (d && (f || l))
+      case 'f': case 'F':
+       if (d > 0)
+         return 0;
+       f++;
+       break;
+      case 'l': case 'L':
+       if (d > 0)
          return 0;
-       d++;
+       l++;
        break;
+      case 'w': case 'W':
+       if (d > 0)
+         return 0;
+       w++;
+       break;
+      case 'q': case 'Q':
+       if (d > 0)
+         return 0;
+       q++;
+       break;
+      case 'i': case 'I':
+      case 'j': case 'J': i++; break;
+      case 'd': case 'D': d++; break;
       default:
        return 0;
       }
 
-  if (f + l > 1 || i > 1)
+  if (f + l + w + q > 1 || i > 1)
     return 0;
 
   /* Allow dd, df, dl suffixes for decimal float constants.  */
@@ -110,7 +125,9 @@ interpret_float_suffix (const uchar *s, size_t len)
 
   return ((i ? CPP_N_IMAGINARY : 0)
          | (f ? CPP_N_SMALL :
-            l ? CPP_N_LARGE : CPP_N_MEDIUM)
+            l ? CPP_N_LARGE :
+            w ? CPP_N_MD_W :
+            q ? CPP_N_MD_Q : CPP_N_MEDIUM)
          | (d ? CPP_N_DFLOAT : 0));
 }
 
@@ -182,6 +199,11 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
          radix = 16;
          str++;
        }
+      else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
+       {
+         radix = 2;
+         str++;
+       }
     }
 
   /* Now scan for a well-formed integer or float.  */
@@ -220,10 +242,22 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
     radix = 10;
 
   if (max_digit >= radix)
-    SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
+    {
+      if (radix == 2)
+       SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
+      else
+       SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
+    }
 
   if (float_flag != NOT_FLOAT)
     {
+      if (radix == 2)
+       {
+         cpp_error (pfile, CPP_DL_ERROR,
+                    "invalid prefix \"0b\" for floating constant");
+         return CPP_N_INVALID;
+       }
+
       if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
        cpp_error (pfile, CPP_DL_PEDWARN,
                   "use of C99 hexadecimal floating constant");
@@ -270,6 +304,10 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
           return CPP_N_INVALID;
         }
 
+      if ((result & CPP_N_DFLOAT) && CPP_PEDANTIC (pfile))
+       cpp_error (pfile, CPP_DL_PEDWARN,
+                  "decimal float constants are a GCC extension");
+
       result |= CPP_N_FLOATING;
     }
   else
@@ -308,11 +346,16 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
   if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
     cpp_error (pfile, CPP_DL_PEDWARN,
               "imaginary constants are a GCC extension");
+  if (radix == 2 && CPP_PEDANTIC (pfile))
+    cpp_error (pfile, CPP_DL_PEDWARN,
+              "binary constants are a GCC extension");
 
   if (radix == 10)
     result |= CPP_N_DECIMAL;
   else if (radix == 16)
     result |= CPP_N_HEX;
+  else if (radix == 2)
+    result |= CPP_N_BINARY;
   else
     result |= CPP_N_OCTAL;
 
@@ -363,6 +406,11 @@ cpp_interpret_integer (cpp_reader *pfile, const cpp_token *token,
          base = 16;
          p += 2;
        }
+      else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
+       {
+         base = 2;
+         p += 2;
+       }
 
       /* We can add a digit to numbers strictly less than this without
         needing the precision and slowness of double integers.  */
@@ -418,12 +466,25 @@ static cpp_num
 append_digit (cpp_num num, int digit, int base, size_t precision)
 {
   cpp_num result;
-  unsigned int shift = 3 + (base == 16);
+  unsigned int shift;
   bool overflow;
   cpp_num_part add_high, add_low;
 
-  /* Multiply by 8 or 16.  Catching this overflow here means we don't
+  /* Multiply by 2, 8 or 16.  Catching this overflow here means we don't
      need to worry about add_high overflowing.  */
+  switch (base)
+    {
+    case 2:
+      shift = 1;
+      break;
+
+    case 16:
+      shift = 4;
+      break;
+
+    default:
+      shift = 3;
+    }
   overflow = !!(num.high >> (PART_PRECISION - shift));
   result.high = num.high << shift;
   result.low = num.low << shift;
@@ -441,7 +502,7 @@ append_digit (cpp_num num, int digit, int base, size_t precision)
   if (add_low + digit < add_low)
     add_high++;
   add_low += digit;
-    
+
   if (result.low + add_low < result.low)
     add_high++;
   if (result.high + add_high < result.high)
@@ -668,9 +729,6 @@ static const struct cpp_operator
   /* RSHIFT */         {13, LEFT_ASSOC},
   /* LSHIFT */         {13, LEFT_ASSOC},
 
-  /* MIN */            {10, LEFT_ASSOC | CHECK_PROMOTION},
-  /* MAX */            {10, LEFT_ASSOC | CHECK_PROMOTION},
-
   /* COMPL */          {16, NO_L_OPERAND},
   /* AND_AND */                {6, LEFT_ASSOC},
   /* OR_OR */          {5, LEFT_ASSOC},
@@ -882,8 +940,6 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
        case CPP_MINUS:
        case CPP_RSHIFT:
        case CPP_LSHIFT:
-       case CPP_MIN:
-       case CPP_MAX:
        case CPP_COMMA:
          top[-1].value = num_binary_op (pfile, top[-1].value,
                                         top->value, top->op);
@@ -1309,7 +1365,6 @@ num_binary_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
 {
   cpp_num result;
   size_t precision = CPP_OPTION (pfile, precision);
-  bool gte;
   size_t n;
 
   switch (op)
@@ -1336,21 +1391,6 @@ num_binary_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
        lhs = num_rshift (lhs, precision, n);
       break;
 
-      /* Min / Max.  */
-    case CPP_MIN:
-    case CPP_MAX:
-      {
-       bool unsignedp = lhs.unsignedp || rhs.unsignedp;
-
-       gte = num_greater_eq (lhs, rhs, precision);
-       if (op == CPP_MIN)
-         gte = !gte;
-       if (!gte)
-         lhs = rhs;
-       lhs.unsignedp = unsignedp;
-      }
-      break;
-
       /* Arithmetic.  */
     case CPP_MINUS:
       rhs = num_negate (rhs, precision);
@@ -1548,7 +1588,8 @@ num_div_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
        {
          if (negate)
            result = num_negate (result, precision);
-         result.overflow = num_positive (result, precision) ^ !negate;
+         result.overflow = (num_positive (result, precision) ^ !negate
+                            && !num_zerop (result));
        }
 
       return result;