From b4c984fbec1caaaa03c2c2bf2c9b42d3f7679223 Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Fri, 21 Dec 2001 02:36:37 +0000 Subject: builtin-attrs.def (__builtin_printf_unlocked, [...]): Mark with the __printf__ attribute. * builtin-attrs.def (__builtin_printf_unlocked, __builtin_fprintf_unlocked, printf_unlocked, fprintf_unlocked): Mark with the __printf__ attribute. * builtins.c (expand_builtin_fputs): Add an `unlocked' parameter and set the replacement function depending on it. (expand_builtin): Skip BUILT_IN_*_UNLOCKED when not optimizing. Handle BUILT_IN_*_UNLOCKED when optimizing. * builtins.def (DEF_EXT_FALLBACK_BUILTIN, DEF_EXT_FRONT_END_LIB_BUILTIN): New macros. Declare the "unlocked" stdio functions. * c-common.c (c_expand_builtin_printf, c_expand_builtin_fprintf): Add an `unlocked' parameter and set the replacement function depending on it. (c_expand_builtin): Handle BUILT_IN_PRINTF_UNLOCKED and BUILT_IN_FPRINTF_UNLOCKED. * doc/extend.texi (printf_unlocked, fprintf_unlocked, fputs_unlocked): Document. testsuite: * gcc.dg/format/builtin-1.c: Test unlocked stdio. * gcc.dg/format/c90-printf-3.c: Likewise. * gcc.dg/format/c99-printf-3.c: Likewise. * gcc.dg/format/ext-1.c: Likewise. * gcc.dg/format/ext-6.c: Likewise. * gcc.dg/format/format.h: Prototype unlocked stdio. From-SVN: r48229 --- gcc/testsuite/gcc.dg/format/builtin-1.c | 5 +++++ gcc/testsuite/gcc.dg/format/c90-printf-3.c | 3 +++ gcc/testsuite/gcc.dg/format/c99-printf-3.c | 3 +++ gcc/testsuite/gcc.dg/format/ext-1.c | 7 +++++++ gcc/testsuite/gcc.dg/format/ext-6.c | 4 ++++ gcc/testsuite/gcc.dg/format/format.h | 2 ++ 6 files changed, 24 insertions(+) (limited to 'gcc/testsuite/gcc.dg/format') diff --git a/gcc/testsuite/gcc.dg/format/builtin-1.c b/gcc/testsuite/gcc.dg/format/builtin-1.c index e128635..ba1cab6 100644 --- a/gcc/testsuite/gcc.dg/format/builtin-1.c +++ b/gcc/testsuite/gcc.dg/format/builtin-1.c @@ -14,4 +14,9 @@ foo (int i) __builtin_fprintf (stdout, "%ld", i); /* { dg-warning "format" "__builtin_fprintf" } */ __builtin_printf ("%d", i); __builtin_printf ("%ld", i); /* { dg-warning "format" "__builtin_printf" } */ + + __builtin_fprintf_unlocked (stdout, "%d", i); + __builtin_fprintf_unlocked (stdout, "%ld", i); /* { dg-warning "format" "__builtin_fprintf_unlocked" } */ + __builtin_printf_unlocked ("%d", i); + __builtin_printf_unlocked ("%ld", i); /* { dg-warning "format" "__builtin_printf_unlocked" } */ } diff --git a/gcc/testsuite/gcc.dg/format/c90-printf-3.c b/gcc/testsuite/gcc.dg/format/c90-printf-3.c index 78518a2..1d53de3 100644 --- a/gcc/testsuite/gcc.dg/format/c90-printf-3.c +++ b/gcc/testsuite/gcc.dg/format/c90-printf-3.c @@ -16,6 +16,9 @@ foo (int i, char *s, size_t n, va_list v0, va_list v1, va_list v2, va_list v3, fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */ printf ("%d", i); printf ("%ld", i); /* { dg-warning "format" "printf" } */ + /* The "unlocked" functions shouldn't warn in c90 mode. */ + fprintf_unlocked (stdout, "%ld", i); /* { dg-bogus "format" "fprintf_unlocked" } */ + printf_unlocked ("%ld", i); /* { dg-bogus "format" "printf_unlocked" } */ sprintf (s, "%d", i); sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */ vfprintf (stdout, "%d", v0); diff --git a/gcc/testsuite/gcc.dg/format/c99-printf-3.c b/gcc/testsuite/gcc.dg/format/c99-printf-3.c index 23ef33d..b8ae405 100644 --- a/gcc/testsuite/gcc.dg/format/c99-printf-3.c +++ b/gcc/testsuite/gcc.dg/format/c99-printf-3.c @@ -15,6 +15,9 @@ foo (int i, char *s, size_t n, va_list v0, va_list v1, va_list v2, va_list v3, fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */ printf ("%d", i); printf ("%ld", i); /* { dg-warning "format" "printf" } */ + /* The "unlocked" functions shouldn't warn in c99 mode. */ + fprintf_unlocked (stdout, "%ld", i); /* { dg-bogus "format" "fprintf_unlocked" } */ + printf_unlocked ("%ld", i); /* { dg-bogus "format" "printf_unlocked" } */ sprintf (s, "%d", i); sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */ snprintf (s, n, "%d", i); diff --git a/gcc/testsuite/gcc.dg/format/ext-1.c b/gcc/testsuite/gcc.dg/format/ext-1.c index dd78032..e69e756 100644 --- a/gcc/testsuite/gcc.dg/format/ext-1.c +++ b/gcc/testsuite/gcc.dg/format/ext-1.c @@ -116,4 +116,11 @@ foo (quad_t q, u_quad_t uq, quad_t *qn, size_t z, size_t *zn, long long int ll, printf ("%IC", lc); /* { dg-warning "flag" "bad use of I flag" } */ printf ("%IS", ls); /* { dg-warning "flag" "bad use of I flag" } */ printf ("%Im"); /* { dg-warning "flag" "bad use of I flag" } */ + + /* As an extension, GCC does format checking on "unlocked" + i.e. thread unsafe versions of these functions. */ + fprintf_unlocked (stdout, "%d", i); + fprintf_unlocked (stdout, "%ld", i); /* { dg-warning "format" "fprintf_unlocked" } */ + printf_unlocked ("%d", i); + printf_unlocked ("%ld", i); /* { dg-warning "format" "printf_unlocked" } */ } diff --git a/gcc/testsuite/gcc.dg/format/ext-6.c b/gcc/testsuite/gcc.dg/format/ext-6.c index a9653a1..08d24cb 100644 --- a/gcc/testsuite/gcc.dg/format/ext-6.c +++ b/gcc/testsuite/gcc.dg/format/ext-6.c @@ -16,6 +16,10 @@ foo (int i, char *s, size_t n, int *ip, va_list v0, va_list v1, va_list v2, fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */ printf ("%d", i); printf ("%ld", i); /* { dg-warning "format" "printf" } */ + fprintf_unlocked (stdout, "%d", i); + fprintf_unlocked (stdout, "%ld", i); /* { dg-warning "format" "fprintf_unlocked" } */ + printf_unlocked ("%d", i); + printf_unlocked ("%ld", i); /* { dg-warning "format" "printf_unlocked" } */ sprintf (s, "%d", i); sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */ snprintf (s, n, "%d", i); diff --git a/gcc/testsuite/gcc.dg/format/format.h b/gcc/testsuite/gcc.dg/format/format.h index b41ebd9..230d141 100644 --- a/gcc/testsuite/gcc.dg/format/format.h +++ b/gcc/testsuite/gcc.dg/format/format.h @@ -67,6 +67,8 @@ extern FILE *stdout; extern int fprintf (FILE *restrict, const char *restrict, ...); extern int printf (const char *restrict, ...); +extern int fprintf_unlocked (FILE *restrict, const char *restrict, ...); +extern int printf_unlocked (const char *restrict, ...); extern int sprintf (char *restrict, const char *restrict, ...); extern int vfprintf (FILE *restrict, const char *restrict, va_list); extern int vprintf (const char *restrict, va_list); -- cgit v1.1