From patchwork Wed May 4 16:45:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 94087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0026E1007EA for ; Thu, 5 May 2011 02:45:54 +1000 (EST) Received: (qmail 28021 invoked by alias); 4 May 2011 16:45:50 -0000 Received: (qmail 27999 invoked by uid 22791); 4 May 2011 16:45:47 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 04 May 2011 16:45:31 +0000 Received: (qmail 2124 invoked from network); 4 May 2011 16:45:30 -0000 Received: from unknown (HELO localhost) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 4 May 2011 16:45:30 -0000 Date: Wed, 4 May 2011 09:45:26 -0700 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: [PATCH] don't use TYPE_ARG_TYPES in c-family/ Message-ID: <20110504164526.GI23480@codesourcery.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org As $SUBJECT suggests. The patch is somewhat larger than it needs to be due to reindenting c-common.c:check_main_parameter_types. Tested on x86_64-unknown-linux. OK to commit? -Nathan gcc/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. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 802040d..ca65d19 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1662,45 +1662,44 @@ strict_aliasing_warning (tree otype, tree type, tree expr) void check_main_parameter_types (tree decl) { - tree args; + function_args_iterator iter; + tree type; int argct = 0; - for (args = TYPE_ARG_TYPES (TREE_TYPE (decl)); args; - args = TREE_CHAIN (args)) - { - tree type = args ? TREE_VALUE (args) : 0; - - if (type == void_type_node || type == error_mark_node ) - break; - - ++argct; - switch (argct) - { - case 1: - if (TYPE_MAIN_VARIANT (type) != integer_type_node) - pedwarn (input_location, OPT_Wmain, "first argument of %q+D should be %", - decl); - break; - - case 2: - if (TREE_CODE (type) != POINTER_TYPE - || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE - || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) - != char_type_node)) - pedwarn (input_location, OPT_Wmain, "second argument of %q+D should be %", - decl); - break; - - case 3: - if (TREE_CODE (type) != POINTER_TYPE - || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE - || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) - != char_type_node)) - pedwarn (input_location, OPT_Wmain, "third argument of %q+D should probably be " - "%", decl); - break; - } - } + FOREACH_FUNCTION_ARGS (TREE_TYPE (decl), type, iter) + { + /* XXX void_type_node belies the abstraction. */ + if (type == void_type_node || type == error_mark_node ) + break; + + ++argct; + switch (argct) + { + case 1: + if (TYPE_MAIN_VARIANT (type) != integer_type_node) + pedwarn (input_location, OPT_Wmain, "first argument of %q+D should be %", + decl); + break; + + case 2: + if (TREE_CODE (type) != POINTER_TYPE + || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE + || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) + != char_type_node)) + pedwarn (input_location, OPT_Wmain, "second argument of %q+D should be %", + decl); + break; + + case 3: + if (TREE_CODE (type) != POINTER_TYPE + || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE + || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) + != char_type_node)) + pedwarn (input_location, OPT_Wmain, "third argument of %q+D should probably be " + "%", decl); + break; + } + } /* It is intentional that this message does not mention the third argument because it's only mentioned in an appendix of the @@ -7394,7 +7393,6 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), a pointer argument. */ for (attr_arg_num = 1; args; args = TREE_CHAIN (args)) { - tree argument; unsigned HOST_WIDE_INT arg_num = 0, ck_num; if (!get_nonnull_operand (TREE_VALUE (args), &arg_num)) @@ -7405,18 +7403,21 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), return NULL_TREE; } - argument = TYPE_ARG_TYPES (type); - if (argument) + if (prototype_p (type)) { - 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; - argument = TREE_CHAIN (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)", (unsigned long) attr_arg_num, (unsigned long) arg_num); @@ -7424,7 +7425,7 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), 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)", (unsigned long) attr_arg_num, (unsigned long) arg_num); @@ -8921,22 +8922,28 @@ sync_resolve_size (tree function, VEC(tree,gc) *params) static bool 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; unsigned int parmnum; + function_args_iter_init (&iter, TREE_TYPE (function)); /* We've declared the implementation functions to use "volatile void *" as the pointer parameter, so we shouldn't get any complaints from the 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))); /* 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. */ 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; if (VEC_length (tree, params) <= parmnum) @@ -8950,10 +8957,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. */ val = VEC_index (tree, params, parmnum); val = convert (ptype, val); - val = convert (TREE_VALUE (arg_types), val); + val = convert (arg_type, 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 diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 0c5115a..66012c4 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -120,7 +120,6 @@ handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name), tree type = *node; tree format_num_expr = TREE_VALUE (args); unsigned HOST_WIDE_INT format_num = 0; - tree argument; if (!get_constant (format_num_expr, &format_num, 0)) { @@ -129,12 +128,11 @@ handle_format_arg_attribute (tree *node, tree ARG_UNUSED (name), return NULL_TREE; } - argument = TYPE_ARG_TYPES (type); - if (argument) + if (prototype_p (type)) { /* The format arg can be any string reference valid for the language and 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; } @@ -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 checked. */ 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) { unsigned HOST_WIDE_INT i; bool is_objc_sref, is_target_sref, is_char_ref; tree ref; 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; - argument = TREE_CHAIN (argument); + i++; } - if (!argument - || !(ref = TREE_VALUE (argument)) + if (!ref || !valid_stringptr_type_p (ref)) { if (!(flags & (int) ATTR_FLAG_BUILT_IN)) @@ -2957,7 +2956,6 @@ handle_format_attribute (tree *node, tree ARG_UNUSED (name), tree args, { tree type = *node; function_format_info info; - tree argument; #ifdef TARGET_FORMAT_TYPES /* 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, return NULL_TREE; } - argument = TYPE_ARG_TYPES (type); - if (argument) + if (prototype_p (type)) { - if (!check_format_string (argument, info.format_num, flags, + if (!check_format_string (type, info.format_num, flags, no_add_attrs, info.format_type)) return NULL_TREE; if (info.first_arg_num != 0) { unsigned HOST_WIDE_INT arg_num = 1; + function_args_iterator iter; + tree arg_type; /* Verify that first_arg_num points to the last arg, the ... */ - while (argument) - arg_num++, argument = TREE_CHAIN (argument); + FOREACH_FUNCTION_ARGS (type, arg_type, iter) + arg_num++; if (arg_num != info.first_arg_num) {