public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR81007
@ 2017-06-08  9:16 Richard Biener
  2017-06-08 13:23 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2017-06-08  9:16 UTC (permalink / raw)
  To: gcc-patches


Folding during gimplification can invoke the devirt machinery which
doesn't deal with errorneous state.  Thus avoid ICEing by not folding
from gimplification in case we've seen errors.

Similarly do not build cgraph edges in those cases as that invokes
the devirt machinery as well (we stop compilation after lowering anyway
in case errors were reported).

The patch also fixes ordering of passes.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2017-06-08  Richard Biener  <rguenther@suse.de>

	PR middle-end/81007
	* gimplify.c (maybe_fold_stmt): Do not fold after errors.
	* cgraphbuild.c: Include diagnostic-core.h.
	(pass_build_cgraph_edges::gate): Add, do not run after errors.
	* passes.def (all_lowering_passes): Run pass_build_cgraph_edges
	last again.

	* g++.dg/pr81007.C: New testcase.

Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c	(revision 249003)
+++ gcc/gimplify.c	(working copy)
@@ -3067,6 +3067,10 @@ gimplify_arg (tree *arg_p, gimple_seq *p
 static bool
 maybe_fold_stmt (gimple_stmt_iterator *gsi)
 {
+  /* Do not fold if we may have invalid IL somewhere.  */
+  if (seen_error ())
+    return false;
+
   struct gimplify_omp_ctx *ctx;
   for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context)
     if ((ctx->region_type & (ORT_TARGET | ORT_PARALLEL | ORT_TASK)) != 0)
Index: gcc/cgraphbuild.c
===================================================================
--- gcc/cgraphbuild.c	(revision 249003)
+++ gcc/cgraphbuild.c	(working copy)
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.
 #include "gimple-walk.h"
 #include "ipa-utils.h"
 #include "except.h"
+#include "diagnostic-core.h"
 
 /* Context of record_reference.  */
 struct record_reference_ctx
@@ -305,6 +306,7 @@ public:
   /* opt_pass methods: */
   virtual unsigned int execute (function *);
 
+  virtual bool gate (function *) { return ! seen_error (); }
 }; // class pass_build_cgraph_edges
 
 unsigned int
Index: gcc/passes.def
===================================================================
--- gcc/passes.def	(revision 249003)
+++ gcc/passes.def	(working copy)
@@ -42,9 +42,9 @@ along with GCC; see the file COPYING3.
   NEXT_PASS (pass_build_cfg);
   NEXT_PASS (pass_warn_function_return);
   NEXT_PASS (pass_expand_omp);
-  NEXT_PASS (pass_build_cgraph_edges);
   NEXT_PASS (pass_sprintf_length, false);
   NEXT_PASS (pass_walloca, /*strict_mode_p=*/true);
+  NEXT_PASS (pass_build_cgraph_edges);
   TERMINATE_PASS_LIST (all_lowering_passes)
 
   /* Interprocedural optimization passes.  */
