OSDN Git Service

(output_toc): Align DF constants if STRICT_ALIGNMENT.
[pf3gnuchains/gcc-fork.git] / gcc / c-typeck.c
index 30d6679..75df083 100644 (file)
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 /* This file is part of the C front end.
@@ -758,6 +759,14 @@ unsigned_type (type)
     return long_unsigned_type_node;
   if (type1 == long_long_integer_type_node)
     return long_long_unsigned_type_node;
+  if (type1 == intDI_type_node)
+    return unsigned_intDI_type_node;
+  if (type1 == intSI_type_node)
+    return unsigned_intSI_type_node;
+  if (type1 == intHI_type_node)
+    return unsigned_intHI_type_node;
+  if (type1 == intQI_type_node)
+    return unsigned_intQI_type_node;
   return type;
 }
 
@@ -778,6 +787,14 @@ signed_type (type)
     return long_integer_type_node;
   if (type1 == long_long_unsigned_type_node)
     return long_long_integer_type_node;
+  if (type1 == unsigned_intDI_type_node)
+    return intDI_type_node;
+  if (type1 == unsigned_intSI_type_node)
+    return intSI_type_node;
+  if (type1 == unsigned_intHI_type_node)
+    return intHI_type_node;
+  if (type1 == unsigned_intQI_type_node)
+    return intQI_type_node;
   return type;
 }
 
@@ -1137,8 +1154,6 @@ lookup_field (type, component, indirect)
       top = TYPE_LANG_SPECIFIC (type)->len;
       while (top - bot > 1)
        {
-         HOST_WIDE_INT cmp;
-
          half = (top - bot + 1) >> 1;
          field = field_array[bot+half];
 
@@ -1166,10 +1181,9 @@ lookup_field (type, component, indirect)
              continue;
            }
 
-         cmp = (HOST_WIDE_INT) DECL_NAME (field) - (HOST_WIDE_INT) component;
-         if (cmp == 0)
+         if (DECL_NAME (field) == component)
            break;
-         if (cmp < 0)
+         if (DECL_NAME (field) < component)
            bot += half;
          else
            top = bot + half;
@@ -2281,7 +2295,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
               && integer_zerop (op1))
        {
          result_type = type0;
-         if (pedantic)
+         if (pedantic || extra_warnings)
            pedwarn ("ordered comparison of pointer with integer zero");
        }
       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
@@ -2453,6 +2467,10 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
              int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
              int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
 
+             int unsignedp0, unsignedp1;
+             tree primop0 = get_narrower (op0, &unsignedp0);
+             tree primop1 = get_narrower (op1, &unsignedp1);
+
              /* Avoid spurious warnings for comparison with enumerators.  */
  
              xop0 = orig_op0;
@@ -2492,6 +2510,61 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
                /* OK */;
              else
                warning ("comparison between signed and unsigned");
+
+             /* Warn if two unsigned values are being compared in a size
+                larger than their original size, and one (and only one) is the
+                result of a `~' operator.  This comparison will always fail.
+
+                Also warn if one operand is a constant, and the constant
+                does not have all bits set that are set in the ~ operand
+                when it is extended.  */
+
+             if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
+                 != (TREE_CODE (primop1) == BIT_NOT_EXPR))
+               {
+                 if (TREE_CODE (primop0) == BIT_NOT_EXPR)
+                   primop0 = get_narrower (TREE_OPERAND (primop0, 0),
+                                           &unsignedp0);
+                 else
+                   primop1 = get_narrower (TREE_OPERAND (primop1, 0),
+                                           &unsignedp1);
+             
+                 if (TREE_CODE (primop0) == INTEGER_CST
+                     || TREE_CODE (primop1) == INTEGER_CST)
+                   {
+                     tree primop;
+                     long constant, mask;
+                     int unsignedp, bits;
+
+                     if (TREE_CODE (primop0) == INTEGER_CST)
+                       {
+                         primop = primop1;
+                         unsignedp = unsignedp1;
+                         constant = TREE_INT_CST_LOW (primop0);
+                       }
+                     else
+                       {
+                         primop = primop0;
+                         unsignedp = unsignedp0;
+                         constant = TREE_INT_CST_LOW (primop1);
+                       }
+
+                     bits = TYPE_PRECISION (TREE_TYPE (primop));
+                     if (bits < TYPE_PRECISION (result_type)
+                         && bits < HOST_BITS_PER_LONG && unsignedp)
+                       {
+                         mask = (~0L) << bits;
+                         if ((mask & constant) != mask)
+                           warning ("comparison of promoted ~unsigned with constant");
+                       }
+                   }
+                 else if (unsignedp0 && unsignedp1
+                          && (TYPE_PRECISION (TREE_TYPE (primop0))
+                              < TYPE_PRECISION (result_type))
+                          && (TYPE_PRECISION (TREE_TYPE (primop1))
+                              < TYPE_PRECISION (result_type)))
+                   warning ("comparison of promoted ~unsigned with unsigned");
+               }
            }
        }
     }
