Commit e19a18d4 by Nathan Froyd Committed by Nathan Froyd

don't use TYPE_ARG_TYPES in c-family/

don't use TYPE_ARG_TYPES in c-family/
	* c-common.c (check_main_parameter_types): Reindent.  Don't use
	TYPE_ARG_TYPES directly.
	(handle_nonnull_attribute): Likewise.
	(sync_resolve_params): Likewise.
	* c-format.c (handle_format_arg_attribute): Likewise.  Adjust call
	to check_format_string.
	(handle_format_attribute): Likewise.
	(check_format_string): Take a function type to examine instead of
	a type list.  Use a function_arg_iterator to step through argument
	types.

From-SVN: r173384
parent 7a2f7208
2011-05-04 Nathan Froyd <froydnj@codesourcery.com>
* c-common.c (check_main_parameter_types): Reindent. Don't use
TYPE_ARG_TYPES directly.
(handle_nonnull_attribute): Likewise.
(sync_resolve_params): Likewise.
* c-format.c (handle_format_arg_attribute): Likewise. Adjust call
to check_format_string.
(handle_format_attribute): Likewise.
(check_format_string): Take a function type to examine instead of
a type list. Use a function_arg_iterator to step through argument
types.
2011-05-04 Richard Guenther <rguenther@suse.de> 2011-05-04 Richard Guenther <rguenther@suse.de>
* c-common.c (fix_string_type): Use size_int for index type bounds. * c-common.c (fix_string_type): Use size_int for index type bounds.
......
...@@ -1663,51 +1663,52 @@ strict_aliasing_warning (tree otype, tree type, tree expr) ...@@ -1663,51 +1663,52 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
void void
check_main_parameter_types (tree decl) check_main_parameter_types (tree decl)
{ {
tree args; function_args_iterator iter;
tree type;
int argct = 0; int argct = 0;
for (args = TYPE_ARG_TYPES (TREE_TYPE (decl)); args; FOREACH_FUNCTION_ARGS (TREE_TYPE (decl), type, iter)
args = TREE_CHAIN (args)) {
{ /* XXX void_type_node belies the abstraction. */
tree type = args ? TREE_VALUE (args) : 0; if (type == void_type_node || type == error_mark_node )
break;
if (type == void_type_node || type == error_mark_node )
break; ++argct;
switch (argct)
++argct; {
switch (argct) case 1:
{ if (TYPE_MAIN_VARIANT (type) != integer_type_node)
case 1: pedwarn (input_location, OPT_Wmain,
if (TYPE_MAIN_VARIANT (type) != integer_type_node) "first argument of %q+D should be %<int%>", decl);
pedwarn (input_location, OPT_Wmain, "first argument of %q+D should be %<int%>", break;
decl);
break; case 2:
if (TREE_CODE (type) != POINTER_TYPE
case 2: || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
if (TREE_CODE (type) != POINTER_TYPE || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
|| TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE != char_type_node))
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) pedwarn (input_location, OPT_Wmain,
!= char_type_node)) "second argument of %q+D should be %<char **%>", decl);
pedwarn (input_location, OPT_Wmain, "second argument of %q+D should be %<char **%>", break;
decl);
break; case 3:
if (TREE_CODE (type) != POINTER_TYPE
case 3: || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
if (TREE_CODE (type) != POINTER_TYPE || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
|| TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE != char_type_node))
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) pedwarn (input_location, OPT_Wmain,
!= char_type_node)) "third argument of %q+D should probably be "
pedwarn (input_location, OPT_Wmain, "third argument of %q+D should probably be " "%<char **%>", decl);
"%<char **%>", decl); break;
break; }
} }
}
/* It is intentional that this message does not mention the third /* It is intentional that this message does not mention the third
argument because it's only mentioned in an appendix of the argument because it's only mentioned in an appendix of the
standard. */ standard. */
if (argct > 0 && (argct < 2 || argct > 3)) if (argct > 0 && (argct < 2 || argct > 3))
pedwarn (input_location, OPT_Wmain, "%q+D takes only zero or two arguments", decl); pedwarn (input_location, OPT_Wmain,
"%q+D takes only zero or two arguments", decl);
} }
/* True if pointers to distinct types T1 and T2 can be converted to /* True if pointers to distinct types T1 and T2 can be converted to
...@@ -7395,7 +7396,6 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), ...@@ -7395,7 +7396,6 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
a pointer argument. */ a pointer argument. */
for (attr_arg_num = 1; args; args = TREE_CHAIN (args)) for (attr_arg_num = 1; args; args = TREE_CHAIN (args))
{ {
tree argument;
unsigned HOST_WIDE_INT arg_num = 0, ck_num; unsigned HOST_WIDE_INT arg_num = 0, ck_num;
if (!get_nonnull_operand (TREE_VALUE (args), &arg_num)) if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
...@@ -7406,18 +7406,21 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), ...@@ -7406,18 +7406,21 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
return NULL_TREE; return NULL_TREE;
} }
argument = TYPE_ARG_TYPES (type); if (prototype_p (type))
if (argument)
{ {
for (ck_num = 1; ; ck_num++) function_args_iterator iter;
tree argument;
function_args_iter_init (&iter, type);
for (ck_num = 1; ; ck_num++, function_args_iter_next (&iter))
{ {
if (!argument || ck_num == arg_num) argument = function_args_iter_cond (&iter);
if (argument == NULL_TREE || ck_num == arg_num)
break; break;
argument = TREE_CHAIN (argument);
} }
if (!argument if (!argument
|| TREE_CODE (TREE_VALUE (argument)) == VOID_TYPE) || TREE_CODE (argument) == VOID_TYPE)
{ {
error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)", error ("nonnull argument with out-of-range operand number (argument %lu, operand %lu)",
(unsigned long) attr_arg_num, (unsigned long) arg_num); (unsigned long) attr_arg_num, (unsigned long) arg_num);
...@@ -7425,7 +7428,7 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), ...@@ -7425,7 +7428,7 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
return NULL_TREE; return NULL_TREE;
} }
if (TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE) if (TREE_CODE (argument) != POINTER_TYPE)
{ {
error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)", error ("nonnull argument references non-pointer operand (argument %lu, operand %lu)",
(unsigned long) attr_arg_num, (unsigned long) arg_num); (unsigned long) attr_arg_num, (unsigned long) arg_num);
...@@ -8922,22 +8925,28 @@ sync_resolve_size (tree function, VEC(tree,gc) *params) ...@@ -8922,22 +8925,28 @@ sync_resolve_size (tree function, VEC(tree,gc) *params)
static bool static bool
sync_resolve_params (tree orig_function, tree function, VEC(tree, gc) *params) sync_resolve_params (tree orig_function, tree function, VEC(tree, gc) *params)
{ {
tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); function_args_iterator iter;
tree ptype; tree ptype;
unsigned int parmnum; unsigned int parmnum;
function_args_iter_init (&iter, TREE_TYPE (function));
/* We've declared the implementation functions to use "volatile void *" /* We've declared the implementation functions to use "volatile void *"
as the pointer parameter, so we shouldn't get any complaints from the as the pointer parameter, so we shouldn't get any complaints from the
call to check_function_arguments what ever type the user used. */ call to check_function_arguments what ever type the user used. */
arg_types = TREE_CHAIN (arg_types); function_args_iter_next (&iter);
ptype = TREE_TYPE (TREE_TYPE (VEC_index (tree, params, 0))); ptype = TREE_TYPE (TREE_TYPE (VEC_index (tree, params, 0)));
/* For the rest of the values, we need to cast these to FTYPE, so that we /* For the rest of the values, we need to cast these to FTYPE, so that we
don't get warnings for passing pointer types, etc. */ don't get warnings for passing pointer types, etc. */
parmnum = 0; parmnum = 0;
while (arg_types != void_list_node) while (1)
{ {
tree val; tree val, arg_type;
arg_type = function_args_iter_cond (&iter);
/* XXX void_type_node belies the abstraction. */
if (arg_type == void_type_node)
break;
++parmnum; ++parmnum;
if (VEC_length (tree, params) <= parmnum) if (VEC_length (tree, params) <= parmnum)
...@@ -8951,10 +8960,10 @@ sync_resolve_params (tree orig_function, tree function, VEC(tree, gc) *params) ...@@ -8951,10 +8960,10 @@ sync_resolve_params (tree orig_function, tree function, VEC(tree, gc) *params)
type. This isn't portable across the C and C++ front ends atm. */ type. This isn't portable across the C and C++ front ends atm. */
val = VEC_index (tree, params, parmnum); val = VEC_index (tree, params, parmnum);
val = convert (ptype, val); val = convert (ptype, val);
val = convert (TREE_VALUE (arg_types), val); val = convert (arg_type, val);
VEC_replace (tree, params, parmnum, val); VEC_replace (tree, params, parmnum, val);
arg_types = TREE_CHAIN (arg_types); function_args_iter_next (&iter);
} }
/* The definition of these primitives is variadic, with the remaining /* The definition of these primitives is variadic, with the remaining
......
...@@ -120,7 +120,6 @@ handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name), ...@@ -120,7 +120,6 @@ handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name),
tree type = *node; tree type = *node;
tree format_num_expr = TREE_VALUE (args); tree format_num_expr = TREE_VALUE (args);
unsigned HOST_WIDE_INT format_num = 0; unsigned HOST_WIDE_INT format_num = 0;
tree argument;
if (!get_constant (format_num_expr, &format_num, 0)) if (!get_constant (format_num_expr, &format_num, 0))
{ {
...@@ -129,12 +128,11 @@ handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name), ...@@ -129,12 +128,11 @@ handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name),
return NULL_TREE; return NULL_TREE;
} }
argument = TYPE_ARG_TYPES (type); if (prototype_p (type))
if (argument)
{ {
/* The format arg can be any string reference valid for the language and /* The format arg can be any string reference valid for the language and
target. We cannot be more specific in this case. */ target. We cannot be more specific in this case. */
if (!check_format_string (argument, format_num, flags, no_add_attrs, -1)) if (!check_format_string (type, format_num, flags, no_add_attrs, -1))
return NULL_TREE; return NULL_TREE;
} }
...@@ -154,23 +152,24 @@ handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name), ...@@ -154,23 +152,24 @@ handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name),
error). When we know the specific reference type expected, this is also error). When we know the specific reference type expected, this is also
checked. */ checked. */
static bool static bool
check_format_string (tree argument, unsigned HOST_WIDE_INT format_num, check_format_string (tree fntype, unsigned HOST_WIDE_INT format_num,
int flags, bool *no_add_attrs, int expected_format_type) int flags, bool *no_add_attrs, int expected_format_type)
{ {
unsigned HOST_WIDE_INT i; unsigned HOST_WIDE_INT i;
bool is_objc_sref, is_target_sref, is_char_ref; bool is_objc_sref, is_target_sref, is_char_ref;
tree ref; tree ref;
int fmt_flags; int fmt_flags;
function_args_iterator iter;
for (i = 1; i != format_num; i++) i = 1;
FOREACH_FUNCTION_ARGS (fntype, ref, iter)
{ {
if (argument == 0) if (i == format_num)
break; break;
argument = TREE_CHAIN (argument); i++;
} }
if (!argument if (!ref
|| !(ref = TREE_VALUE (argument))
|| !valid_stringptr_type_p (ref)) || !valid_stringptr_type_p (ref))
{ {
if (!(flags & (int) ATTR_FLAG_BUILT_IN)) if (!(flags & (int) ATTR_FLAG_BUILT_IN))
...@@ -2957,7 +2956,6 @@ handle_format_attribute (tree *node, tree ARG_UNUSED (name), tree args, ...@@ -2957,7 +2956,6 @@ handle_format_attribute (tree *node, tree ARG_UNUSED (name), tree args,
{ {
tree type = *node; tree type = *node;
function_format_info info; function_format_info info;
tree argument;
#ifdef TARGET_FORMAT_TYPES #ifdef TARGET_FORMAT_TYPES
/* If the target provides additional format types, we need to /* If the target provides additional format types, we need to
...@@ -2984,21 +2982,22 @@ handle_format_attribute (tree *node, tree ARG_UNUSED (name), tree args, ...@@ -2984,21 +2982,22 @@ handle_format_attribute (tree *node, tree ARG_UNUSED (name), tree args,
return NULL_TREE; return NULL_TREE;
} }
argument = TYPE_ARG_TYPES (type); if (prototype_p (type))
if (argument)
{ {
if (!check_format_string (argument, info.format_num, flags, if (!check_format_string (type, info.format_num, flags,
no_add_attrs, info.format_type)) no_add_attrs, info.format_type))
return NULL_TREE; return NULL_TREE;
if (info.first_arg_num != 0) if (info.first_arg_num != 0)
{ {
unsigned HOST_WIDE_INT arg_num = 1; unsigned HOST_WIDE_INT arg_num = 1;
function_args_iterator iter;
tree arg_type;
/* Verify that first_arg_num points to the last arg, /* Verify that first_arg_num points to the last arg,
the ... */ the ... */
while (argument) FOREACH_FUNCTION_ARGS (type, arg_type, iter)
arg_num++, argument = TREE_CHAIN (argument); arg_num++;
if (arg_num != info.first_arg_num) if (arg_num != info.first_arg_num)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment