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 tree-optimization/17697


Hi!

cpp_fold_builtin can fold builtins into something that no longer throws.
The following patch ought to fix this up.
Ok to commit?

I'd still appreciate if C++ frontend folks looked at duplicate_decls
and fixed the bogus clearing of TREE_NOTHROW flag if both the builtin
is throw () and declaration in program too.

2004-09-28  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/17697
	* tree-ssa-ccp.c (execute_fold_all_builtins): Update eh and cleanup
	cfg if needed.

	* g++.dg/opt/pr17697-1.C: New test.
	* g++.dg/opt/pr17697-2.C: New test.
	* g++.dg/opt/pr17697-3.C: New test.

--- gcc/tree-ssa-ccp.c.jj	2004-09-27 08:27:16.000000000 +0200
+++ gcc/tree-ssa-ccp.c	2004-09-28 21:37:10.277970688 +0200
@@ -2138,6 +2138,7 @@ convert_to_gimple_builtin (block_stmt_it
 static void
 execute_fold_all_builtins (void)
 {
+  bool cfg_changed = false;
   basic_block bb;
   FOR_EACH_BB (bb)
     {
@@ -2182,6 +2183,9 @@ execute_fold_all_builtins (void)
 		abort ();
 	    }
 	  modify_stmt (*stmtp);
+	  if (maybe_clean_eh_stmt (*stmtp)
+	      && tree_purge_dead_eh_edges (bb))
+	    cfg_changed = true;
 
 	  if (dump_file && (dump_flags & TDF_DETAILS))
 	    {
@@ -2191,6 +2195,10 @@ execute_fold_all_builtins (void)
 	    }
 	}
     }
+
+  /* Delete unreachable blocks.  */
+  if (cfg_changed)
+    cleanup_tree_cfg ();
 }
 
 
--- gcc/testsuite/g++.dg/opt/pr17697-3.C.jj	2004-09-28 12:21:46.000000000 +0200
+++ gcc/testsuite/g++.dg/opt/pr17697-3.C	2004-09-28 12:22:44.000000000 +0200
@@ -0,0 +1,28 @@
+// PR tree-optimization/17697
+// { dg-do run }
+// { dg-options "-O2" }
+
+extern "C" extern int strcmp (const char *s, const char *t);
+
+namespace A
+{
+  extern int strcmp (const char *s, const char *t);
+}
+
+inline int
+A::strcmp (const char *s, const char *t)
+{
+  return ::strcmp (s, t);
+}
+
+int
+foo (char *x)
+{
+  return A::strcmp ("", x);
+}
+
+int
+main ()
+{
+  return foo ("") != 0 || foo ("a") == 0;
+}
--- gcc/testsuite/g++.dg/opt/pr17697-1.C.jj	2004-09-28 12:21:46.000000000 +0200
+++ gcc/testsuite/g++.dg/opt/pr17697-1.C	2004-09-28 12:20:58.000000000 +0200
@@ -0,0 +1,32 @@
+// PR tree-optimization/17697
+// { dg-do run }
+// { dg-options "-O2" }
+
+extern "C"
+{
+  extern int strcmp (const char *s, const char *t) throw ()
+    __attribute__ ((pure));
+}
+
+namespace A
+{
+  extern int strcmp (const char *s, const char *t);
+}
+
+inline int
+A::strcmp (const char *s, const char *t)
+{
+  return ::strcmp (s, t);
+}
+
+int
+foo (char *x) throw ()
+{
+  return A::strcmp ("", x);
+}
+
+int
+main ()
+{
+  return foo ("") != 0 || foo ("a") == 0;
+}
--- gcc/testsuite/g++.dg/opt/pr17697-2.C.jj	2004-09-28 12:21:46.000000000 +0200
+++ gcc/testsuite/g++.dg/opt/pr17697-2.C	2004-09-28 12:22:05.000000000 +0200
@@ -0,0 +1,32 @@
+// PR tree-optimization/17697
+// { dg-do run }
+// { dg-options "-O2" }
+
+extern "C"
+{
+  extern int strcmp (const char *s, const char *t) throw ()
+    __attribute__ ((pure));
+}
+
+namespace A
+{
+  extern int strcmp (const char *s, const char *t) throw ();
+}
+
+inline int
+A::strcmp (const char *s, const char *t) throw ()
+{
+  return ::strcmp (s, t);
+}
+
+int
+foo (char *x) throw ()
+{
+  return A::strcmp ("", x);
+}
+
+int
+main ()
+{
+  return foo ("") != 0 || foo ("a") == 0;
+}

	Jakub


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