]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/c/c-typeck.c
re PR c/51849 (-Wc99-compat would be considered useful)
[gcc.git] / gcc / c / c-typeck.c
index 4deeae76a073257199a0068566ae9e5e1405cee4..0ed92c699f753feb5a6968a3dda6c051b3fc01f0 100644 (file)
@@ -40,7 +40,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "target.h"
 #include "tree-iterator.h"
 #include "bitmap.h"
-#include "pointer-set.h"
 #include "basic-block.h"
 #include "gimple-expr.h"
 #include "gimplify.h"
@@ -2511,7 +2510,7 @@ build_array_ref (location_t loc, tree array, tree index)
            return error_mark_node;
        }
 
-      if (pedantic)
+      if (pedantic || warn_c90_c99_compat)
        {
          tree foo = array;
          while (TREE_CODE (foo) == COMPONENT_REF)
@@ -2519,9 +2518,10 @@ build_array_ref (location_t loc, tree array, tree index)
          if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
            pedwarn (loc, OPT_Wpedantic,
                     "ISO C forbids subscripting %<register%> array");
-         else if (!flag_isoc99 && !lvalue_p (foo))
-           pedwarn (loc, OPT_Wpedantic,
-                    "ISO C90 forbids subscripting non-lvalue array");
+         else if (!lvalue_p (foo))
+           pedwarn_c90 (loc, OPT_Wpedantic,
+                        "ISO C90 forbids subscripting non-lvalue "
+                        "array");
        }
 
       type = TREE_TYPE (TREE_TYPE (array));
@@ -2731,6 +2731,16 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr)
   else
     {
       bool expr_const_operands = true;
+
+      if (TREE_CODE (expr.value) == PARM_DECL
+         && C_ARRAY_PARAMETER (expr.value))
+       {
+         if (warning_at (loc, OPT_Wsizeof_array_argument,
+                         "%<sizeof%> on array function parameter %qE will "
+                         "return size of %qT", expr.value,
+                         expr.original_type))
+           inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
+       }
       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
                                       &expr_const_operands);
       ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
@@ -3450,7 +3460,6 @@ pointer_diff (location_t loc, tree op0, tree op1)
   addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
   addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
   tree target_type = TREE_TYPE (TREE_TYPE (op0));
-  tree con0, con1, lit0, lit1;
   tree orig_op1 = op1;
 
   /* If the operands point into different address spaces, we need to
@@ -3480,7 +3489,6 @@ pointer_diff (location_t loc, tree op0, tree op1)
   else
     inttype = restype;
 
-
   if (TREE_CODE (target_type) == VOID_TYPE)
     pedwarn (loc, OPT_Wpointer_arith,
             "pointer of type %<void *%> used in subtraction");
@@ -3488,50 +3496,6 @@ pointer_diff (location_t loc, tree op0, tree op1)
     pedwarn (loc, OPT_Wpointer_arith,
             "pointer to a function used in subtraction");
 
-  /* If the conversion to ptrdiff_type does anything like widening or
-     converting a partial to an integral mode, we get a convert_expression
-     that is in the way to do any simplifications.
-     (fold-const.c doesn't know that the extra bits won't be needed.
-     split_tree uses STRIP_SIGN_NOPS, which leaves conversions to a
-     different mode in place.)
-     So first try to find a common term here 'by hand'; we want to cover
-     at least the cases that occur in legal static initializers.  */
-  if (CONVERT_EXPR_P (op0)
-      && (TYPE_PRECISION (TREE_TYPE (op0))
-         == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))))
-    con0 = TREE_OPERAND (op0, 0);
-  else
-    con0 = op0;
-  if (CONVERT_EXPR_P (op1)
-      && (TYPE_PRECISION (TREE_TYPE (op1))
-         == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))))
-    con1 = TREE_OPERAND (op1, 0);
-  else
-    con1 = op1;
-
-  if (TREE_CODE (con0) == POINTER_PLUS_EXPR)
-    {
-      lit0 = TREE_OPERAND (con0, 1);
-      con0 = TREE_OPERAND (con0, 0);
-    }
-  else
-    lit0 = integer_zero_node;
-
-  if (TREE_CODE (con1) == POINTER_PLUS_EXPR)
-    {
-      lit1 = TREE_OPERAND (con1, 1);
-      con1 = TREE_OPERAND (con1, 0);
-    }
-  else
-    lit1 = integer_zero_node;
-
-  if (operand_equal_p (con0, con1, 0))
-    {
-      op0 = lit0;
-      op1 = lit1;
-    }
-
-
   /* First do the subtraction as integers;
      then drop through to build the divide operator.
      Do not do default conversions on the minus operator
@@ -6189,7 +6153,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
       else
        /* Avoid warning about the volatile ObjC EH puts on decls.  */
        if (!objc_ok)
