+2005-11-25 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ PR middle-end/25022
+ * builtins.c (expand_builtin_printf, expand_builtin_fprintf,
+ fold_builtin_fputs, fold_builtin_printf, fold_builtin_fprintf):
+ Lookup the explicit replacement functions for any unlocked
+ stdio builtin transformations.
+
2005-11-25 Hans-Peter Nilsson <hp@axis.com>
* config/cris/cris.md ("reload_out<mode>"): Mark operand 2 as
bool unlocked)
{
tree arglist = TREE_OPERAND (exp, 1);
- tree fn_putchar = unlocked
- ? implicit_built_in_decls[BUILT_IN_PUTCHAR_UNLOCKED]
- : implicit_built_in_decls[BUILT_IN_PUTCHAR];
- tree fn_puts = unlocked ? implicit_built_in_decls[BUILT_IN_PUTS_UNLOCKED]
- : implicit_built_in_decls[BUILT_IN_PUTS];
+ /* If we're using an unlocked function, assume the other unlocked
+ functions exist explicitly. */
+ tree const fn_putchar = unlocked ? built_in_decls[BUILT_IN_PUTCHAR_UNLOCKED]
+ : implicit_built_in_decls[BUILT_IN_PUTCHAR];
+ tree const fn_puts = unlocked ? built_in_decls[BUILT_IN_PUTS_UNLOCKED]
+ : implicit_built_in_decls[BUILT_IN_PUTS];
const char *fmt_str;
tree fn, fmt, arg;
bool unlocked)
{
tree arglist = TREE_OPERAND (exp, 1);
- tree fn_fputc = unlocked ? implicit_built_in_decls[BUILT_IN_FPUTC_UNLOCKED]
- : implicit_built_in_decls[BUILT_IN_FPUTC];
- tree fn_fputs = unlocked ? implicit_built_in_decls[BUILT_IN_FPUTS_UNLOCKED]
- : implicit_built_in_decls[BUILT_IN_FPUTS];
+ /* If we're using an unlocked function, assume the other unlocked
+ functions exist explicitly. */
+ tree const fn_fputc = unlocked ? built_in_decls[BUILT_IN_FPUTC_UNLOCKED]
+ : implicit_built_in_decls[BUILT_IN_FPUTC];
+ tree const fn_fputs = unlocked ? built_in_decls[BUILT_IN_FPUTS_UNLOCKED]
+ : implicit_built_in_decls[BUILT_IN_FPUTS];
const char *fmt_str;
tree fn, fmt, fp, arg;
fold_builtin_fputs (tree arglist, bool ignore, bool unlocked, tree len)
{
tree fn;
- tree fn_fputc = unlocked ? implicit_built_in_decls[BUILT_IN_FPUTC_UNLOCKED]
+ /* If we're using an unlocked function, assume the other unlocked
+ functions exist explicitly. */
+ tree const fn_fputc = unlocked ? built_in_decls[BUILT_IN_FPUTC_UNLOCKED]
: implicit_built_in_decls[BUILT_IN_FPUTC];
- tree fn_fwrite = unlocked ? implicit_built_in_decls[BUILT_IN_FWRITE_UNLOCKED]
+ tree const fn_fwrite = unlocked ? built_in_decls[BUILT_IN_FWRITE_UNLOCKED]
: implicit_built_in_decls[BUILT_IN_FWRITE];
/* If the return value is used, or the replacement _DECL isn't
if (fcode == BUILT_IN_PRINTF_UNLOCKED)
{
- fn_putchar = implicit_built_in_decls[BUILT_IN_PUTCHAR_UNLOCKED];
- fn_puts = implicit_built_in_decls[BUILT_IN_PUTS_UNLOCKED];
+ /* If we're using an unlocked function, assume the other
+ unlocked functions exist explicitly. */
+ fn_putchar = built_in_decls[BUILT_IN_PUTCHAR_UNLOCKED];
+ fn_puts = built_in_decls[BUILT_IN_PUTS_UNLOCKED];
}
else
{
if (fcode == BUILT_IN_FPRINTF_UNLOCKED)
{
- fn_fputc = implicit_built_in_decls[BUILT_IN_FPUTC_UNLOCKED];
- fn_fputs = implicit_built_in_decls[BUILT_IN_FPUTS_UNLOCKED];
+ /* If we're using an unlocked function, assume the other
+ unlocked functions exist explicitly. */
+ fn_fputc = built_in_decls[BUILT_IN_FPUTC_UNLOCKED];
+ fn_fputs = built_in_decls[BUILT_IN_FPUTS_UNLOCKED];
}
else
{
+2005-11-25 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * gcc.c-torture/execute/builtins/fprintf.c,
+ gcc.c-torture/execute/builtins/fputs-lib.c,
+ gcc.c-torture/execute/builtins/fputs.c,
+ gcc.c-torture/execute/builtins/lib/fprintf.c,
+ gcc.c-torture/execute/builtins/lib/printf.c,
+ gcc.c-torture/execute/builtins/printf.c: Test the unlocked style.
+
2005-11-25 J"orn Rennecke <joern.rennecke@st.com>
* gcc.dg/20050922-2.c: New test.
Written by Kaveh R. Ghazi, 1/7/2001. */
#include <stdio.h>
+extern int fprintf_unlocked (FILE *, const char *, ...);
extern void abort(void);
void
const char *const s1 = "hello world";
const char *const s2[] = { s1, 0 }, *const*s3;
+ fprintf (*s_ptr, "");
+ fprintf (*s_ptr, "%s", "");
fprintf (*s_ptr, "%s", "hello");
fprintf (*s_ptr, "%s", "\n");
fprintf (*s_ptr, "%s", *s2);
/* Test at least one instance of the __builtin_ style. We do this
to ensure that it works and that the prototype is correct. */
__builtin_fprintf (*s_ptr, "%s", "hello world\n");
+ /* Check the unlocked style, these evaluate to nothing to avoid
+ problems on systems without the unlocked functions. */
+ fprintf_unlocked (*s_ptr, "");
+ __builtin_fprintf_unlocked (*s_ptr, "");
+ fprintf_unlocked (*s_ptr, "%s", "");
+ __builtin_fprintf_unlocked (*s_ptr, "%s", "");
}
return n > r ? EOF : 0;
}
+/* Locking stdio doesn't matter for the purposes of this test. */
+int
+fputs_unlocked(const char *string, FILE *stream)
+{
+ return fputs (string, stream);
+}
prototypes are set correctly too. */
__builtin_fputc ('\n', *s_ptr);
__builtin_fwrite ("hello\n", 1, 6, *s_ptr);
+ /* Check the unlocked style, these evaluate to nothing to avoid
+ problems on systems without the unlocked functions. */
+ fputs_unlocked ("", *s_ptr);
+ __builtin_fputs_unlocked ("", *s_ptr);
/* Check side-effects in conditional expression. */
s_ptr = s_array;
va_end (ap);
return r;
}
+
+/* Locking stdio doesn't matter for the purposes of this test. */
+int
+fprintf_unlocked (FILE *fp, const char *string, ...)
+{
+ va_list ap;
+ int r;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+ va_start (ap, string);
+ r = vfprintf (fp, string, ap);
+ va_end (ap);
+ return r;
+}
return r;
}
+
+/* Locking stdio doesn't matter for the purposes of this test. */
+int
+printf_unlocked (const char *string, ...)
+{
+ va_list ap;
+ int r;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+ va_start (ap, string);
+ r = vprintf (string, ap);
+ va_end (ap);
+ return r;
+}
Written by Kaveh R. Ghazi, 12/4/2000. */
extern int printf (const char *, ...);
+extern int printf_unlocked (const char *, ...);
extern void abort(void);
void
if (s3 != s2+1 || *s3 != 0)
abort();
+ printf ("");
+ printf ("%s", "");
printf ("\n");
+ printf ("%s", "\n");
printf ("hello world\n");
+ printf ("%s", "hello world\n");
/* Test at least one instance of the __builtin_ style. We do this
to ensure that it works and that the prototype is correct. */
prototypes are set correctly too. */
__builtin_putchar ('\n');
__builtin_puts ("hello");
+ /* Check the unlocked style, these evaluate to nothing to avoid
+ problems on systems without the unlocked functions. */
+ printf_unlocked ("");
+ __builtin_printf_unlocked ("");
+ printf_unlocked ("%s", "");
+ __builtin_printf_unlocked ("%s", "");
}