]> 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>
Sat, 26 Nov 2005 01:25:20 +0000 (01:25 +0000)
committerKaveh Ghazi <ghazi@gcc.gnu.org>
Sat, 26 Nov 2005 01:25:20 +0000 (01:25 +0000)
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

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c
gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c
gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c
gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c
gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c
gcc/testsuite/gcc.c-torture/execute/builtins/printf.c

index f26b24a24ce6a24bd5a29238aa564576b14449f2..654acf22846a6a6c36f1fd7afbabca57095532a9 100644 (file)
@@ -1,3 +1,11 @@
+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
index 6cca5fbe37e5b6a1c07f3166844790f67aaa45b6..c2866ce512653772ff3a4a7acf6d1a1481b4d1d3 100644 (file)
@@ -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
     {
index cfadb7e31427fee1bdf0bafbfe31256c00deaa04..99342b2e8716a89e015ab5043228e825c55d5778 100644 (file)
@@ -1,3 +1,12 @@
+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.
index 6b6e71b78f80ecbc6aa6f1e3074068d7a9738181..f7db2e0618ee6b48d72fd2f4e4a716e926a36240 100644 (file)
@@ -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", "");
 }
index beb8325fca5e5abac9059d9cf5ac0c1e23b13517..c2292a7818ca84740a54d895721264b26a90d793 100644 (file)
@@ -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);
+}
index 9274d5b643f88e05aa094aae8d8a517cc340faa4..93fa9736449ce4f27c43c9262b2479611063b972 100644 (file)
@@ -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;
index f32cf3a050b0110224aae46d32a474f969c231b9..a22db41d800e4f94afa44b3911bc42050208e2b6 100644 (file)
@@ -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;
+}
index e67003e1dd4b619e49f02fecd5c2d5d73c1c5ca6..2f8c133177c438f073cccd72fe198d2c9c329161 100644 (file)
@@ -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;
+}
index 0d01e544aa12ec190c4517cb738b7a90126194dc..e493f90b7cd452c9fb57f1b5537c63013d83fee9 100644 (file)
@@ -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", "");
 }