Index: gcc/testsuite/g++.dg/pr81007.C
===================================================================
--- gcc/testsuite/g++.dg/pr81007.C	(nonexistent)
+++ gcc/testsuite/g++.dg/pr81007.C	(working copy)
@@ -0,0 +1,14 @@
+// { dg-do compile }
+
+struct A
+{
+  A p; // { dg-error "incomplete" }
+  virtual void foo();
+};
+
+struct B : A {};
+
+void bar(B& b)
+{
+  b.foo();
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix PR81007
  2017-06-08  9:16 [PATCH] Fix PR81007 Richard Biener
@ 2017-06-08 13:23 ` Richard Biener
  2017-06-08 13:46   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2017-06-08 13:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

On Thu, 8 Jun 2017, Richard Biener wrote:

> 
> Folding during gimplification can invoke the devirt machinery which
> doesn't deal with errorneous state.  Thus avoid ICEing by not folding
> from gimplification in case we've seen errors.
> 
> Similarly do not build cgraph edges in those cases as that invokes
> the devirt machinery as well (we stop compilation after lowering anyway
> in case errors were reported).
> 
> The patch also fixes ordering of passes.
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Bah.  The cgraphbuild.c hunks cause

FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 111)
FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 111)
FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 63)
FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 82)
FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 90)
FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 90)
...

looks like the code processing queued cgraph nodes enqueues
further nodes by looking at callees and thus omp lowering
doesn't register split out functions with the cgraph?

No time to dig in right now.

But relying on the folding machinery not to ICE looks fragile to me.
Eventually, given the ICE is reached by cgraph edge building, we
have to plug that hole anyways.

Richard.

> Richard.
> 
> 2017-06-08  Richard Biener  <rguenther@suse.de>
> 
> 	PR middle-end/81007
> 	* gimplify.c (maybe_fold_stmt): Do not fold after errors.
> 	* cgraphbuild.c: Include diagnostic-core.h.
> 	(pass_build_cgraph_edges::gate): Add, do not run after errors.
> 	* passes.def (all_lowering_passes): Run pass_build_cgraph_edges
> 	last again.
> 
> 	* g++.dg/pr81007.C: New testcase.
> 
> Index: gcc/gimplify.c
> ===================================================================
> --- gcc/gimplify.c	(revision 249003)
> +++ gcc/gimplify.c	(working copy)
> @@ -3067,6 +3067,10 @@ gimplify_arg (tree *arg_p, gimple_seq *p
>  static bool
>  maybe_fold_stmt (gimple_stmt_iterator *gsi)
>  {
> +  /* Do not fold if we may have invalid IL somewhere.  */
> +  if (seen_error ())
> +    return false;
> +
>    struct gimplify_omp_ctx *ctx;
>    for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context)
>      if ((ctx->region_type & (ORT_TARGET | ORT_PARALLEL | ORT_TASK)) != 0)
> Index: gcc/cgraphbuild.c
> ===================================================================
> --- gcc/cgraphbuild.c	(revision 249003)
> +++ gcc/cgraphbuild.c	(working copy)
> @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.
>  #include "gimple-walk.h"
>  #include "ipa-utils.h"
>  #include "except.h"
> +#include "diagnostic-core.h"
>  
>  /* Context of record_reference.  */
>  struct record_reference_ctx
> @@ -305,6 +306,7 @@ public:
>    /* opt_pass methods: */
>    virtual unsigned int execute (function *);
>  
> +  virtual bool gate (function *) { return ! seen_error (); }
>  }; // class pass_build_cgraph_edges
>  
>  unsigned int
> Index: gcc/passes.def
> ===================================================================
> --- gcc/passes.def	(revision 249003)
> +++ gcc/passes.def	(working copy)
> @@ -42,9 +42,9 @@ along with GCC; see the file COPYING3.
>    NEXT_PASS (pass_build_cfg);
>    NEXT_PASS (pass_warn_function_return);
>    NEXT_PASS (pass_expand_omp);
> -  NEXT_PASS (pass_build_cgraph_edges);
>    NEXT_PASS (pass_sprintf_length, false);
>    NEXT_PASS (pass_walloca, /*strict_mode_p=*/true);
> +  NEXT_PASS (pass_build_cgraph_edges);
>    TERMINATE_PASS_LIST (all_lowering_passes)
>  
>    /* Interprocedural optimization passes.  */
> Index: gcc/testsuite/g++.dg/pr81007.C
> ===================================================================
> --- gcc/testsuite/g++.dg/pr81007.C	(nonexistent)
> +++ gcc/testsuite/g++.dg/pr81007.C	(working copy)
> @@ -0,0 +1,14 @@
> +// { dg-do compile }
> +
> +struct A
> +{
> +  A p; // { dg-error "incomplete" }
> +  virtual void foo();
> +};
> +
> +struct B : A {};
> +
> +void bar(B& b)
> +{
> +  b.foo();
> +}
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix PR81007
  2017-06-08 13:23 ` Richard Biener
@ 2017-06-08 13:46   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2017-06-08 13:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

On Thu, 8 Jun 2017, Richard Biener wrote:

> On Thu, 8 Jun 2017, Richard Biener wrote:
> 
> > 
> > Folding during gimplification can invoke the devirt machinery which
> > doesn't deal with errorneous state.  Thus avoid ICEing by not folding
> > from gimplification in case we've seen errors.
> > 
> > Similarly do not build cgraph edges in those cases as that invokes
> > the devirt machinery as well (we stop compilation after lowering anyway
> > in case errors were reported).
> > 
> > The patch also fixes ordering of passes.
> > 
> > Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> 
> Bah.  The cgraphbuild.c hunks cause
> 
> FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 111)
> FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 111)
> FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 63)
> FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 82)
> FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 90)
> FAIL: g++.dg/gomp/linear-2.C  -std=gnu++11  (test for errors, line 90)
> ...
> 
> looks like the code processing queued cgraph nodes enqueues
> further nodes by looking at callees and thus omp lowering
> doesn't register split out functions with the cgraph?
> 
> No time to dig in right now.
> 
> But relying on the folding machinery not to ICE looks fragile to me.
> Eventually, given the ICE is reached by cgraph edge building, we
> have to plug that hole anyways.

