From 677ff44144c9a085fd89f336776cbac272df05cf Mon Sep 17 00:00:00 2001 From: Jim Wilson Date: Tue, 6 Apr 1993 12:30:45 -0700 Subject: (decl_attributes... (decl_attributes, format case): Error if num_arg does not point to a string type argument, or if first_arg_num not the anonymous argument. From-SVN: r4032 --- gcc/c-common.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'gcc') diff --git a/gcc/c-common.c b/gcc/c-common.c index 21dedef..e4d161f 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -275,6 +275,8 @@ decl_attributes (decl, attributes) int format_num = TREE_INT_CST_LOW (TREE_PURPOSE (TREE_VALUE (list))); int first_arg_num = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (list))); int is_scan; + tree argument; + int arg_num; if (TREE_CODE (decl) != FUNCTION_DECL) { @@ -299,6 +301,34 @@ decl_attributes (decl, attributes) "format string arg follows the args to be formatted, for `%s'"); return; } + + /* Verify that the format_num argument is actually a string, in case + the format attribute is in error. */ + argument = TYPE_ARG_TYPES (TREE_TYPE (decl)); + for (arg_num = 1; ; ++arg_num) + { + if (argument == 0 || arg_num == format_num) + break; + argument = TREE_CHAIN (argument); + } + if (! argument + || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE + || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument))) + != char_type_node)) + { + error_with_decl (decl, + "format string arg not a string type, for `%s'"); + return; + } + /* Verify that first_arg_num points to the last argument, the ... */ + while (argument) + arg_num++, argument = TREE_CHAIN (argument); + if (arg_num != first_arg_num) + { + error_with_decl (decl, + "args to be formatted is not ..., for `%s'"); + return; + } record_format_info (DECL_NAME (decl), is_scan, format_num, first_arg_num); -- cgit v1.1