[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-04-21 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

--- Comment #9 from Jakub Jelinek  ---
Tried now also:
--- gcc/gimplify.c.jj   2020-04-19 12:10:35.700627184 +0200
+++ gcc/gimplify.c  2020-04-21 12:24:41.444307978 +0200
@@ -886,7 +886,11 @@ mostly_copy_tree_r (tree *tp, int *walk_

   /* Cope with the statement expression extension.  */
   else if (code == STATEMENT_LIST)
-;
+{
+  if (!TREE_SIDE_EFFECTS (t))
+   if (tree nt = expr_single (t))
+ *tp = nt;
+}

   /* Leave the bulk of the work to copy_tree_r itself.  */
   else
--- gcc/testsuite/g++.dg/other/pr94340.C.jj 2020-04-21 12:15:35.855765641
+0200
+++ gcc/testsuite/g++.dg/other/pr94340.C2020-04-21 12:15:35.855765641
+0200
@@ -0,0 +1,16 @@
+// PR debug/94340
+// { dg-do compile }
+// { dg-options "-O -fcompare-debug" }
+
+struct D { int i; D (); ~D (); };
+D foo ();
+
+void
+bar (void)
+{
+  if (
+  ({
+ foo ();
+   }).i)
+return;
+}
--- gcc/testsuite/g++.dg/other/pr93786.C.jj 2020-04-21 12:15:35.855765641
+0200
+++ gcc/testsuite/g++.dg/other/pr93786.C2020-04-21 12:15:35.855765641
+0200
@@ -0,0 +1,11 @@
+// PR middle-end/93786
+// { dg-do compile }
+// { dg-options "-O2 -fcompare-debug" }
+
+struct S { virtual void bar (); };
+
+void
+foo (S *s)
+{
+  ({ s; })->bar ();
+}

and while it doesn't ICE, it fails -fcompare-debug on both tests.
So, I'm afraid I have no further ideas what to do here, everything I've tried
didn't work.
Alex, do you think you could have a look at this for GCC11?
Thanks.

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-03-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

--- Comment #8 from Jakub Jelinek  ---
Created attachment 48133
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48133=edit
gcc10-pr93786.patch

Untested fix.

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-03-04 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

Jakub Jelinek  changed:

   What|Removed |Added

   Target Milestone|8.4 |8.5

--- Comment #7 from Jakub Jelinek  ---
GCC 8.4.0 has been released, adjusting target milestone.

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-02-25 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

--- Comment #6 from Jakub Jelinek  ---
Tried:
--- gcc/gimplify.c.jj   2020-02-09 08:16:19.399581468 +0100
+++ gcc/gimplify.c  2020-02-25 13:46:51.166409528 +0100
@@ -886,7 +886,29 @@ mostly_copy_tree_r (tree *tp, int *walk_

   /* Cope with the statement expression extension.  */
   else if (code == STATEMENT_LIST)
-;
+{
+  if (!TREE_SIDE_EFFECTS (t))
+   {
+ tree nt = NULL_TREE;
+  tree_stmt_iterator i;
+ /* With -g we can get STATEMENT_LISTs without side-effects
+that contain some debug stmts and exactly one other stmt.
+"unshare" those by extracting the single other stmt in the
+copy.  */
+ for (i = tsi_start (t); !tsi_end_p (i); tsi_next ())
+   if (TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT)
+ ;
+   else if (nt)
+ break;
+   else
+ nt = tsi_stmt (i);
+ if (nt && tsi_end_p (i) && TREE_TYPE (t) == TREE_TYPE (nt))
+   {
+ *tp = nt;
+ mostly_copy_tree_r (tp, walk_subtrees, data);
+   }
+   }
+}

   /* Leave the bulk of the work to copy_tree_r itself.  */
   else
and while we don't ICE anymore on the testcase, it FAILs with -fcompare-debug:
-  _1 = s->_vptr.S;
+  struct S * retval.0;
+
+  # DEBUG BEGIN_STMT
+  # DEBUG BEGIN_STMT
+  retval.0 = s;
+  _1 = retval.0->_vptr.S;
gimple difference.

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-02-18 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

--- Comment #5 from Jakub Jelinek  ---
(In reply to rguent...@suse.de from comment #4)
> Could we make those sepcifc DEBUG_STMTS appear only later (during
> gimplification maybe?) and represent them as expression flags in the
> FEs?  That would avoid the stmt-list wrapping dependent on -g

A question for Alex I guess.

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-02-18 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

--- Comment #4 from rguenther at suse dot de  ---
On Tue, 18 Feb 2020, jakub at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786
> 
> --- Comment #3 from Jakub Jelinek  ---
> (In reply to Richard Biener from comment #2)
> > Hmm, but this destructive modification of something we don't unshare doesn't
> > work.  Either we have to always wrap statement lists but then we're back to
> > the compare-debug issue or we somehow fix the destructiveness on the
> > stmt list node itself - like not setting it's type to void or marking it
> > as having side-effects (why do we do this anyways, in voidify_wrapper_expr?
> > is that for debugging?), we'd also need to leave the final value in the
> > stmt list for a possible second gimplification round...
> > 
> > Maybe the best thing is to kill off the debug stmts when they would cause
> > a stmt list to appear and revert the previous fix.
> 
> We might kill them only in one of the two places (say keep in the argument and
> remove from the OBJ_TYPE_REF operand or vice versa), but we'd need some
> function that walks the non-TREE_SIDE_EFFECTS tree and looks for such
> STATEMENT_LISTs, as they might be wrapped in casts/whatever else that doesn't
> have side-effects.
> Another possibility would be do that in copy_if_shared_r or so (only handle 
> the
> !TREE_SIDE_EFFECTS STATEMENT_EXPR that contain only DEBUG_STMTs + one 
> non-debug
> one), but we wouldn't have control over which of the two or more copies gets 
> to
> keep the STATEMENT_LIST and which don't (well, it would be whatever we
> walk_tree first).

Could we make those sepcifc DEBUG_STMTS appear only later (during
gimplification maybe?) and represent them as expression flags in the
FEs?  That would avoid the stmt-list wrapping dependent on -g

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-02-18 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

--- Comment #3 from Jakub Jelinek  ---
(In reply to Richard Biener from comment #2)
> Hmm, but this destructive modification of something we don't unshare doesn't
> work.  Either we have to always wrap statement lists but then we're back to
> the compare-debug issue or we somehow fix the destructiveness on the
> stmt list node itself - like not setting it's type to void or marking it
> as having side-effects (why do we do this anyways, in voidify_wrapper_expr?
> is that for debugging?), we'd also need to leave the final value in the
> stmt list for a possible second gimplification round...
> 
> Maybe the best thing is to kill off the debug stmts when they would cause
> a stmt list to appear and revert the previous fix.

We might kill them only in one of the two places (say keep in the argument and
remove from the OBJ_TYPE_REF operand or vice versa), but we'd need some
function that walks the non-TREE_SIDE_EFFECTS tree and looks for such
STATEMENT_LISTs, as they might be wrapped in casts/whatever else that doesn't
have side-effects.
Another possibility would be do that in copy_if_shared_r or so (only handle the
!TREE_SIDE_EFFECTS STATEMENT_EXPR that contain only DEBUG_STMTs + one non-debug
one), but we wouldn't have control over which of the two or more copies gets to
keep the STATEMENT_LIST and which don't (well, it would be whatever we
walk_tree first).

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-02-18 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

Richard Biener  changed:

   What|Removed |Added

   Keywords||ice-on-valid-code
   Priority|P3  |P2
 CC||rguenth at gcc dot gnu.org

--- Comment #2 from Richard Biener  ---
Hmm, but this destructive modification of something we don't unshare doesn't
work.  Either we have to always wrap statement lists but then we're back to
the compare-debug issue or we somehow fix the destructiveness on the
stmt list node itself - like not setting it's type to void or marking it
as having side-effects (why do we do this anyways, in voidify_wrapper_expr?
is that for debugging?), we'd also need to leave the final value in the
stmt list for a possible second gimplification round...

Maybe the best thing is to kill off the debug stmts when they would cause
a stmt list to appear and revert the previous fix.

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-02-18 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

Martin Liška  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2020-02-18
 CC||marxin at gcc dot gnu.org
 Ever confirmed|0   |1

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-02-17 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

Jakub Jelinek  changed:

   What|Removed |Added

 CC||aoliva at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
The change makes the STATEMENT_LIST non-TREE_SIDE_EFFECTS, so that it doesn't
cause -fcompare-debug failures.  Unfortunately, for the OBJ_TYPE_REF the tree
is used twice, once in OBJ_TYPE_REF's second operand and once as the first
argument of the call; because of the missing TREE_SIDE_EFFECTs save_expr isn't
called on it (that would cause -fcompare-debug too), unshare_body doesn't
unshare STATEMENT_EXPRs and as gimplification is destructive, this means that
when we gimplify it once, we voidify it and destroy and the next time we
gimplify it we ICE because it has void type.
I'm afraid I don't really have a good solution here.

[Bug middle-end/93786] [8/9/10 Regression] gimplifier ICE with statement expression since r8-5526

2020-02-17 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93786

Jakub Jelinek  changed:

   What|Removed |Added

   Target Milestone|--- |8.4