This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] handle attribute positional arguments consistently (PR 87541, 87542)


While still testing an enhancement in the area of attributes
I ran across bugs and inconsistencies in how different handlers
deal with positional arguments.  The bugs are either an ICE due
to the handlers not consistently converting positional arguments
to constants (i.e., CONST_DEL to INTEGER_CST in C++) for which
downstream code is unprepared (PR 87541), or errors for valid
code (PR 87542), or failing to diagnose invalid arguments.
The other inconsistencies are simply in responding to the same
invalid condition differently for different attributes .

The attached patch introduces a new function to do validate
positional arguments in a uniform way and replaces the existing
handling with it.

As a consequence of the handling being made consistent a number
of tests needed adjusting. In addition, some invalid arguments
that were previously rejected with a hard error are diagnosed
with just a warning (invalid argument values in attribute format),
and in one other instance what previously triggered a warning is
now accepted without one (attribute alloc_size on a function
without a prototype).  I'd be up tightening things up if that's
preferable as long it's done consistently.

Tested on x86_64-linux.

Martin

PS It would be nice to have a general policy for how to respond
to invalid attribute arguments (warning or error).  Even better,
it would be ideal to move the validation from the front-ends and
back-ends into the middle-end.  I.e., describe attribute arguments
in more detail in struct attribute_spec and have decl_attributes
validate nut just the number of arguments but also their types
and, when appropriate, expected values.
PR c++/87541 - ICE using a constant decl as an attribute alloc_size argument

gcc/ChangeLog:

	PR c++/87541
	* tree.c (type_argument_type): New function.
	* tree.h (type_argument_type): Declare it.

gcc/c-family/ChangeLog:

	PR c++/87541
	* c-attribs.c (positional_argument): New function.
	(handle_alloc_size_attribute): Use it and simplify.
	(handle_alloc_align_attribute): Same.
	(handle_assume_aligned_attribute): Same.
	(handle_nonnull_attribute): Same.
	* c-common.c (check_function_arguments): Pass fntype to
	check_function_format.
	* c-common.h (check_function_format): Add an argument.
	(PosArgFlags, positional_argument): Declare new type and function.
	* c-format.c (decode_format_attr): Add arguments.
	(check_format_string, get_constant): Same.
	(convert_format_name_to_system_name): Adjust.

gcc/testsuite/ChangeLog:

	PR c++/87541
	* g++.dg/ext/attr-alloc_size.C: New test.
	* c-c++-common/pr71574.c: Adjust diagnostics.
	* c-c++-common/attributes-1.c: Same.
	* gcc.dg/attr-alloc_align-2.c: Same.
	* gcc.dg/attr-alloc_align-4.c: New test.
	* gcc.dg/attr-alloc_size-2.c: Adjust diagnostics.
	* gcc.dg/attr-alloc_size.c: Same.
	* gcc.dg/attr-assume_aligned-4.c: New test.
	* gcc.dg/format/attr-3.c: Adjust diagnostics.
	* gcc.dg/nonnull-2.c: Same.

Index: gcc/c-family/c-attribs.c
===================================================================
--- gcc/c-family/c-attribs.c	(revision 264901)
+++ gcc/c-family/c-attribs.c	(working copy)
@@ -44,6 +44,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-iterator.h"
 #include "opts.h"
 #include "gimplify.h"
+#include "tree-pretty-print.h"
 
 static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
@@ -492,6 +493,170 @@ attribute_takes_identifier_p (const_tree attr_id)
     return targetm.attribute_takes_identifier_p (attr_id);
 }
 
+/* Verify that argument value POS at position ARGNO to attribute NAME
+   applied to function TYPE refers to a function parameter at position
+   POS and the expected type CODE.  If so, return POS after default
+   conversions, if any.  Otherwise, issue appropriate warnings and
+   return null.  A non-zero 1-based ARGNO should be passed ib by
+   callers only for attributes with more than one argument.  */
+
+tree
+positional_argument (const_tree fntype, const_tree atname, tree pos,
+		     tree_code code, int argno /* = 0 */,
+		     int flags /* = PosArgFlags () */)
+{
+  if (pos && TREE_CODE (pos) != IDENTIFIER_NODE
+      && TREE_CODE (pos) != FUNCTION_DECL)
+    pos = default_conversion (pos);
+
+  pretty_printer posval;
+  if (pos != error_mark_node)
+    {
+      /* Only format the position value when it's valid.  By convention
+	 do not quote constant integers.  */
+      pp_space (&posval);
+      if (TREE_CODE (pos) != INTEGER_CST)
+	pp_begin_quote (&posval, pp_show_color (global_dc->printer));
+      dump_generic_node (&posval, pos, 0, TDF_NONE, false);
+      if (TREE_CODE (pos) != INTEGER_CST)
+	pp_end_quote (&posval, pp_show_color (global_dc->printer));
+    }
+
+  if (TREE_CODE (pos) != INTEGER_CST)
+    {
+      /* Only mention the argument number when it's non-zero.  */
+      if (argno < 1)
+	warning (OPT_Wattributes,
+		 "%qE attribute argument value%s is not an integer "
+		 "constant",
+		 atname, pp_formatted_text (&posval));
+      else
+	warning (OPT_Wattributes,
+		 "%qE attribute argument %i value%s is not an integer "
+		 "constant",
+		 atname, argno, pp_formatted_text (&posval));
+	
+      return NULL_TREE;
+    }
+
+  /* Argument positions are 1-based.  */
+  if (integer_zerop (pos))
+    {
+      if (flags & posarg_zero)
+	/* Zero is explicitly allowed.  */
+	return pos;
+
+      if (argno < 1)
+	warning (OPT_Wattributes,
+		 "%qE attribute argument value%s does not refer to "
+		 "a function parameter",
+		 atname, pp_formatted_text (&posval));
+      else
+	warning (OPT_Wattributes,
+		 "%qE attribute argument %i value%s does not refer to "
+		 "a function parameter",
+		 atname, argno, pp_formatted_text (&posval));
+	
+      return NULL_TREE;
+    }
+
+  if (!prototype_p (fntype))
+    return pos;
+
+  /* Verify that the argument position does not exceed the number
+     of formal arguments to the function.  When POSARG_ELLIPSIS
+     is set, ARGNO may be beyond the last argument of a vararg
+     function.  */
+  unsigned nargs = type_num_arguments (fntype);
+  if (!nargs
+      || !tree_fits_uhwi_p (pos)
+      || ((flags & posarg_ellipsis) == 0
+	  && !IN_RANGE (tree_to_uhwi (pos), 1, nargs)))
+    {
+
+      if (argno < 1)
+	warning (OPT_Wattributes,
+		 "%qE attribute argument value%s exceeds the number "
+		 "of function parameters %u",
+		 atname, pp_formatted_text (&posval), nargs);
+      else
+	warning (OPT_Wattributes,
+		 "%qE attribute argument %i value%s exceeds the number "
+		 "of function parameters %u",
+		 atname, argno, pp_formatted_text (&posval), nargs);
+      return NULL_TREE;
+    }
+
+  /* Verify that the type of the referenced formal argument matches
+     the expected type.  */
+  unsigned HOST_WIDE_INT ipos = tree_to_uhwi (pos);
+
+  /* Zero was handled above.  */
+  gcc_assert (ipos != 0);
+
+  if (tree argtype = type_argument_type (fntype, ipos))
+    {
+      if (flags & posarg_ellipsis)
+	{
+	  if (argno < 1)
+	    error ("%qE attribute argument value%s does not refer to "
+		   "a variable argument list",
+		   atname, pp_formatted_text (&posval));
+	  else
+	    error ("%qE attribute argument %i value%s does not refer to "
+		   "a variable argument list",
+		   atname, argno, pp_formatted_text (&posval));
+	  return NULL_TREE;
+	}
+
+      /* Where the expected code is STRING_CST accept any pointer
+	 to a narrow character type, qualified or otherwise.  */
+      bool type_match;
+      if (code == STRING_CST && POINTER_TYPE_P (argtype))
+	{
+	  tree type = TREE_TYPE (argtype);
+	  type = TYPE_MAIN_VARIANT (type);
+	  type_match = (type == char_type_node
+			|| type == signed_char_type_node
+			|| type == unsigned_char_type_node);
+	}
+      else
+	type_match = TREE_CODE (argtype) == code;
+
+      if (!type_match)
+	{
+	  if (argno < 1)
+	    warning (OPT_Wattributes,
+		     "%qE attribute argument value%s refers to "
+		     "parameter type %qT",
+		     atname, pp_formatted_text (&posval), argtype);
+	  else
+	    warning (OPT_Wattributes,
+		   "%qE attribute argument %i value%s refers to "
+		     "parameter type %qT",
+		     atname, argno, pp_formatted_text (&posval), argtype);
+	  return NULL_TREE;
+	}
+    }
+  else if (!(flags & posarg_ellipsis))
+    {
+      if (argno < 1)
+	warning (OPT_Wattributes,
+		 "%qE attribute argument value%s refers to "
+		 "a variadic function parameter of unknown type",
+		 atname, pp_formatted_text (&posval));
+      else
+	warning (OPT_Wattributes,
+		 "%qE attribute argument %i value%s refers to "
+		 "a variadic function parameter of unknown type",
+		 atname, argno, pp_formatted_text (&posval));
+      return NULL_TREE;
+    }
+
+  return pos;
+}
+
+
 /* Attribute handlers common to C front ends.  */
 
 /* Handle a "packed" attribute; arguments as in
@@ -2398,27 +2563,21 @@ handle_malloc_attribute (tree *node, tree name, tr
    struct attribute_spec.handler.  */
 
 static tree
