OSDN Git Service

* c-format.c (init_function_format_info): Check __builtin_printf
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 22 Sep 2001 19:06:29 +0000 (19:06 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 22 Sep 2001 19:06:29 +0000 (19:06 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45757 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-format.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/builtin-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/format/ext-6.c [new file with mode: 0644]

index e3f1a65..5d4a9f7 100644 (file)
@@ -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.
index 331cd25..e25c29e 100644 (file)
@@ -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,
index 6e7008e..2d73c67 100644 (file)
@@ -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 (file)
index 0000000..e128635
--- /dev/null
@@ -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 (file)
index 0000000..a9653a1
--- /dev/null
@@ -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" } */
+}