]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/25022 (failure to transform the unlocked stdio calls)
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>
Sun, 4 Dec 2005 01:37:23 +0000 (01:37 +0000)
committerKaveh Ghazi <ghazi@gcc.gnu.org>
Sun, 4 Dec 2005 01:37:23 +0000 (01:37 +0000)
2005-12-03  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

PR middle-end/25022
* builtins.c (expand_builtin_fputs, expand_builtin_printf,
expand_builtin_fprintf): Lookup the explicit replacement functions
for any unlocked stdio builtin transformations.

* builtins.c (expand_builtin_fputs): Defer check for missing
replacement functions.

testsuite:
* gcc.c-torture/execute/stdio-opt-1.c,
gcc.c-torture/execute/stdio-opt-2.c,
gcc.c-torture/execute/stdio-opt-3.c: Test the unlocked style.

From-SVN: r108010

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c
gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c
gcc/testsuite/gcc.c-torture/execute/stdio-opt-3.c

index 099f12bed4e1defb0f370cdce6e019b6357c8707..f52da64006f93c9dde9848373f6c892a9b7b798b 100644 (file)
@@ -1,3 +1,13 @@
+2005-12-03  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       PR middle-end/25022
+       * builtins.c (expand_builtin_fputs, expand_builtin_printf,
+       expand_builtin_fprintf): Lookup the explicit replacement functions
+       for any unlocked stdio builtin transformations.
+
+       * builtins.c (expand_builtin_fputs): Defer check for missing
+       replacement functions.
+
 2005-12-02  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/24103
index a3e069e4baca087d2dde7d2d028c96c69b418094..2931684a9a62478044cc545238c1a3584e98d318 100644 (file)
@@ -4329,14 +4329,15 @@ static rtx
 expand_builtin_fputs (tree arglist, rtx target, bool unlocked)
 {
   tree len, 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
-     initialized, don't do the transformation.  */
-  if (target != const0_rtx || !fn_fputc || !fn_fwrite)
+  /* If the return value is used, don't do the transformation.  */
+  if (target != const0_rtx)
     return 0;
 
   /* Verify the arguments in the original call.  */
@@ -4397,6 +4398,11 @@ expand_builtin_fputs (tree arglist, rtx target, bool unlocked)
       abort ();
     }
 
+  /* If the replacement _DECL isn't initialized, don't do the
+     transformation.  */
+  if (!fn)
+    return 0;
+
   return expand_expr (build_function_call_expr (fn, arglist),
                      const0_rtx, VOIDmode, EXPAND_NORMAL);
 }
@@ -4651,11 +4657,12 @@ static rtx
 expand_builtin_printf (tree arglist, rtx target, enum machine_mode mode,
                       bool unlocked)
 {
-  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;
 
@@ -4754,10 +4761,12 @@ static rtx
 expand_builtin_fprintf (tree arglist, rtx target, enum machine_mode mode,
                        bool unlocked)
 {
-  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;
 
index 9d91df6d96824970101f5c2f9782e4aa74d4c2c8..b3c6d9755ab5b9fea0ec170b71df595408812fe4 100644 (file)
@@ -1,3 +1,9 @@
+2005-12-03  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * gcc.c-torture/execute/stdio-opt-1.c,
+       gcc.c-torture/execute/stdio-opt-2.c,
+       gcc.c-torture/execute/stdio-opt-3.c: Test the unlocked style.
+
 2005-12-03  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * gcc.dg/loop-3.c: Skip if ix86 and -m64.
index 8cfb4ebe08ea30da0e99ba1cc1fa3236c9add18e..9029147f0d0a26c3d85cb085bd05dfbc55620fc2 100644 (file)
@@ -52,6 +52,10 @@ int main()
      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;
@@ -75,4 +79,16 @@ fputs(const char *string, FILE *stream)
 {
   abort();
 }
+
+#endif
+
+/* Locking stdio doesn't matter for the purposes of this test.  */
+static int __attribute__ ((__noinline__))
+fputs_unlocked(const char *string, FILE *stream)
+{
+#ifdef __OPTIMIZE__
+  abort();
+#else
+  return fputs (string, stream);
 #endif
+}
index 833017ee5472091f722ce23ac73d5f77c452731d..fe9d9c12c8e17ba287354fff43f0d076bee01a6b 100644 (file)
@@ -5,7 +5,10 @@
 
    Written by Kaveh R. Ghazi, 12/4/2000.  */
 
+#include <stdio.h>
+#include <stdarg.h>
 extern int printf (const char *, ...);
+extern int printf_unlocked (const char *, ...);
 extern void abort(void);
 
 int main()
@@ -27,6 +30,7 @@ int main()
   if (s3 != s2+1 || *s3 != 0)
     abort();
   
+  printf ("");
   printf ("\n");
   printf ("hello world\n");
   
@@ -37,6 +41,10 @@ int main()
      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 ("");
 
   return 0;
 }
@@ -52,3 +60,19 @@ printf (const char *string, ...)
   abort();
 }
 #endif
+
+/* Locking stdio doesn't matter for the purposes of this test.  */
+static int __attribute__ ((__noinline__))
+printf_unlocked (const char *string, ...)
+{
+#ifdef __OPTIMIZE__
+  abort();
+#else
+  va_list ap;
+  int r;
+  va_start (ap, string);
+  r = vprintf (string, ap);
+  va_end (ap);
+  return r;
+#endif
+}
index afc76a2171670a03dc2f0762d51d4f44dd86bbc5..9fe00178df8cd9a0dd0436cb5eb5eba05d669e0e 100644 (file)
@@ -6,6 +6,8 @@
    Written by Kaveh R. Ghazi, 1/7/2001.  */
 
 #include <stdio.h>
+#include <stdarg.h>
+extern int fprintf_unlocked (FILE *, const char *, ...);
 extern int fprintf (FILE *, const char *, ...);
 extern void abort(void);
 
@@ -15,6 +17,8 @@ int main()
   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,6 +53,12 @@ int main()
   /* 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 0;
 }
@@ -64,3 +74,19 @@ fprintf (FILE *stream, const char *string, ...)
   abort();
 }
 #endif
+
+/* Locking stdio doesn't matter for the purposes of this test.  */
+static int __attribute__ ((__noinline__))
+fprintf_unlocked (FILE *stream, const char *string, ...)
+{
+#ifdef __OPTIMIZE__
+  abort();
+#else
+  va_list ap;
+  int r;
+  va_start (ap, string);
+  r = vfprintf (stream, string, ap);
+  va_end (ap);
+  return r;
+#endif
+}