aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <jsm28@cam.ac.uk>2001-09-22 20:06:29 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2001-09-22 20:06:29 +0100
commit040cc0718f8b93a667211eac1c95e86fc591c16f (patch)
tree2b2e6635a5d2abc634d9e996e64c0528d5207f80
parentf6a67a813e4cea8aee736da0cf9d8dca10e8d880 (diff)
downloadgcc-040cc0718f8b93a667211eac1c95e86fc591c16f.zip
gcc-040cc0718f8b93a667211eac1c95e86fc591c16f.tar.gz
gcc-040cc0718f8b93a667211eac1c95e86fc591c16f.tar.bz2
c-format.c (init_function_format_info): Check __builtin_printf and __builtin_fprintf even if -ffreestanding.
* c-format.c (init_function_format_info): Check __builtin_printf and __builtin_fprintf even if -ffreestanding. Check C99 functions in gnu89 mode. testsuite: * gcc.dg/format/builtin-1.c, gcc.dg/format/ext-6.c: New tests. From-SVN: r45757
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-format.c13
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/format/builtin-1.c17
-rw-r--r--gcc/testsuite/gcc.dg/format/ext-6.c43
5 files changed, 78 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e3f1a65..5d4a9f7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2001-09-22 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * 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 <kenner@vlsi1.ultra.nyu.edu>
* c-common.c (format_attribute_table): Remove decl.
diff --git a/gcc/c-format.c b/gcc/c-format.c
index 331cd25..e25c29e 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 6e7008e..2d73c67 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2001-09-22 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * gcc.dg/format/builtin-1.c, gcc.dg/format/ext-6.c: New tests.
+
2001-09-22 George Helffrich <george@geo.titech.ac.jp>
* 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 0000000..e128635
--- /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 <jsm28@cam.ac.uk> */
+/* { 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 0000000..a9653a1
--- /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 <jsm28@cam.ac.uk> */
+/* { 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" } */
+}