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 devirtualization ICE (PR tree-optimization/59622, take 3)


Hi!

On Fri, Jan 03, 2014 at 11:33:50AM +0100, Jakub Jelinek wrote:
> On Fri, Jan 03, 2014 at 11:24:53AM +0100, Richard Biener wrote:

Anyway, back to the original patch, so do you prefer something like
this instead?  I.e. handle only __builtin_unreachable and
__cxa_pure_virtual specially, and not devirt for fold_stmt_inplace?

2014-01-07  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/59622
	* gimple-fold.c (gimple_fold_call): Fix a typo in message.  Handle
	__cxa_pure_virtual similarly to __builtin_unreachable.  Don't
	devirtualize for inplace at all.

	* g++.dg/opt/pr59622-2.C: New test.

--- gcc/gimple-fold.c.jj	2014-01-03 11:40:57.247320424 +0100
+++ gcc/gimple-fold.c	2014-01-07 18:15:00.352601812 +0100
@@ -1167,7 +1167,7 @@ gimple_fold_call (gimple_stmt_iterator *
                                                  (OBJ_TYPE_REF_EXPR (callee)))))
 	    {
 	      fprintf (dump_file,
-		       "Type inheritnace inconsistent devirtualization of ");
+		       "Type inheritance inconsistent devirtualization of ");
 	      print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
 	      fprintf (dump_file, " to ");
 	      print_generic_expr (dump_file, callee, TDF_SLIM);
@@ -1177,26 +1177,35 @@ gimple_fold_call (gimple_stmt_iterator *
 	  gimple_call_set_fn (stmt, OBJ_TYPE_REF_EXPR (callee));
 	  changed = true;
 	}
-      else if (flag_devirtualize && virtual_method_call_p (callee))
+      else if (flag_devirtualize && !inplace && virtual_method_call_p (callee))
 	{
 	  bool final;
 	  vec <cgraph_node *>targets
 	    = possible_polymorphic_call_targets (callee, &final);
 	  if (final && targets.length () <= 1)
 	    {
+	      tree fndecl;
 	      if (targets.length () == 1)
+		fndecl = targets[0]->decl;
+	      else
+		fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE);
+
+	      /* If fndecl (like __builtin_unreachable or
+		 __cxa_pure_virtual) takes no arguments, doesn't have
+		 return value and is noreturn, just add the call before
+		 stmt and DCE will do it's job later on.  */
+	      if (TREE_THIS_VOLATILE (fndecl)
+		  && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl)))
+		  && TYPE_ARG_TYPES (TREE_TYPE (fndecl)) == void_list_node)
 		{
-		  gimple_call_set_fndecl (stmt, targets[0]->decl);
-		  changed = true;
-		}
-	      else if (!inplace)
-		{
-		  tree fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE);
 		  gimple new_stmt = gimple_build_call (fndecl, 0);
 		  gimple_set_location (new_stmt, gimple_location (stmt));
 		  gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
 		  return true;
 		}
+
+	      gimple_call_set_fndecl (stmt, fndecl);
+	      changed = true;
 	    }
 	}
     }
--- gcc/testsuite/g++.dg/opt/pr59622-2.C.jj	2014-01-07 18:10:45.435904909 +0100
+++ gcc/testsuite/g++.dg/opt/pr59622-2.C	2014-01-07 18:10:45.435904909 +0100
@@ -0,0 +1,21 @@
+// PR tree-optimization/59622
+// { dg-do compile }
+// { dg-options "-O2" }
+
+namespace
+{
+  struct A
+  {
+    A () {}
+    virtual A *bar (int) = 0;
+    A *baz (int x) { return bar (x); }
+  };
+}
+
+A *a;
+
+void
+foo ()
+{
+  a->baz (0);
+}


	Jakub


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