@@ -2575,7 +2648,13 @@ pointer_int_sum (resultcode, ptrop, intop)
       && TREE_CONSTANT (size_exp)
       /* If the constant comes from pointer subtraction,
         skip this optimization--it would cause an error.  */
-      && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE)
+      && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
+      /* If the constant is unsigned, and smaller than the pointer size,
+        then we must skip this optimization.  This is because it could cause
+        an overflow error if the constant is negative but INTOP is not.  */
+      && (! TREE_UNSIGNED (TREE_TYPE (intop))
+         || (TYPE_PRECISION (TREE_TYPE (intop))
+             == TYPE_PRECISION (TREE_TYPE (ptrop)))))
     {
       enum tree_code subcode = resultcode;
       tree int_type = TREE_TYPE (intop);
@@ -4052,7 +4131,8 @@ convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
                warn_for_assignment ("pointer targets in %s differ in signedness",
                                     get_spelling (errtype), funname, parmnum);
            }
-         else
+         else if (TREE_CODE (ttl) == FUNCTION_TYPE
+                  && TREE_CODE (ttr) == FUNCTION_TYPE)
            {
              /* Because const and volatile on functions are restrictions
                 that say the function will not do certain things,
@@ -4179,7 +4259,8 @@ initializer_constant_valid_p (value, endtype)
   switch (TREE_CODE (value))
     {
     case CONSTRUCTOR:
-      if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
+      if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
+          || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
          && TREE_CONSTANT (value))
        return
          initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
@@ -4813,7 +4894,7 @@ digest_init (type, init, require_constant, constructor_constant)
      and it initializes the first element of x to 0.  */
   if (flag_traditional)
     {
-      tree top = 0, prev = 0;
+      tree top = 0, prev = 0, otype = type;
       while (TREE_CODE (type) == RECORD_TYPE
             || TREE_CODE (type) == ARRAY_TYPE
             || TREE_CODE (type) == QUAL_UNION_TYPE
@@ -4835,11 +4916,17 @@ digest_init (type, init, require_constant, constructor_constant)
              return error_mark_node;
            }
        }
-      TREE_OPERAND (prev, 1)
-       = build_tree_list (NULL_TREE,
-                          digest_init (type, init, require_constant,
-                                       constructor_constant));
-      return top;
+
+      if (otype != type)
+       {
+         TREE_OPERAND (prev, 1)
+           = build_tree_list (NULL_TREE,
+                              digest_init (type, init, require_constant,
+                                           constructor_constant));
+         return top;
+       }
+      else
+       return error_mark_node;
     }
   error_init ("invalid initializer%s", " for `%s'", NULL);
   return error_mark_node;
@@ -4861,7 +4948,7 @@ static tree constructor_fields;
 static tree constructor_index;
 
 /* For an ARRAY_TYPE, this is the end index of the range
-   to intitialize with the next element, or NULL in the ordinary case
+   to initialize with the next element, or NULL in the ordinary case
    where the element is used just once.  */
 static tree constructor_range_end;
 
@@ -5150,7 +5237,7 @@ really_start_incremental_init (type)
       || TREE_CODE (constructor_type) == UNION_TYPE)
     {
       constructor_fields = TYPE_FIELDS (constructor_type);
-      /* Skip any nameless bit fields atthe beginning.  */
+      /* Skip any nameless bit fields at the beginning.  */
       while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
             && DECL_NAME (constructor_fields) == 0)
        constructor_fields = TREE_CHAIN (constructor_fields);