-         WARN_FOR_ASSIGNMENT (location, expr_loc, 0,
+         WARN_FOR_ASSIGNMENT (location, expr_loc,
+                              OPT_Wincompatible_pointer_types,
                               G_("passing argument %d of %qE from "
                                  "incompatible pointer type"),
                               G_("assignment from incompatible pointer type"),
@@ -6212,7 +6177,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
         or one that results from arithmetic, even including
         a cast to integer type.  */
       if (!null_pointer_constant)
-       WARN_FOR_ASSIGNMENT (location, expr_loc, 0,
+       WARN_FOR_ASSIGNMENT (location, expr_loc,
+                            OPT_Wint_conversion,
                             G_("passing argument %d of %qE makes "
                                "pointer from integer without a cast"),
                             G_("assignment makes pointer from integer "
@@ -6226,7 +6192,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
     }
   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
     {
-      WARN_FOR_ASSIGNMENT (location, expr_loc, 0,
+      WARN_FOR_ASSIGNMENT (location, expr_loc,
+                          OPT_Wint_conversion,
                           G_("passing argument %d of %qE makes integer "
                              "from pointer without a cast"),
                           G_("assignment makes integer from pointer "
@@ -6943,6 +6910,7 @@ struct constructor_stack
   char outer;
   char incremental;
   char designated;
+  int designator_depth;
 };
 
 static struct constructor_stack *constructor_stack;
@@ -7114,6 +7082,7 @@ really_start_incremental_init (tree type)
   p->outer = 0;
   p->incremental = constructor_incremental;
   p->designated = constructor_designated;
+  p->designator_depth = designator_depth;
   p->next = 0;
   constructor_stack = p;
 
@@ -7263,6 +7232,7 @@ push_init_level (location_t loc, int implicit,
   p->outer = 0;
   p->incremental = constructor_incremental;
   p->designated = constructor_designated;
+  p->designator_depth = designator_depth;
   p->next = constructor_stack;
   p->range_stack = 0;
   constructor_stack = p;
@@ -7570,6 +7540,7 @@ pop_init_level (location_t loc, int implicit,
   constructor_erroneous = p->erroneous;
   constructor_incremental = p->incremental;
   constructor_designated = p->designated;
+  designator_depth = p->designator_depth;
   constructor_pending_elts = p->pending_elts;
   constructor_depth = p->depth;
   if (!p->implicit)
@@ -8639,6 +8610,15 @@ process_init_element (location_t loc, struct c_expr value, bool implicit,
   if (constructor_type == 0)
     return;
 
+  if (!implicit && warn_designated_init && !was_designated
+      && TREE_CODE (constructor_type) == RECORD_TYPE
+      && lookup_attribute ("designated_init",
+                          TYPE_ATTRIBUTES (constructor_type)))
+    warning_init (loc,
+                 OPT_Wdesignated_init,
+                 "positional initialization of field "
+                 "in %<struct%> declared with %<designated_init%> attribute");
+
   /* If we've exhausted any levels that didn't have braces,
      pop them now.  */
   while (constructor_stack->implicit)
@@ -9185,7 +9165,8 @@ c_finish_goto_ptr (location_t loc, tree expr)
 
 /* Generate a C `return' statement.  RETVAL is the expression for what
    to return, or a null pointer for `return;' with no value.  LOC is
-   the location of the return statement.  If ORIGTYPE is not NULL_TREE, it
+   the location of the return statement, or the location of the expression,
+   if the statement has any.  If ORIGTYPE is not NULL_TREE, it
    is the original type of RETVAL.  */
 
 tree
@@ -9323,8 +9304,12 @@ c_finish_return (location_t loc, tree retval, tree origtype)
                    warning_at (loc, OPT_Wreturn_local_addr,
                                "function returns address of label");
                  else
-                   warning_at (loc, OPT_Wreturn_local_addr,
-                               "function returns address of local variable");
+                   {
+                     warning_at (loc, OPT_Wreturn_local_addr,
+                                 "function returns address of local variable");
+                     tree zero = build_zero_cst (TREE_TYPE (res));
+                     t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero);
+                   }
                }
              break;
 
@@ -11769,15 +11754,15 @@ c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
                 tree decl, tree placeholder)
 {
   copy_body_data id;
-  struct pointer_map_t *decl_map = pointer_map_create ();
+  hash_map<tree, tree> decl_map;
 
-  *pointer_map_insert (decl_map, omp_decl1) = placeholder;
-  *pointer_map_insert (decl_map, omp_decl2) = decl;
+  decl_map.put (omp_decl1, placeholder);
+  decl_map.put (omp_decl2, decl);
   memset (&id, 0, sizeof (id));
   id.src_fn = DECL_CONTEXT (omp_decl1);
   id.dst_fn = current_function_decl;
   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
-  id.decl_map = decl_map;
+  id.decl_map = &decl_map;
 
   id.copy_decl = copy_decl_no_change;
   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
@@ -11786,7 +11771,6 @@ c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
   id.transform_lang_insert_block = NULL;
   id.eh_lp_nr = 0;
   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
-  pointer_map_destroy (decl_map);
   return stmt;
 }
 
This page took 0.041699 seconds and 5 git commands to generate.