-handle_alloc_size_attribute (tree *node, tree ARG_UNUSED (name), tree args,
+handle_alloc_size_attribute (tree *node, tree name, tree args,
 			     int ARG_UNUSED (flags), bool *no_add_attrs)
 {
-  unsigned arg_count = type_num_arguments (*node);
-  for (; args; args = TREE_CHAIN (args))
+  for (int i = 1; args; args = TREE_CHAIN (args), ++i)
     {
-      tree position = TREE_VALUE (args);
-      if (position && TREE_CODE (position) != IDENTIFIER_NODE
-	  && TREE_CODE (position) != FUNCTION_DECL)
-	position = default_conversion (position);
-
-      if (!tree_fits_uhwi_p (position)
-	  || !arg_count
-	  || !IN_RANGE (tree_to_uhwi (position), 1, arg_count))
+      tree pos = TREE_VALUE (args);
+      if (tree val = positional_argument (*node, name, pos, INTEGER_TYPE, i))
+	TREE_VALUE (args) = val;
+      else
 	{
-	  warning (OPT_Wattributes,
-	           "alloc_size parameter outside range");
 	  *no_add_attrs = true;
-	  return NULL_TREE;
+	  break;
 	}
     }
+
   return NULL_TREE;
 }
 
@@ -2426,24 +2585,23 @@ static tree
    struct attribute_spec.handler.  */
 
 static tree
-handle_alloc_align_attribute (tree *node, tree, tree args, int,
+handle_alloc_align_attribute (tree *node, tree name, tree args, int,
 			      bool *no_add_attrs)
 {
-  unsigned arg_count = type_num_arguments (*node);
-  tree position = TREE_VALUE (args);
-  if (position && TREE_CODE (position) != IDENTIFIER_NODE
-      && TREE_CODE (position) != FUNCTION_DECL)
-    position = default_conversion (position);
-
-  if (!tree_fits_uhwi_p (position)
-      || !arg_count
-      || !IN_RANGE (tree_to_uhwi (position), 1, arg_count))
+  tree decl = *node;
+  tree rettype = TREE_TYPE (decl);
+  if (!POINTER_TYPE_P (rettype))
     {
       warning (OPT_Wattributes,
-	       "alloc_align parameter outside range");
+	       "%qE attribute ignored on a function returning %qT",
+	       name, rettype);
       *no_add_attrs = true;
       return NULL_TREE;
     }
+
+  if (!positional_argument (*node, name, TREE_VALUE (args), INTEGER_TYPE))
+    *no_add_attrs = true;
+
   return NULL_TREE;
 }
 
@@ -2451,23 +2609,63 @@ static tree
    struct attribute_spec.handler.  */
 
 static tree
-handle_assume_aligned_attribute (tree *, tree, tree args, int,
+handle_assume_aligned_attribute (tree *node, tree name, tree args, int,
 				 bool *no_add_attrs)
 {
+  tree decl = *node;
+  tree rettype = TREE_TYPE (decl);
+  if (TREE_CODE (rettype) != POINTER_TYPE)
+    {
+      warning (OPT_Wattributes,
+	       "%qE attribute ignored on a function returning %qT",
+	       name, rettype);
+      *no_add_attrs = true;
+      return NULL_TREE;
+    }
+
+  /* The alignment specified by the first argument.  */
+  tree align = NULL_TREE;
+
   for (; args; args = TREE_CHAIN (args))
     {
-      tree position = TREE_VALUE (args);
-      if (position && TREE_CODE (position) != IDENTIFIER_NODE
-	  && TREE_CODE (position) != FUNCTION_DECL)
-	position = default_conversion (position);
+      tree val = TREE_VALUE (args);
+      if (val && TREE_CODE (val) != IDENTIFIER_NODE
+	  && TREE_CODE (val) != FUNCTION_DECL)
+	val = default_conversion (val);
 
-      if (TREE_CODE (position) != INTEGER_CST)
+      if (!tree_fits_shwi_p (val))
 	{
 	  warning (OPT_Wattributes,
-		   "assume_aligned parameter not integer constant");
+		   "%qE attribute %E is not an integer constant",
+		   name, val);
 	  *no_add_attrs = true;
 	  return NULL_TREE;
 	}
+
+      if (!align)
+	{
+	  /* Validate and save the alignment.  */
+	  if (!integer_pow2p (val))
+	    {
+	      warning (OPT_Wattributes,
+		       "%qE attribute argument %E is not a power of 2",
+		       name, val);
+	      *no_add_attrs = true;
+	      return NULL_TREE;
+	    }
+
+	  align = val;
+	}
+      else if (tree_int_cst_sgn (val) < 0 || tree_int_cst_le (align, val))
+	{
+	  /* The misalignment specified by the second argument
+	     must be non-negative and less than the alignment.  */
+	  warning (OPT_Wattributes,
+		   "%qE attribute argument %E is not in the range [0, %E)",
+		   name, val, align);
+	  *no_add_attrs = true;
+	  return NULL_TREE;
+	}
     }
   return NULL_TREE;
 }
@@ -3049,12 +3247,11 @@ handle_vector_size_attribute (tree *node, tree nam
 /* Handle the "nonnull" attribute.  */
 
 static tree
-handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
+handle_nonnull_attribute (tree *node, tree name,
 			  tree args, int ARG_UNUSED (flags),
 			  bool *no_add_attrs)
 {
   tree type = *node;
-  unsigned HOST_WIDE_INT attr_arg_num;
 
   /* If no arguments are specified, all pointer arguments should be
      non-null.  Verify a full prototype is given so that the arguments
@@ -3073,57 +3270,16 @@ static tree
       return NULL_TREE;
     }
 
-  /* Argument list specified.  Verify that each argument number references
-     a pointer argument.  */
-  for (attr_arg_num = 1; args; attr_arg_num++, args = TREE_CHAIN (args))
+  for (int i = 1; args; args = TREE_CHAIN (args), ++i)
     {
-      unsigned HOST_WIDE_INT arg_num = 0, ck_num;
-
-      tree arg = TREE_VALUE (args);
-      if (arg && TREE_CODE (arg) != IDENTIFIER_NODE
-	  && TREE_CODE (arg) != FUNCTION_DECL)
-	TREE_VALUE (args) = arg = default_conversion (arg);
-
-      if (!get_nonnull_operand (arg, &arg_num))
+      tree pos = TREE_VALUE (args);
+      if (tree val = positional_argument (type, name, pos, POINTER_TYPE, i))
+	TREE_VALUE (args) = val;
+      else
 	{
-	  error ("nonnull argument has invalid operand number (argument %lu)",
-		 (unsigned long) attr_arg_num);
 	  *no_add_attrs = true;
-	  return NULL_TREE;
+	  break;
 	}
-
-      if (prototype_p (type))
-	{
-	  function_args_iterator iter;
-	  tree argument;
-
-	  function_args_iter_init (&iter, type);
-	  for (ck_num = 1; ; ck_num++, function_args_iter_next (&iter))
-	    {
-	      argument = function_args_iter_cond (&iter);
-	      if (argument == NULL_TREE || ck_num == arg_num)
-		break;
-	    }
-
-	  if (!argument
-	      || TREE_CODE (argument) == VOID_TYPE)
-	    {
-	      error ("nonnull argument with out-of-range operand number "
-		     "(argument %lu, operand %lu)",
-		     (unsigned long) attr_arg_num, (unsigned long) arg_num);
-	      *no_add_attrs = true;
-	      return NULL_TREE;
-	    }
-
-	  if (TREE_CODE (argument) != POINTER_TYPE)
-	    {
-	      error ("nonnull argument references non-pointer operand "
-		     "(argument %lu, operand %lu)",
-		     (unsigned long) attr_arg_num, (unsigned long) arg_num);
-	      *no_add_attrs = true;
-	      return NULL_TREE;
-	    }
-	}
     }
 
   return NULL_TREE;
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 264901)
+++ gcc/c-family/c-common.c	(working copy)
@@ -5622,7 +5622,8 @@ check_function_arguments (location_t loc, const_tr
   /* Check for errors in format strings.  */
 
   if (warn_format || warn_suggest_attribute_format)
-    check_function_format (TYPE_ATTRIBUTES (fntype), nargs, argarray, arglocs);
+    check_function_format (fntype, TYPE_ATTRIBUTES (fntype), nargs, argarray,
+			   arglocs);
 
   if (warn_format)
     check_function_sentinel (fntype, nargs, argarray);
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 264901)
+++ gcc/c-family/c-common.h	(working copy)
@@ -804,7 +804,8 @@ extern void check_function_arguments_recurse (void
 					      unsigned HOST_WIDE_INT);
 extern bool check_builtin_function_arguments (location_t, vec<location_t>,
 					      tree, int, tree *);
-extern void check_function_format (tree, int, tree *, vec<location_t> *);
+extern void check_function_format (const_tree, tree, int, tree *,
+				   vec<location_t> *);
 extern bool attribute_fallthrough_p (tree);
 extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
 extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
@@ -1322,6 +1323,18 @@ extern int tm_attr_to_mask (tree);
 extern tree tm_mask_to_attr (int);
 extern tree find_tm_attribute (tree);
 
+/* A bitmap of flags to positional_argument.  */
+enum PosArgFlags {
+  /* Consider positional attribute argument value zero valid.  */
+  posarg_zero = 1,
+  /* Consider positional attribute argument value valid if it refers
+     to the ellipsis (i.e., beyond the last typed argument).  */
+  posarg_ellipsis = 2
+};
+
+extern tree positional_argument (const_tree, const_tree, tree, tree_code,
+				 int = 0, int = PosArgFlags ());
+
 extern enum flt_eval_method
 excess_precision_mode_join (enum flt_eval_method, enum flt_eval_method);
 
Index: gcc/c-family/c-format.c
===================================================================
--- gcc/c-family/c-format.c	(revision 264901)
+++ gcc/c-family/c-format.c	(working copy)
@@ -62,15 +62,17 @@ static GTY(()) tree local_tree_type_node;
 static GTY(()) tree local_gimple_ptr_node;
 static GTY(()) tree locus;
 
-static bool decode_format_attr (tree, function_format_info *, int);
+static bool decode_format_attr (const_tree, tree, tree, function_format_info *,
+				bool);
 static int decode_format_type (const char *);
 
-static bool check_format_string (tree argument,
+static bool check_format_string (const_tree argument,
 				 unsigned HOST_WIDE_INT format_num,
 				 int flags, bool *no_add_attrs,
 				 int expected_format_type);
-static bool get_constant (tree expr, unsigned HOST_WIDE_INT *value,
-			  int validated_p);
+static tree get_constant (const_tree fntype, const_tree atname, tree expr,
+			  int argno, unsigned HOST_WIDE_INT *value,
+			  int flags, bool validated_p);
 static const char *convert_format_name_to_system_name (const char *attr_name);
 
 static int first_target_format_type;
@@ -132,16 +134,18 @@ valid_stringptr_type_p (tree strref)
 /* Handle a "format_arg" attribute; arguments as in
    struct attribute_spec.handler.  */
 tree
-handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name),
+handle_format_arg_attribute (tree *node, tree atname,
 			     tree args, int flags, bool *no_add_attrs)
 {
   tree type = *node;
-  tree format_num_expr = TREE_VALUE (args);
+  tree *format_num_expr = &TREE_VALUE (args);
   unsigned HOST_WIDE_INT format_num = 0;
 
-  if (!get_constant (format_num_expr, &format_num, 0))
+  if (tree val = get_constant (type, atname, *format_num_expr, 0, &format_num,
+			       0, false))
+    *format_num_expr = val;
+  else
     {
-      error ("format string has invalid operand number");
       *no_add_attrs = true;
       return NULL_TREE;
     }
@@ -170,7 +174,7 @@ tree
    error).  When we know the specific reference type expected, this is also 
    checked.  */
 static bool
-check_format_string (tree fntype, unsigned HOST_WIDE_INT format_num,
+check_format_string (const_tree fntype, unsigned HOST_WIDE_INT format_num,
 		     int flags, bool *no_add_attrs, int expected_format_type)
 {
   unsigned HOST_WIDE_INT i;
@@ -263,19 +267,20 @@ static bool
 
 /* Verify EXPR is a constant, and store its value.
    If validated_p is true there should be no errors.
-   Returns true on success, false otherwise.  */
-static bool
-get_constant (tree expr, unsigned HOST_WIDE_INT *value, int validated_p)
+   Returns the converted constant value on success, null otherwise.  */
+static tree
+get_constant (const_tree fntype, const_tree atname, tree expr, int argno,
+	      unsigned HOST_WIDE_INT *value, int flags, bool validated_p)
 {
-  if (!tree_fits_uhwi_p (expr))
+  if (tree val = positional_argument (fntype, atname, expr, STRING_CST,
+				      argno, flags))
     {
-      gcc_assert (!validated_p);
-      return false;
+      *value = TREE_INT_CST_LOW (val);
+      return val;
     }
 
-  *value = TREE_INT_CST_LOW (expr);
-
-  return true;
+  gcc_assert (!validated_p);
+  return NULL_TREE;
 }
 
 /* Decode the arguments to a "format" attribute into a
@@ -286,12 +291,12 @@ static bool
    attributes are successfully decoded, false otherwise.  */
 
 static bool
-decode_format_attr (tree args, function_format_info *info, int validated_p)
+decode_format_attr (const_tree fntype, tree atname, tree args,
+		    function_format_info *info, bool validated_p)
 {
   tree format_type_id = TREE_VALUE (args);
-  tree format_num_expr = TREE_VALUE (TREE_CHAIN (args));
-  tree first_arg_num_expr
-    = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
+  tree *format_num_expr = &TREE_VALUE (TREE_CHAIN (args));
+  tree *first_arg_num_expr = &TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
 
   if (TREE_CODE (format_type_id) != IDENTIFIER_NODE)
     {
@@ -326,17 +331,18 @@ static bool
 	}
     }
 
-  if (!get_constant (format_num_expr, &info->format_num, validated_p))
-    {
-      error ("format string has invalid operand number");
-      return false;
-    }
+  if (tree val = get_constant (fntype, atname, *format_num_expr,
+			       2, &info->format_num, 0, validated_p))
+    *format_num_expr = val;
+  else
+    return false;
 
-  if (!get_constant (first_arg_num_expr, &info->first_arg_num, validated_p))
-    {
-      error ("%<...%> has invalid operand number");
-      return false;
-    }
+  if (tree val = get_constant (fntype, atname, *first_arg_num_expr,
+			       3, &info->first_arg_num,
+			       (posarg_zero | posarg_ellipsis), validated_p))
+    *first_arg_num_expr = val;
+  else
+    return false;
 
   if (info->first_arg_num != 0 && info->first_arg_num <= info->format_num)
     {
@@ -1076,11 +1082,13 @@ decode_format_type (const char *s)
    attribute themselves.  */
 
 void
-check_function_format (tree attrs, int nargs, tree *argarray,
-		       vec<location_t> *arglocs)
+check_function_format (const_tree fntype, tree attrs, int nargs,
+		       tree *argarray, vec<location_t> *arglocs)
 {
   tree a;
 
+  tree atname = get_identifier ("format");
+
   /* See if this function has any format attributes.  */
   for (a = attrs; a; a = TREE_CHAIN (a))
     {
@@ -1088,7 +1096,8 @@ void
 	{
 	  /* Yup; check it.  */
 	  function_format_info info;
-	  decode_format_attr (TREE_VALUE (a), &info, /*validated=*/true);
+	  decode_format_attr (fntype, atname, TREE_VALUE (a), &info,
+			      /*validated=*/true);
 	  if (warn_format)
 	    {
 	      /* FIXME: Rewrite all the internal functions in this file
@@ -4100,10 +4109,10 @@ convert_format_name_to_system_name (const char *at
 /* Handle a "format" attribute; arguments as in
    struct attribute_spec.handler.  */
 tree
-handle_format_attribute (tree *node, tree ARG_UNUSED (name), tree args,
+handle_format_attribute (tree *node, tree atname, tree args,
 			 int flags, bool *no_add_attrs)
 {
-  tree type = *node;
+  const_tree type = *node;
   function_format_info info;
 
 #ifdef TARGET_FORMAT_TYPES
@@ -4129,7 +4138,7 @@ tree
   if (TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
     TREE_VALUE (args) = canonicalize_attr_name (TREE_VALUE (args));
 
-  if (!decode_format_attr (args, &info, 0))
+  if (!decode_format_attr (type, atname, args, &info, /* validated_p = */false))
     {
       *no_add_attrs = true;
       return NULL_TREE;
Index: gcc/testsuite/c-c++-common/attributes-1.c
===================================================================
--- gcc/testsuite/c-c++-common/attributes-1.c	(revision 264901)
+++ gcc/testsuite/c-c++-common/attributes-1.c	(working copy)
@@ -1,21 +1,22 @@
 /* { dg-do compile } */
 /* { dg-prune-output "undeclared here \\(not in a function\\)|\[^\n\r\]* was not declared in this scope" } */
 
-void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,bar))); /* { dg-warning "outside range" } */
-void* my_realloc(void*, unsigned) __attribute__((alloc_size(bar))); /* { dg-warning "outside range" } */
+void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,bar))); /* { dg-warning ".alloc_size. attribute argument 2 value is not an integer constant" } */
+void* my_realloc(void*, unsigned) __attribute__((alloc_size(bar))); /* { dg-warning ".alloc_size. attribute argument 1 value is not an integer constant" } */
 
 typedef char vec __attribute__((vector_size(bar))); /* { dg-warning "ignored" } */
 
-void f1(char*) __attribute__((nonnull(bar))); /* { dg-error "invalid operand" } */
-void f2(char*) __attribute__((nonnull(1,bar))); /* { dg-error "invalid operand" } */
+void f1(char*) __attribute__((nonnull(bar))); /* { dg-warning ".nonnull. attribute argument 1 value is not an integer constant" } */
 
+void f2(char*) __attribute__((nonnull(1,bar))); /* { dg-warning ".nonnull. attribute argument 2 value is not an integer constant" } */
+
 void foo(void);
-void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,foo))); /* { dg-warning "outside range" } */
-void* my_realloc(void*, unsigned) __attribute__((alloc_size(foo))); /* { dg-warning "outside range" } */
+void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,foo))); /* { dg-warning ".alloc_size. attribute argument 2 value .foo. is not an integer constant" } */
+void* my_realloc(void*, unsigned) __attribute__((alloc_size(foo))); /* { dg-warning ".alloc_size. attribute argument 1 value .foo. is not an integer constant" } */
 
 typedef char vec __attribute__((vector_size(foo))); /* { dg-warning "ignored" } */
 
-void f1(char*) __attribute__((nonnull(foo))); /* { dg-error "invalid operand" } */
-void f2(char*) __attribute__((nonnull(1,foo))); /* { dg-error "invalid operand" } */
+void f1(char*) __attribute__((nonnull(foo))); /* { dg-warning ".nonnull. attribute argument 1 value .foo. is not an integer constant" } */
+void f2(char*) __attribute__((nonnull(1,foo))); /* { dg-warning ".nonnull. attribute argument 2 value .foo. is not an integer constant" } */
 
 void g() __attribute__((aligned(foo))); /* { dg-error "invalid value|not an integer" } */
Index: gcc/testsuite/g++.dg/ext/attr-alloc_size.C
===================================================================
--- gcc/testsuite/g++.dg/ext/attr-alloc_size.C	(nonexistent)
+++ gcc/testsuite/g++.dg/ext/attr-alloc_size.C	(working copy)
@@ -0,0 +1,53 @@
+/* PR c++/87541 - ICE using a constant decl as an attribute alloc_size argument
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+#define ALLOC_SIZE(N)   __attribute__ ((alloc_size (N)))
+
+const int i1 = 1;
+ALLOC_SIZE (i1) void* fcst (int);
+
+void* call_fcst (void)
+{
+  void *p = fcst (1);
+  __builtin___memset_chk (p, 0, 2, __builtin_object_size (p, 1));   // { dg-warning "\\\[-Wstringop-overflow=" }
+  return p;
+}
+
+
+enum { e1 = 1 };
+ALLOC_SIZE (e1) void* fenum (int);
+
+void* call_fenum (void)
+{
+  void *p = fenum (1);
+  __builtin___memset_chk (p, 0, 2, __builtin_object_size (p, 1));   // { dg-warning "\\\[-Wstringop-overflow=" }
+  return p;
+}
+
+
+template <class T>
+struct A
+{
+  ALLOC_SIZE (T::N1) static void* ftemplarg_1 (int);
+  ALLOC_SIZE (T::N2) static void*
+  ftemplarg_2 (int); // { dg-warning "attribute argument 1 value 2 exceeds the number of function parameters 1" }
+};
+
+struct B { static const int N1 = 1; static const int N2 = 1; };
+
+void* call_ftemplarg_1 (A<B> *pa)
+{
+  void *p = pa->ftemplarg_1 (1);
+  __builtin___memset_chk (p, 0, 2, __builtin_object_size (p, 1));   // { dg-warning "\\\[-Wstringop-overflow=" }
+  return p;
+}
+
+struct C { static const int N1 = 1; static const int N2 = 2; };
+
+void* call_ftemplarg_2 (A<C> *pa)
+{
+  void *p = pa->ftemplarg_2 (1);
+  __builtin___memset_chk (p, 0, 2, __builtin_object_size (p, 1));
+  return p;
+}
Index: gcc/testsuite/gcc.dg/attr-alloc_align-2.c
===================================================================
--- gcc/testsuite/gcc.dg/attr-alloc_align-2.c	(revision 264901)
+++ gcc/testsuite/gcc.dg/attr-alloc_align-2.c	(working copy)
@@ -5,6 +5,6 @@ void *f1 (int) __attribute__((alloc_align (1)));
 void *f2 (int, int, int) __attribute__((alloc_align (3)));
 void *f3 (void) __attribute__((alloc_align)); /* { dg-error "wrong number of arguments specified" } */
 void *f4 (int, int) __attribute__((alloc_align (1, 2))); /* { dg-error "wrong number of arguments specified" } */
-void *f5 (void) __attribute__((alloc_align (i))); /* { dg-warning "outside range" } */
-void *f6 (int) __attribute__((alloc_align (0))); /* { dg-warning "outside range" } */
-void *f7 (int) __attribute__((alloc_align (2))); /* { dg-warning "outside range" } */
+void *f5 (void) __attribute__((alloc_align (i))); /* { dg-warning ".alloc_align. attribute argument value .i. is not an integer constant" } */
+void *f6 (int) __attribute__((alloc_align (0))); /* { dg-warning ".alloc_align. attribute argument value 0 does not refer to a function parameter" } */
+void *f7 (int) __attribute__((alloc_align (2))); /* { dg-warning ".alloc_align. attribute argument value 2 exceeds the number of function parameters 1" } */
Index: gcc/testsuite/gcc.dg/attr-alloc_align-4.c
===================================================================
--- gcc/testsuite/gcc.dg/attr-alloc_align-4.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/attr-alloc_align-4.c	(working copy)
@@ -0,0 +1,37 @@
+/* PR middle-end/81871 - bogus attribute alloc_align accepted
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+#define ALIGN(N)   __attribute__ ((alloc_align (N)))
+#define SIZE_MAX  __SIZE_MAX__
+
+ALIGN (1) void fvv_m1 (void);     /* { dg-warning ".alloc_align. attribute ignored on a function returning .void." } */
+
+ALIGN (1) int fiv_1 (void);       /* { dg-warning ".alloc_align. attribute ignored on a function returning .int." } */
+
+ALIGN (0) void* fpvv_0 (void);    /* { dg-warning ".alloc_align. attribute argument value 0 does not refer to a function parameter" } */
+
+ALIGN (1) void* fpvv_1 (void);    /* { dg-warning ".alloc_align. attribute argument value 1 exceeds the number of function parameters 0" } */
+
+ALIGN (2) void* fii_2 (int);      /* { dg-warning ".alloc_align. attribute argument value 2 exceeds the number of function parameters 1" } */
+
+ALIGN (1) void fvi_1 (int);       /* { dg-warning ".alloc_align. attribute ignored on a function returning .void." } */
+
+/* Using alloc_align with a function returning a pointer to a function
+   should perhaps trigger a warning.  */
+typedef void (F)(void);
+ALIGN (1) F* fpF_i_1 (int);
+
+ALIGN (SIZE_MAX) void*
+fpvi_szmax (int);                 /* { dg-warning ".alloc_align. attribute argument value \[0-9\]+ exceeds the number of function parameters 1" } */
+
+ALIGN ("1") void*
+fpvi_str_1 (int);                 /* { dg-warning ".alloc_align. attribute argument value .\"1\". is not an integer constant" } */
+
+ALIGN (1) void*
+fpvi_pv_1 (void*);                /* { dg-warning ".alloc_align. attribute argument value 1 refers to parameter type .void \\\*." } */
+
+struct S { int i; };
+ALIGN (2) void*
+fpvi_S_2 (int, struct S);         /* { dg-warning ".alloc_align. attribute argument value 2 refers to parameter type .struct S." } */
+
Index: gcc/testsuite/gcc.dg/attr-alloc_size-2.c
===================================================================
--- gcc/testsuite/gcc.dg/attr-alloc_size-2.c	(revision 264901)
+++ gcc/testsuite/gcc.dg/attr-alloc_size-2.c	(working copy)
@@ -1,4 +1,5 @@
-/* { dg-do compile } */
+/* PR c/36021 - __attribute__((alloc_size(n))) with function of no
+   arguments causes gcc to segfault
+   { dg-do compile } */
 
-char *foo() __attribute__((alloc_size(1))); /* { dg-warning "outside range" } */
-
+char *foo() __attribute__((alloc_size(1)));
Index: gcc/testsuite/gcc.dg/attr-alloc_size.c
===================================================================
--- gcc/testsuite/gcc.dg/attr-alloc_size.c	(revision 264901)
+++ gcc/testsuite/gcc.dg/attr-alloc_size.c	(working copy)
@@ -5,13 +5,13 @@ extern void abort (void);
 
 #include "../gcc.c-torture/execute/builtins/chk.h"
 
-extern char *mallocminus1(int size) __attribute__((alloc_size(-1))); /* { dg-warning "parameter outside range" } */
-extern char *malloc0(int size) __attribute__((alloc_size(0))); /* { dg-warning "parameter outside range" } */
+extern char *mallocminus1(int size) __attribute__((alloc_size(-1))); /* { dg-warning ".alloc_size. attribute argument 1 value -1 exceeds the number of function parameters 1" } */
+extern char *malloc0(int size) __attribute__((alloc_size(0))); /* { dg-warning ".alloc_size. attribute argument 1 value 0 does not refer to a function parameter" } */
 extern char *malloc1(int size) __attribute__((alloc_size(1)));
 extern char *malloc2(int empty, int size) __attribute__((alloc_size(2)));
 extern char *calloc1(int size, int elements) __attribute__((alloc_size(1,2)));
 extern char *calloc2(int size, int empty, int elements) __attribute__((alloc_size(1,3)));
-extern char *balloc1(void *size) __attribute__((alloc_size(1)));
+extern char *balloc1(void *size) __attribute__((alloc_size(1)));   /* { dg-warning ".alloc_size. attribute argument 1 value 1 refers to parameter type .void *." } */
 
 void
 test (void)
Index: gcc/testsuite/gcc.dg/attr-assume_aligned-4.c
===================================================================
--- gcc/testsuite/gcc.dg/attr-assume_aligned-4.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/attr-assume_aligned-4.c	(working copy)
@@ -0,0 +1,36 @@
+/* PR middle-end/87533 - bogus assume_aligned attribute silently accepted
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+#define A(...)  __attribute__ ((assume_aligned (__VA_ARGS__)))
+
+A (1) void fv_1 (void);       /* { dg-warning ".assume_aligned. attribute ignored on a function returning .void." } */
+
+A (1) int fi_1 (void);        /* { dg-warning ".assume_aligned. attribute ignored on a function returning .int." } */
+
+A (-1) void* fpv_m1 (void);   /* { dg-warning ".assume_aligned. attribute argument -1 is not a power of 2" } */
+
+A (0) void* fpv_0 (void);     /* { dg-warning ".assume_aligned. attribute argument 0 is not a power of 2" } */
+
+/* Alignment of 1 is fine, it just doesn't offer any benefits.  */
+A (1) void* fpv_1 (void);
+
+A (3) void* fpv_3 (void);     /* { dg-warning ".assume_aligned. attribute argument 3 is not a power of 2" } */
+
+A (16383) void* fpv_16km1 (void);     /* { dg-warning ".assume_aligned. attribute argument 16383 is not a power of 2" } */
+A (16384) void* fpv_16k (void);
+A (16385) void* fpv_16kp1 (void);    /* { dg-warning ".assume_aligned. attribute argument 16385 is not a power of 2" } */
+
+A (32767) void* fpv_32km1 (void);     /* { dg-warning ".assume_aligned. attribute argument 32767 is not a power of 2" } */
+
+A (4, -1) void* fpv_4_m1 (void);      /* { dg-warning ".assume_aligned. attribute argument -1 is not in the range \\\[0, 4\\\)" } */
+
+A (4, 0) void* fpv_4_0 (void);
+A (4, 1) void* fpv_4_1 (void);
+A (4, 2) void* fpv_4_2 (void);
+A (4, 3) void* fpv_4_3 (void);
+
+A (4, 4) void* fpv_4_3 (void);        /* { dg-warning ".assume_aligned. attribute argument 4 is not in the range \\\[0, 4\\\)" } */
+
+A (4) void* gpv_4_3 (void);
+A (2) void* gpv_4_3 (void);
Index: gcc/testsuite/gcc.dg/format/attr-3.c
===================================================================
--- gcc/testsuite/gcc.dg/format/attr-3.c	(revision 264901)
+++ gcc/testsuite/gcc.dg/format/attr-3.c	(working copy)
@@ -41,10 +41,10 @@ extern void fe1 (const char *, ...) __attribute__(
 /* Both the numbers must be integer constant expressions.  */
 extern void ff0 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, (long long)(10/5))));
 int foo;
