This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch]: fix PR middle-end/25022 failure to transform the unlocked stdio calls


This patch fixes PR middle-end/25022, a regression from gcc-3.3.

We're not transforming the "unlocked" stdio calls any more.  This
occurs because we lookup the replacement function in the array
implicit_built_in_decls in builtins.c.  The elements in that array are
set to null if the replacement is an "extension" builtin.  All
unlocked stdio functions are considered extensions, hence they are
never used.  We didn't have explicit tests for the unlocked calls in
the suite to I added a few to ensure this doesn't bitrot again.

Full bootstrap complete and the new testcases pass.  The rest of the
testsuite is running now.  Okay for mainline and 4.1 if there are no
regressions?

		Thanks,
		--Kaveh


2005-11-24  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.

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.

diff -rup orig/egcc-SVN20051123/gcc/builtins.c egcc-SVN20051123/gcc/builtins.c
--- orig/egcc-SVN20051123/gcc/builtins.c	2005-11-19 02:28:40.000000000 -0500
+++ egcc-SVN20051123/gcc/builtins.c	2005-11-24 10:25:09.000000000 -0500
@@ -4843,11 +4843,12 @@ expand_builtin_printf (tree exp, rtx tar
 		       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 ta
 		        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 a
 
   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 
 
   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
     {
diff -rup orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c
--- orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c	2005-11-03 10:37:47.000000000 -0500
+++ egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c	2005-11-24 10:25:09.000000000 -0500
@@ -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", "");
 }
diff -rup orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c
--- orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c	2005-11-03 10:37:47.000000000 -0500
+++ egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c	2005-11-24 10:25:09.000000000 -0500
@@ -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);
+}
diff -rup orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c
--- orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c	2005-11-03 10:37:47.000000000 -0500
+++ egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c	2005-11-24 10:25:09.000000000 -0500
@@ -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;
diff -rup orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c
--- orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c	2005-11-03 10:37:47.000000000 -0500
+++ egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c	2005-11-24 10:25:09.000000000 -0500
@@ -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;
+}
diff -rup orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c
--- orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c	2005-11-03 10:37:47.000000000 -0500
+++ egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c	2005-11-24 10:25:09.000000000 -0500
@@ -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;
+}
diff -rup orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c
--- orig/egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c	2005-11-03 10:37:47.000000000 -0500
+++ egcc-SVN20051123/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c	2005-11-24 10:44:59.000000000 -0500
@@ -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", "");
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]