diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e3f1a65bac8..5d4a9f7a461 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2001-09-22 Joseph S. Myers + + * c-format.c (init_function_format_info): Check __builtin_printf + and __builtin_fprintf even if -ffreestanding. Check C99 functions + in gnu89 mode. + Sat Sep 22 09:09:32 2001 Richard Kenner * c-common.c (format_attribute_table): Remove decl. diff --git a/gcc/c-format.c b/gcc/c-format.c index 331cd252e8f..e25c29e2a06 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -325,17 +325,20 @@ static international_format_info *international_format_list = NULL; 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 ("__builtin_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 ("__builtin_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, @@ -354,7 +357,7 @@ init_function_format_info () strftime_format_type, 3, 0); } - if (flag_hosted && flag_isoc99) + 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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6e7008ecbb9..2d73c67a6d8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-09-22 Joseph S. Myers + + * gcc.dg/format/builtin-1.c, gcc.dg/format/ext-6.c: New tests. + 2001-09-22 George Helffrich * g77.dg/strlen0.f: New test. diff --git a/gcc/testsuite/gcc.dg/format/builtin-1.c b/gcc/testsuite/gcc.dg/format/builtin-1.c new file mode 100644 index 00000000000..e128635b99a --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/builtin-1.c @@ -0,0 +1,17 @@ +/* Test for format extensions. Test that the __builtin functions get their + default attributes even with -ffreestanding. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat -ffreestanding" } */ + +#include "format.h" + +void +foo (int i) +{ + __builtin_fprintf (stdout, "%d", i); + __builtin_fprintf (stdout, "%ld", i); /* { dg-warning "format" "__builtin_fprintf" } */ + __builtin_printf ("%d", i); + __builtin_printf ("%ld", i); /* { dg-warning "format" "__builtin_printf" } */ +} diff --git a/gcc/testsuite/gcc.dg/format/ext-6.c b/gcc/testsuite/gcc.dg/format/ext-6.c new file mode 100644 index 00000000000..a9653a1ea75 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/ext-6.c @@ -0,0 +1,43 @@ +/* Test for format extensions. Test that the C99 functions get their + default attributes in gnu89 mode. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu89 -Wformat" } */ + +#include "format.h" + +void +foo (int i, char *s, size_t n, int *ip, va_list v0, va_list v1, va_list v2, + va_list v3, va_list v4, va_list v5, va_list v6, va_list v7, va_list v8, + va_list v9, va_list v10, va_list v11, va_list v12, va_list v13) +{ + fprintf (stdout, "%d", i); + fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */ + printf ("%d", i); + printf ("%ld", i); /* { dg-warning "format" "printf" } */ + sprintf (s, "%d", i); + sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */ + snprintf (s, n, "%d", i); + snprintf (s, n, "%ld", i); /* { dg-warning "format" "snprintf" } */ + vfprintf (stdout, "%d", v0); + vfprintf (stdout, "%Y", v1); /* { dg-warning "format" "vfprintf" } */ + vprintf ("%d", v2); + vprintf ("%Y", v3); /* { dg-warning "format" "vprintf" } */ + vsprintf (s, "%d", v4); + vsprintf (s, "%Y", v5); /* { dg-warning "format" "vsprintf" } */ + vsnprintf (s, n, "%d", v6); + vsnprintf (s, n, "%Y", v7); /* { dg-warning "format" "vsnprintf" } */ + fscanf (stdin, "%d", ip); + fscanf (stdin, "%ld", ip); /* { dg-warning "format" "fscanf" } */ + scanf ("%d", ip); + scanf ("%ld", ip); /* { dg-warning "format" "scanf" } */ + sscanf (s, "%d", ip); + sscanf (s, "%ld", ip); /* { dg-warning "format" "sscanf" } */ + vfscanf (stdin, "%d", v8); + vfscanf (stdin, "%Y", v9); /* { dg-warning "format" "vfscanf" } */ + vscanf ("%d", v10); + vscanf ("%Y", v11); /* { dg-warning "format" "vscanf" } */ + vsscanf (s, "%d", v12); + vsscanf (s, "%Y", v13); /* { dg-warning "format" "vsscanf" } */ +}