This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to check C99 format functions in gnu89 mode and __builtin oneswhen freestanding
- To: <gcc-patches at gcc dot gnu dot org>
- Subject: Patch to check C99 format functions in gnu89 mode and __builtin oneswhen freestanding
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Date: Sat, 22 Sep 2001 20:07:48 +0100 (BST)
This patch fixes some oddities in which format functions are checked
when. The __builtin functions should be checked unconditionally, even
with -ffreestanding. The C99 functions should also be checked in
gnu89 mode (this is consistent with the handling of C99 built-in
functions).
Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to
mainline.
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.
testsuite:
2001-09-22 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/format/builtin-1.c, gcc.dg/format/ext-6.c: New tests.
--- c-format.c.orig Fri Sep 21 01:15:16 2001
+++ c-format.c Sat Sep 22 12:49:46 2001
@@ -325,17 +325,20 @@ static international_format_info *intern
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,
--- testsuite/gcc.dg/format/builtin-1.c.orig Mon Mar 26 23:57:02 2001
+++ testsuite/gcc.dg/format/builtin-1.c Sat Sep 22 16:18:18 2001
@@ -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" } */
+}
--- testsuite/gcc.dg/format/ext-6.c.orig Mon Mar 26 23:57:02 2001
+++ testsuite/gcc.dg/format/ext-6.c Sat Sep 22 16:15:28 2001
@@ -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" } */
+}
--
Joseph S. Myers
jsm28@cam.ac.uk