Commit 7e7b53aa by Kaveh R. Ghazi Committed by Kaveh Ghazi

re PR middle-end/25022 (failure to transform the unlocked stdio calls)

	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.

testsuite:
	* 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.

From-SVN: r107535
parent 8712ef1a
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
......
......@@ -4843,11 +4843,12 @@ expand_builtin_printf (tree exp, rtx target, enum machine_mode mode,
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;
......@@ -4949,10 +4950,12 @@ expand_builtin_fprintf (tree exp, rtx target, enum machine_mode mode,
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;
......@@ -9611,9 +9614,11 @@ tree
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
......@@ -10752,8 +10757,10 @@ fold_builtin_printf (tree fndecl, tree arglist, bool ignore,
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
{
......@@ -10908,8 +10915,10 @@ fold_builtin_fprintf (tree fndecl, tree arglist, bool ignore,
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.
......@@ -6,6 +6,7 @@
Written by Kaveh R. Ghazi, 1/7/2001. */
#include <stdio.h>
extern int fprintf_unlocked (FILE *, const char *, ...);
extern void abort(void);
void
......@@ -15,6 +16,8 @@ main_test (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);
......@@ -49,4 +52,10 @@ main_test (void)
/* 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", "");
}
......@@ -16,3 +16,9 @@ fputs(const char *string, FILE *stream)
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);
}
......@@ -49,6 +49,10 @@ main_test(void)
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;
......
......@@ -17,3 +17,19 @@ fprintf (FILE *fp, const char *string, ...)
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;
}
......@@ -18,3 +18,19 @@ printf (const char *string, ...)
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;
}
......@@ -6,6 +6,7 @@
Written by Kaveh R. Ghazi, 12/4/2000. */
extern int printf (const char *, ...);
extern int printf_unlocked (const char *, ...);
extern void abort(void);
void
......@@ -28,8 +29,12 @@ main_test (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. */
......@@ -38,4 +43,10 @@ main_test (void)
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", "");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment