[Patch]: Fix PR middle-end/25158

Kaveh R. Ghazi ghazi@caipclassic.rutgers.edu
Wed Nov 30 17:34:00 GMT 2005


I believe this patch fixes PR middle-end/25158.  We're not eliminating
"unlocked" stdio calls with empty output strings on hpux.

Hpux doesn't have fputc_unlocked, and clears out that as a possible
replacement function.  As I noted in the PR, we have to defer the
checks in fold_builtin_fputs for missing replacement functions in
order to reach the code which eliminates empty output strings.  (All
other builtins seem to defer the check this way also.)

Tested with a full bootstrap on i686-unknown-linux-gnu, no
regressions.  I also built a cross-compiler targetted to
hppa2.0w-hp-hpux11.11 and compiled a testcase with empty strings
passed to fprintf_unlocked and fputs_unlocked and ensured they were
optimized away.

I'm going to wait for confirmation from Dave that everything's okay on
a native hpux test.

Pending that, okay for mainline and 4.1?

		Thanks,
		--Kaveh


2005-11-29  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	PR middle-end/25158
	* builtins.c (fold_builtin_fputs): Defer check for missing
	replacement functions.

diff -rup orig/egcc-SVN20051129/gcc/builtins.c egcc-SVN20051129/gcc/builtins.c
--- orig/egcc-SVN20051129/gcc/builtins.c	2005-11-29 00:18:53.000000000 -0500
+++ egcc-SVN20051129/gcc/builtins.c	2005-11-29 16:57:20.000000000 -0500
@@ -9639,9 +9639,8 @@ fold_builtin_fputs (tree arglist, bool i
   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 (!ignore || !fn_fputc || !fn_fwrite)
+  /* If the return value is used, don't do the transformation.  */
+  if (!ignore)
     return 0;
 
   /* Verify the arguments in the original call.  */
@@ -9703,6 +9702,11 @@ fold_builtin_fputs (tree arglist, bool i
       gcc_unreachable ();
     }
 
+  /* If the replacement _DECL isn't initialized, don't do the
+     transformation.  */
+  if (!fn)
+    return 0;
+
   /* These optimizations are only performed when the result is ignored,
      hence there's no need to cast the result to integer_type_node.  */
   return build_function_call_expr (fn, arglist);



More information about the Gcc-patches mailing list