diff options
author | Joseph Myers <jsm28@cam.ac.uk> | 2001-10-02 08:12:25 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2001-10-02 08:12:25 +0100 |
commit | 6431177a552eca9ee9d4b1fde8255f98363e4c34 (patch) | |
tree | 4648d58efabadc87677da26b0f516d5bfc64f45c /gcc/testsuite/gcc.dg/format | |
parent | ed0ea5602b8f9b125eb77a59521ce8a636584704 (diff) | |
download | gcc-6431177a552eca9ee9d4b1fde8255f98363e4c34.zip gcc-6431177a552eca9ee9d4b1fde8255f98363e4c34.tar.gz gcc-6431177a552eca9ee9d4b1fde8255f98363e4c34.tar.bz2 |
attribs.c (decl_attributes): Possibly call insert_default_attributes to insert default attributes on...
* attribs.c (decl_attributes): Possibly call
insert_default_attributes to insert default attributes on
functions in a lazy manner.
* builtin-attrs.def: New file; define the default format and
format_arg attributes.
* c-common.c (c_format_attribute_table): Move to earlier in the
file.
(c_common_nodes_and_builtins): Initialize format_attribute_table.
(enum built_in_attribute, built_in_attributes,
c_attrs_initialized, c_init_attributes,
c_common_insert_default_attributes): New.
(c_common_lang_init): Don't initialize format_attribute_table. Do
call c_init_attributes.
* Makefile.in (c-common.o): Depend on builtin-attrs.def.
* c-common.h (init_function_format_info): Don't declare.
(c_common_insert_default_attributes): Declare.
* c-decl.c (implicitly_declare, builtin_function): Call
decl_attributes.
(init_decl_processing): Don't call init_function_format_info.
(insert_default_attributes): New.
* c-format.c (handle_format_attribute,
handle_format_arg_attribute): Be quiet about inappropriate
declaration when applying default attributes.
(init_function_format_info): Remove.
* tree.h (enum attribute_flags): Add ATTR_FLAG_BUILT_IN.
(insert_default_attributes): Declare.
cp:
* decl.c (init_decl_processing): Don't call
init_function_format_info. Initialize lang_attribute_table
earlier.
(builtin_function): Call decl_attributes.
(insert_default_attributes): New.
testsuite:
* gcc.dg/format/attr-5.c, gcc.dg/format/attr-6.c: New tests.
From-SVN: r45942
Diffstat (limited to 'gcc/testsuite/gcc.dg/format')
-rw-r--r-- | gcc/testsuite/gcc.dg/format/attr-5.c | 28 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/attr-6.c | 21 |
2 files changed, 49 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/format/attr-5.c b/gcc/testsuite/gcc.dg/format/attr-5.c new file mode 100644 index 0000000..a4e9634 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/attr-5.c @@ -0,0 +1,28 @@ +/* Test for format attributes: test default attributes are silently ignored + when a function is redeclared in an inappropriate manner. */ +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +/* We can't #include "format.h" here. */ + +/* This scanf declaration is static, so can't be the system function. */ +static int scanf(const char *restrict, ...); + +/* This sscanf declaration doesn't have variable arguments, so isn't + compatible with a format attribute. */ +extern int sscanf(const char *restrict, const char *restrict, int *); + +void +foo (const char *s, int *p) +{ + scanf("%ld", p); /* { dg-bogus "format" "static" } */ + sscanf(s, "%ld", p); /* { dg-bogus "format" "wrong type" } */ +} + +/* Dummy definition of scanf. */ +static int +scanf (const char *restrict fmt, ...) +{ + return 0; +} diff --git a/gcc/testsuite/gcc.dg/format/attr-6.c b/gcc/testsuite/gcc.dg/format/attr-6.c new file mode 100644 index 0000000..4e95cfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/attr-6.c @@ -0,0 +1,21 @@ +/* Test for format attributes: test default attributes are applied + to implicit declarations. */ +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu89 -Wformat" } */ + +/* We can't #include "format.h" here. */ + +/* Technically, none of the format functions should be implicitly declared; + either the implicit type is wrong, the function has variable arguments + or it requires a type declared in a header. However, some bad programming + practice uses implicit declarations of some of these functions. + + Note that printf is not used in this test because of the declaration + of it as a built-in function. */ + +void +foo (const char *s, int *p) +{ + scanf("%ld", p); /* { dg-warning "format" "implicit scanf" } */ +} |