-extern void ff1 (const char *, ...) __attribute__((format(gnu_attr_printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */
-extern void ff2 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */
+extern void ff1 (const char *, ...) __attribute__((format(gnu_attr_printf, foo, 10/5))); /* { dg-warning ".format. attribute argument 2 value .foo. is not an integer constant" "bad number" } */
+extern void ff2 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, foo))); /* { dg-warning ".format. attribute argument 3 value .foo. is not an integer constant" "bad number" } */
 extern char *ff3 (const char *) __attribute__((format_arg(3-2)));
-extern char *ff4 (const char *) __attribute__((format_arg(foo))); /* { dg-error "invalid operand" "bad format_arg number" } */
+extern char *ff4 (const char *) __attribute__((format_arg(foo))); /* { dg-warning ".format_arg. attribute argument value .foo. is not an integer constant" "bad format_arg number" } */
 
 /* The format string argument must precede the arguments to be formatted.
    This includes if no parameter types are specified (which is not valid ISO
@@ -56,14 +56,14 @@ extern void fg3 () __attribute__((format(gnu_attr_
 
 /* The format string argument must be a string type, and the arguments to
    be formatted must be the "...".  */
-extern void fh0 (int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "format int string" } */
+extern void fh0 (int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-warning ".format. attribute argument 2 value 1 refers to parameter type .int." "format int string" } */
 extern void fh1 (signed char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */
 extern void fh2 (unsigned char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */
 extern void fh3 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 3))); /* { dg-error "is not" "not ..." } */