@@ -5322,7 +5409,7 @@ push_init_level (implicit)
           || TREE_CODE (constructor_type) == UNION_TYPE)
     {
       constructor_fields = TYPE_FIELDS (constructor_type);
-      /* Skip any nameless bit fields atthe beginning.  */
+      /* Skip any nameless bit fields at the beginning.  */
       while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
             && DECL_NAME (constructor_fields) == 0)
        constructor_fields = TREE_CHAIN (constructor_fields);
@@ -5436,7 +5523,8 @@ pop_init_level (implicit)
          && constructor_incremental)
        {
          constructor = digest_init (constructor_type, constructor,
-                                    0, 0);
+                                    require_constant_value,
+                                    require_constant_elements);
 
          /* If initializing an array of unknown size,
             determine the size now.  */
@@ -5655,6 +5743,11 @@ set_init_label (fieldname)
   tree tail;
   int passed = 0;
 
+  /* Don't die if an entire brace-pair level is superfluous
+     in the containing level.  */
+  if (constructor_type == 0)
+    return;
+
   for (tail = TYPE_FIELDS (constructor_type); tail;
        tail = TREE_CHAIN (tail))
     {
@@ -5771,7 +5864,8 @@ output_init_element (value, type, field, pending)
           constructor_index, which is modified in place.  */
        constructor_pending_elts
          = tree_cons (copy_node (field),
-                      digest_init (type, value, 0, 0),
+                      digest_init (type, value, require_constant_value, 
+                                   require_constant_elements),
                       constructor_pending_elts);
     }
   else if (TREE_CODE (constructor_type) == RECORD_TYPE
@@ -5783,7 +5877,8 @@ output_init_element (value, type, field, pending)
       if (!duplicate)
        constructor_pending_elts
          = tree_cons (field,
-                      digest_init (type, value, 0, 0),
+                      digest_init (type, value, require_constant_value, 
+                                   require_constant_elements),
                       constructor_pending_elts);
     }
   else
@@ -5798,7 +5893,9 @@ output_init_element (value, type, field, pending)
              if (field && TREE_CODE (field) == INTEGER_CST)
                field = copy_node (field);
              constructor_elements
-               = tree_cons (field, digest_init (type, value, 0, 0),
+               = tree_cons (field, digest_init (type, value,
+                                                require_constant_value, 
+                                                require_constant_elements),
                             constructor_elements);
            }
          else
@@ -5819,7 +5916,9 @@ output_init_element (value, type, field, pending)
                      assemble_zeros (next - here);
                    }
                }
-             output_constant (digest_init (type, value, 0, 0),
+             output_constant (digest_init (type, value,
+                                           require_constant_value,
+                                           require_constant_elements),
                               int_size_in_bytes (type));
 
              /* For a record or union,
@@ -6128,7 +6227,7 @@ process_init_element (value)
            }
 
          constructor_fields = TREE_CHAIN (constructor_fields);
-         /* Skip any nameless bit fields atthe beginning.  */
+         /* Skip any nameless bit fields at the beginning.  */
          while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
                 && DECL_NAME (constructor_fields) == 0)
            constructor_fields = TREE_CHAIN (constructor_fields);
@@ -6281,7 +6380,8 @@ process_init_element (value)
 
   /* If the (lexically) previous elments are not now saved,
      we can discard the storage for them.  */
-  if (constructor_incremental && constructor_pending_elts == 0 && value != 0)
+  if (constructor_incremental && constructor_pending_elts == 0 && value != 0
+      && constructor_stack == 0)
     clear_momentary ();
 }
 \f
@@ -6343,7 +6443,8 @@ c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
       else
        {
          tree type = TREE_TYPE (o[i]);
-         if (TYPE_READONLY (type)
+         if (TREE_READONLY (o[i])
+             || TYPE_READONLY (type)
              || ((TREE_CODE (type) == RECORD_TYPE
                   || TREE_CODE (type) == UNION_TYPE)
                  && C_TYPE_FIELDS_READONLY (type)))