So I'm testing the following instead.

Richard.

2017-06-08  Richard Biener  <rguenther@suse.de>

	PR middle-end/81007
	* ipa-polymorphic-call.c
	(ipa_polymorphic_call_context::restrict_to_inner_class):
	Skip FIELD_DECLs with error_mark_node type.
	* passes.def (all_lowering_passes): Run pass_build_cgraph_edges
	last again.

	* g++.dg/pr81007.C: New testcase.

Index: gcc/ipa-polymorphic-call.c
===================================================================
--- gcc/ipa-polymorphic-call.c	(revision 249003)
+++ gcc/ipa-polymorphic-call.c	(working copy)
@@ -267,7 +267,8 @@ ipa_polymorphic_call_context::restrict_t
 	{
 	  for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
 	    {
-	      if (TREE_CODE (fld) != FIELD_DECL)
+	      if (TREE_CODE (fld) != FIELD_DECL
+		  || TREE_TYPE (fld) == error_mark_node)
 		continue;
 
 	      pos = int_bit_position (fld);
Index: gcc/passes.def
===================================================================
--- gcc/passes.def	(revision 249003)
+++ gcc/passes.def	(working copy)
@@ -42,9 +42,9 @@ along with GCC; see the file COPYING3.
   NEXT_PASS (pass_build_cfg);
   NEXT_PASS (pass_warn_function_return);
   NEXT_PASS (pass_expand_omp);
-  NEXT_PASS (pass_build_cgraph_edges);
   NEXT_PASS (pass_sprintf_length, false);
   NEXT_PASS (pass_walloca, /*strict_mode_p=*/true);
+  NEXT_PASS (pass_build_cgraph_edges);
   TERMINATE_PASS_LIST (all_lowering_passes)
 
   /* Interprocedural optimization passes.  */
Index: gcc/testsuite/g++.dg/pr81007.C
===================================================================
--- gcc/testsuite/g++.dg/pr81007.C	(nonexistent)
+++ gcc/testsuite/g++.dg/pr81007.C	(working copy)
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-options "-O2" }
+
+struct A
+{
+  A p; // { dg-error "incomplete" }
+  virtual void foo();
+};
+
+struct B : A {};
+
+void bar(B& b)
+{
+  b.foo();
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-08 13:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-08  9:16 [PATCH] Fix PR81007 Richard Biener
2017-06-08 13:23 ` Richard Biener
2017-06-08 13:46   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).