-extern void fh4 (const char *, int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "is not" "not ..." } */
+extern void fh4 (const char *, int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error ".format. attribute argument 3 value 2 does not refer to a variable argument list" "not ..." } */
 
 /* format_arg formats must take and return a string.  */
-extern char *fi0 (int) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg int string" } */
+extern char *fi0 (int) __attribute__((format_arg(1))); /* { dg-warning ".format_arg. attribute argument value 1 refers to parameter type .int." } */
 extern char *fi1 (signed char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg signed char string" } */
 extern char *fi2 (unsigned char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg unsigned char string" } */
 extern int fi3 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret int string" } */
Index: gcc/testsuite/gcc.dg/nonnull-2.c
===================================================================
--- gcc/testsuite/gcc.dg/nonnull-2.c	(revision 264901)
+++ gcc/testsuite/gcc.dg/nonnull-2.c	(working copy)
@@ -4,11 +4,12 @@
 
 extern void func1 () __attribute__((nonnull)); /* { dg-error "without arguments" } */
 
-extern void func2 (char *) __attribute__((nonnull(2))); /* { dg-error "out-of-range operand" } */
+extern void func2 (char *) __attribute__((nonnull(2))); /* { dg-warning ".nonnull. attribute argument 1 value 2 exceeds the number of function parameters 1" } */
 
-extern void func3 (char *) __attribute__((nonnull(foo))); /* { dg-error "invalid operand number|undeclared" } */
+extern void func3 (char *) __attribute__((nonnull (foo))); /* { dg-warning ".nonnull. attribute argument 1 value is not an integer constant" } */
+/* { dg-error ".foo. undeclared" "undeclared argument" { target *-*-* } .-1 } */
 
-extern void func4 (int) __attribute__((nonnull(1))); /* { dg-error "references non-pointer" } */
+extern void func4 (int) __attribute__((nonnull(1))); /* { dg-warning ".nonnull. attribute argument 1 value 1 refers to parameter type .int." } */
 
 void
 foo (void)
Index: gcc/tree.c
===================================================================
--- gcc/tree.c	(revision 264901)
+++ gcc/tree.c	(working copy)
@@ -4947,7 +4947,8 @@ build_nt_call_vec (tree fn, vec<tree, va_gc> *args
   return ret;
 }
 
-/* Create a DECL_... node of code CODE, name NAME and data type TYPE.
+/* Create a DECL_... node of code CODE, name NAME  (if non-null)
+   and data type TYPE.
    We do NOT enter this node in any sort of symbol table.
 
    LOC is the location of the decl.
@@ -6749,6 +6750,37 @@ type_num_arguments (const_tree type)
   return i;
 }
 
+/* Return the type of the function TYPE's argument ARGNO if known.
+   For vararg function's where ARGNO refers to one of the variadic
+   arguments return null.  Otherwise, return a void_type_node for
+   out-of-bounds ARGNO.  */
+
+tree
+type_argument_type (const_tree type, unsigned argno)
+{
+  /* Treat zero the same as an out-of-bounds argument number.  */
+  if (!argno)
+    return void_type_node;
+
+  unsigned i = 1;
+
+  for (tree t = TYPE_ARG_TYPES (type); ; t = TREE_CHAIN (t), ++i)
+    {
+      /* A vararg function's argument list ends in a null.  Otheriwse,
+	 an ordinary function's argument list ends with void.  Return
+	 null if ARGNO refers to a vararg argument, void_type_node if
+	 it's out of bounds, and the formal argument type otherwise.  */
+      if (!t)
+	break;
+
+      tree argtype = TREE_VALUE (t);
+      if (i == argno || VOID_TYPE_P (argtype))
+	return argtype;
+    }
+
+  return NULL_TREE;
+}
+
 /* Nonzero if integer constants T1 and T2
    represent the same constant value.  */
 
Index: gcc/tree.h
===================================================================
--- gcc/tree.h	(revision 264901)
+++ gcc/tree.h	(working copy)
@@ -4798,6 +4798,7 @@ extern tree get_file_function_name (const char *);
 extern tree get_callee_fndecl (const_tree);
 extern combined_fn get_call_combined_fn (const_tree);
 extern int type_num_arguments (const_tree);
+extern tree type_argument_type (const_tree, unsigned) ATTRIBUTE_NONNULL (1);
 extern bool associative_tree_code (enum tree_code);
 extern bool commutative_tree_code (enum tree_code);
 extern bool commutative_ternary_tree_code (enum tree_code);
Index: gcc/testsuite/c-c++-common/pr71574.c
===================================================================
--- gcc/testsuite/c-c++-common/pr71574.c	(revision 264901)
+++ gcc/testsuite/c-c++-common/pr71574.c	(working copy)
@@ -1,12 +1,15 @@
-/* PR c/71574 */
+/* PR c/71574 - ICE on code with alloc_align attribute */
 /* { dg-do compile } */
 
 int fn1 (void);
-int fn2 (void) __attribute__ ((alloc_align (fn1))); /* { dg-warning "parameter outside range" } */
-int fn3 (void) __attribute__ ((alloc_size (fn1))); /* { dg-warning "parameter outside range" } */
-int fn4 (void) __attribute__ ((assume_aligned (fn1))); /* { dg-warning "not integer constant" } */
-int fn5 (char *, char *) __attribute__((nonnull (fn1))); /* { dg-error "nonnull argument has invalid operand" } */
+int fn2 (void) __attribute__ ((alloc_align (fn1))); /* { dg-warning ".alloc_align. attribute ignored on a function returning .int." } */
+int fn3 (void) __attribute__ ((alloc_size (fn1))); /* { dg-warning ".alloc_size. attribute argument 1 value .fn1. is not an integer constant" } */
+int fn4 (void) __attribute__ ((assume_aligned (fn1))); /* { dg-warning ".assume_aligned. attribute ignored on a function returning .int." } */
+int fn5 (char *, char *) __attribute__((nonnull (fn1))); /* { dg-warning ".nonnull. attribute argument 1 value .fn1. is not an integer constant" } */
 int fn6 (const char *, ...) __attribute__ ((sentinel (fn1))); /* { dg-warning "not an integer constant" } */
 
+void* fn7 (void) __attribute__ ((alloc_align (fn1))); /* { dg-warning ".alloc_align. attribute argument value .fn1. is not an integer constant" } */
+void* fn8 (void) __attribute__ ((assume_aligned (fn1))); /* { dg-warning "not an integer constant" } */
+
 typedef int __attribute__((vector_size (fn1))) v4si; /* { dg-warning "attribute ignored" } */
 typedef int T __attribute__((aligned (fn1))); /* { dg-error "requested alignment is not" } */
Index: gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm
===================================================================
--- gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm	(revision 264901)
+++ gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm	(working copy)
@@ -19,8 +19,8 @@
 - (void) log2: (int)level  message: (const char *) my_format, ...  __attribute__ ((format (printf, 2)));    /* { dg-error "wrong" } */
 + (void) debug2: (const char *) my_format, ...  __attribute__ ((format (printf))); /* { dg-error "wrong" } */
 - (void) debug2: (const char *) my_format, ...  __attribute__ ((format (printf))); /* { dg-error "wrong" } */
-+ (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "args to be formatted is not ..." } */
-- (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "args to be formatted is not ..." } */
++ (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-warning "does not refer to a variable argument list" } */
+- (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-warning "does not refer to a variable argument list" } */
 @end
 
 void test (LogObject *object)
Index: gcc/testsuite/obj-c++.dg/attributes/method-nonnull-1.mm
===================================================================
--- gcc/testsuite/obj-c++.dg/attributes/method-nonnull-1.mm	(revision 264901)
+++ gcc/testsuite/obj-c++.dg/attributes/method-nonnull-1.mm	(working copy)
@@ -19,14 +19,14 @@
 - (void) insertObject: (id)object  atIndex: (size_t)index  andObject: (id)anotherObject  atIndex: (size_t)anotherIndex __attribute__ ((nonnull (1, 3)));
 
 /* Test the behavior with invalid code.  */
-+ (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-error "out-of-range" } */
-- (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-error "out-of-range" } */
++ (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-warning "does not refer to a function parameter" } */
+- (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-warning "does not refer to a function parameter" } */
 
-+ (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-error "out-of-range" } */
-- (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-error "out-of-range" } */
++ (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-warning "exceeds the number of function parameters 3" } */
+- (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-warning "exceeds the number of function parameters 3" } */
 
-+ (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-error "non-pointer operand" } */
-- (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-error "non-pointer operand" } */
++ (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-warning "refers to parameter type .size_t." } */
+- (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-warning "refers to parameter type .size_t." } */
 
 + (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-error "" } */
 - (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-error "" } */
Index: gcc/testsuite/objc.dg/attributes/method-format-1.m
===================================================================
--- gcc/testsuite/objc.dg/attributes/method-format-1.m	(revision 264901)
+++ gcc/testsuite/objc.dg/attributes/method-format-1.m	(working copy)
@@ -19,8 +19,8 @@
 - (void) log2: (int)level  message: (const char *) my_format, ...  __attribute__ ((format (printf, 2)));    /* { dg-error "wrong" } */
 + (void) debug2: (const char *) my_format, ...  __attribute__ ((format (printf))); /* { dg-error "wrong" } */
 - (void) debug2: (const char *) my_format, ...  __attribute__ ((format (printf))); /* { dg-error "wrong" } */
-+ (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "args to be formatted is not ..." } */
-- (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "args to be formatted is not ..." } */
++ (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "does not refer to a variable argument list" } */
+- (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "does not refer to a variable argument list" } */
 @end
 
 void test (LogObject *object)
Index: gcc/testsuite/objc.dg/attributes/method-nonnull-1.m
===================================================================
--- gcc/testsuite/objc.dg/attributes/method-nonnull-1.m	(revision 264901)
+++ gcc/testsuite/objc.dg/attributes/method-nonnull-1.m	(working copy)
@@ -19,17 +19,17 @@
 - (void) insertObject: (id)object  atIndex: (size_t)index  andObject: (id)anotherObject  atIndex: (size_t)anotherIndex __attribute__ ((nonnull (1, 3)));
 
 /* Test the behavior with invalid code.  */
-+ (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-error "out-of-range" } */
-- (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-error "out-of-range" } */
++ (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-warning "does not refer to a function parameter" } */
+- (void) removeObject: (id)object __attribute__ ((nonnull (0))); /* { dg-warning "does not refer to a function parameter" } */
 
-+ (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-error "out-of-range" } */
-- (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-error "out-of-range" } */
++ (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-error "exceeds the number of function parameters 3" } */
+- (void) removeObject: (id)object __attribute__ ((nonnull (2))); /* { dg-error "exceeds the number of function parameters 3" } */
 
-+ (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-error "non-pointer operand" } */
-- (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-error "non-pointer operand" } */
++ (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-warning "refers to parameter type .size_t." } */
+- (void) removeObjectAtIndex: (size_t)object __attribute__ ((nonnull (1))); /* { dg-warning "refers to parameter type .size_t." } */
 
-+ (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-error "invalid operand" } */
-- (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-error "invalid operand" } */
++ (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-warning "is not an integer constant" } */
+- (void) removeObject: (id)object __attribute__ ((nonnull (MyArray))); /* { dg-warning "is not an integer constant" } */
 @end
 
 void test (MyArray *object)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]