aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJim Wilson <wilson@gcc.gnu.org>1993-04-06 12:30:45 -0700
committerJim Wilson <wilson@gcc.gnu.org>1993-04-06 12:30:45 -0700
commit677ff44144c9a085fd89f336776cbac272df05cf (patch)
tree1631746372fc920493ae32ffee6b26f284c0bb88 /gcc
parent1b8297c13f94c9dd27b5f726d388cc09d2d8a391 (diff)
downloadgcc-677ff44144c9a085fd89f336776cbac272df05cf.zip
gcc-677ff44144c9a085fd89f336776cbac272df05cf.tar.gz
gcc-677ff44144c9a085fd89f336776cbac272df05cf.tar.bz2
(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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-common.c30
1 files changed, 30 insertions, 0 deletions
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);