summaryrefslogtreecommitdiff
path: root/gcc/c-format.c
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2001-10-02 07:12:25 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2001-10-02 07:12:25 +0000
commit7d3b509adae17f526dad2929ae2b16183408401d (patch)
tree4648d58efabadc87677da26b0f516d5bfc64f45c /gcc/c-format.c
parent7c2404e186a146b9f3c028fed4742d3abc302d1b (diff)
downloadgcc-7d3b509adae17f526dad2929ae2b16183408401d.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45942 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-format.c')
-rw-r--r--gcc/c-format.c90
1 files changed, 10 insertions, 80 deletions
diff --git a/gcc/c-format.c b/gcc/c-format.c
index 3cc880e870e..4ee3b3d44a2 100644
--- a/gcc/c-format.c
+++ b/gcc/c-format.c
@@ -89,7 +89,7 @@ handle_format_attribute (node, name, args, flags, no_add_attrs)
tree *node;
tree name ATTRIBUTE_UNUSED;
tree args;
- int flags ATTRIBUTE_UNUSED;
+ int flags;
bool *no_add_attrs;
{
tree decl = *node;
@@ -177,7 +177,8 @@ handle_format_attribute (node, name, args, flags, no_add_attrs)
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
!= char_type_node))
{
- error ("format string arg not a string type");
+ if (!(flags & (int) ATTR_FLAG_BUILT_IN))
+ error ("format string arg not a string type");
*no_add_attrs = true;
return NULL_TREE;
}
@@ -191,7 +192,8 @@ handle_format_attribute (node, name, args, flags, no_add_attrs)
if (arg_num != first_arg_num)
{
- error ("args to be formatted is not '...'");
+ if (!(flags & (int) ATTR_FLAG_BUILT_IN))
+ error ("args to be formatted is not '...'");
*no_add_attrs = true;
return NULL_TREE;
}
@@ -218,7 +220,7 @@ handle_format_arg_attribute (node, name, args, flags, no_add_attrs)
tree *node;
tree name ATTRIBUTE_UNUSED;
tree args;
- int flags ATTRIBUTE_UNUSED;
+ int flags;
bool *no_add_attrs;
{
tree decl = *node;
@@ -268,7 +270,8 @@ handle_format_arg_attribute (node, name, args, flags, no_add_attrs)
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
!= char_type_node))
{
- error ("format string arg not a string type");
+ if (!(flags & (int) ATTR_FLAG_BUILT_IN))
+ error ("format string arg not a string type");
*no_add_attrs = true;
return NULL_TREE;
}
@@ -278,7 +281,8 @@ handle_format_arg_attribute (node, name, args, flags, no_add_attrs)
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl))))
!= char_type_node))
{
- error ("function does not return string type");
+ if (!(flags & (int) ATTR_FLAG_BUILT_IN))
+ error ("function does not return string type");
*no_add_attrs = true;
return NULL_TREE;
}
@@ -310,80 +314,6 @@ typedef struct international_format_info
static international_format_info *international_format_list = NULL;
-/* Initialize the table of functions to perform format checking on.
- The ISO C functions are always checked (whether <stdio.h> is
- included or not), since it is common to call printf without
- including <stdio.h>. There shouldn't be a problem with this,
- since ISO C reserves these function names whether you include the
- header file or not. In any case, the checking is harmless. With
- -ffreestanding, these default attributes are disabled, and must be
- specified manually if desired.
-
- Also initialize the name of function that modify the format string for
- internationalization purposes. */
-
-void
-init_function_format_info ()
-{
- /* __builtin functions should be checked unconditionally, even with
- -ffreestanding. */
- record_function_format (get_identifier ("__builtin_printf"), NULL_TREE,
- printf_format_type, 1, 2);
- record_function_format (get_identifier ("__builtin_fprintf"), NULL_TREE,
- printf_format_type, 2, 3);
-
- if (flag_hosted)
- {
- /* Functions from ISO/IEC 9899:1990. */
- record_function_format (get_identifier ("printf"), NULL_TREE,
- printf_format_type, 1, 2);
- record_function_format (get_identifier ("fprintf"), NULL_TREE,
- printf_format_type, 2, 3);
- record_function_format (get_identifier ("sprintf"), NULL_TREE,
- printf_format_type, 2, 3);
- record_function_format (get_identifier ("scanf"), NULL_TREE,
- scanf_format_type, 1, 2);
- record_function_format (get_identifier ("fscanf"), NULL_TREE,
- scanf_format_type, 2, 3);
- record_function_format (get_identifier ("sscanf"), NULL_TREE,
- scanf_format_type, 2, 3);
- record_function_format (get_identifier ("vprintf"), NULL_TREE,
- printf_format_type, 1, 0);
- record_function_format (get_identifier ("vfprintf"), NULL_TREE,
- printf_format_type, 2, 0);
- record_function_format (get_identifier ("vsprintf"), NULL_TREE,
- printf_format_type, 2, 0);
- record_function_format (get_identifier ("strftime"), NULL_TREE,
- strftime_format_type, 3, 0);
- }
-
- if (flag_hosted && (flag_isoc99 || flag_noniso_default_format_attributes))
- {
- /* ISO C99 adds the snprintf and vscanf family functions. */
- record_function_format (get_identifier ("snprintf"), NULL_TREE,
- printf_format_type, 3, 4);
- record_function_format (get_identifier ("vsnprintf"), NULL_TREE,
- printf_format_type, 3, 0);
- record_function_format (get_identifier ("vscanf"), NULL_TREE,
- scanf_format_type, 1, 0);
- record_function_format (get_identifier ("vfscanf"), NULL_TREE,
- scanf_format_type, 2, 0);
- record_function_format (get_identifier ("vsscanf"), NULL_TREE,
- scanf_format_type, 2, 0);
- }
-
- if (flag_hosted && flag_noniso_default_format_attributes)
- {
- /* Uniforum/GNU gettext functions, not in ISO C. */
- record_international_format (get_identifier ("gettext"), NULL_TREE, 1);
- record_international_format (get_identifier ("dgettext"), NULL_TREE, 2);
- record_international_format (get_identifier ("dcgettext"), NULL_TREE, 2);
- /* X/Open strfmon function. */
- record_function_format (get_identifier ("strfmon"), NULL_TREE,
- strfmon_format_type, 3, 4);
- }
-}
-
/* Record information for argument format checking. FUNCTION_IDENT is
the identifier node for the name of the function to check (its decl
need not exist yet).