Bug 91270 - [10 Regression] ICE in verify_use at gcc/tree-ssa.c:883 since r273791
Summary: [10 Regression] ICE in verify_use at gcc/tree-ssa.c:883 since r273791
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P1 normal
Target Milestone: 10.0
Assignee: Martin Liška
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2019-07-27 07:34 UTC by David Binderman
Modified: 2019-07-30 11:01 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 9.1.0
Known to fail: 10.0
Last reconfirmed: 2019-07-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2019-07-27 07:34:23 UTC
For this C++ code:

class a {
public:
  ~a();
};
long b;
void c() {
  a *d = new a[b];
  delete[] d;
}

compiled with flag -O2 on recent gcc trunk, does this:

$ /home/dcb/gcc/results/bin/gcc -c -O2 bug538.cc
during GIMPLE pass: cddce
bug538.cc: In function ‘void c()’:
bug538.cc:9:1: internal compiler error: Segmentation fault
    9 | }
      | ^
0xfbaf6f crash_signal
	../../trunk/gcc/toplev.c:326
0x11c9455 verify_use
	../../trunk/gcc/tree-ssa.c:884
0x11cd940 verify_ssa(bool, bool)
	../../trunk/gcc/tree-ssa.c:1161
0xee3b05 execute_function_todo
	../../trunk/gcc/passes.c:1970

The problem seems to exist between revisions 273750
and 273800.
Comment 1 Marc Glisse 2019-07-27 08:07:03 UTC
Does this patch fix it for you?
https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01644.html
Comment 2 David Binderman 2019-07-27 18:21:40 UTC
(In reply to Marc Glisse from comment #1)
> Does this patch fix it for you?
> https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01644.html

Sadly, no.

bug538.cc
script.cc: In member function ‘void CInputScript::ParseDefineFont()’:
script.cc:1117:6: error: missing definition
script.cc:1117:6: error: no immediate_use list
for SSA_NAME: _37 in statement:
# .MEM_95 = VDEF <.MEM_49>
operator delete [] (_69, _37);
during GIMPLE pass: dce
script.cc:1117:6: internal compiler error: verify_ssa failed
0x1075d8c verify_ssa(bool, bool)
	../../trunk/gcc/tree-ssa.c:1208

I've done one pass of range reduction and 273775 seems fine,
so range is 273775 to 273800.
Comment 3 David Binderman 2019-07-27 19:05:10 UTC
273788 seems fine, so range is 273788 to 273800.
Comment 4 Martin Liška 2019-07-28 08:29:11 UTC
It's mine. I'm working on a patch.
Comment 5 Martin Liška 2019-07-28 08:50:27 UTC
I've got a patch candidate:

diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index cf507fa0453..bdaad09ef35 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -1294,6 +1294,21 @@ eliminate_unnecessary_stmts (void)
 		      && !gimple_plf (def_stmt, STMT_NECESSARY))
 		    gimple_set_plf (stmt, STMT_NECESSARY, false);
 		}
+
+	      /* Delete operator has 2 arguments, where the second argument is
+		 size of the deallocated memory.  */
+	      if (is_gimple_call (stmt)
+		  && gimple_call_operator_delete_p (as_a <gcall *> (stmt)))
+		{
+		  tree ptr = gimple_call_arg (stmt, 1);
+		  if (TREE_CODE (ptr) == SSA_NAME)
+		    {
+		      gimple *def_stmt = SSA_NAME_DEF_STMT (ptr);
+		      if (!gimple_nop_p (def_stmt)
+			  && !gimple_plf (def_stmt, STMT_NECESSARY))
+			gimple_set_plf (stmt, STMT_NECESSARY, false);
+		    }
+		}
 	    }
 
 	  /* If GSI is not necessary then remove it.  */

I'll finish it tomorrow morning and send it to mailing list.
Comment 6 Martin Liška 2019-07-28 08:53:14 UTC
(In reply to Martin Liška from comment #5)
> I've got a patch candidate:
> 
> diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
> index cf507fa0453..bdaad09ef35 100644
> --- a/gcc/tree-ssa-dce.c
> +++ b/gcc/tree-ssa-dce.c
> @@ -1294,6 +1294,21 @@ eliminate_unnecessary_stmts (void)
>  		      && !gimple_plf (def_stmt, STMT_NECESSARY))
>  		    gimple_set_plf (stmt, STMT_NECESSARY, false);
>  		}
> +
> +	      /* Delete operator has 2 arguments, where the second argument is
> +		 size of the deallocated memory.  */
> +	      if (is_gimple_call (stmt)
> +		  && gimple_call_operator_delete_p (as_a <gcall *> (stmt)))
> +		{
> +		  tree ptr = gimple_call_arg (stmt, 1);
> +		  if (TREE_CODE (ptr) == SSA_NAME)
> +		    {
> +		      gimple *def_stmt = SSA_NAME_DEF_STMT (ptr);
> +		      if (!gimple_nop_p (def_stmt)
> +			  && !gimple_plf (def_stmt, STMT_NECESSARY))
> +			gimple_set_plf (stmt, STMT_NECESSARY, false);
> +		    }
> +		}
>  	    }
>  
>  	  /* If GSI is not necessary then remove it.  */
> 
> I'll finish it tomorrow morning and send it to mailing list.

This patch will be better:

diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index cf507fa0453..04338a67181 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -1294,6 +1294,20 @@ eliminate_unnecessary_stmts (void)
 		      && !gimple_plf (def_stmt, STMT_NECESSARY))
 		    gimple_set_plf (stmt, STMT_NECESSARY, false);
 		}
+
+	      /* Some delete operators have 2 arguments, where the second argument is
+		 size of the deallocated memory.  */
+	      if (gimple_call_num_args (stmt) == 2)
+		{
+		  tree ptr = gimple_call_arg (stmt, 1);
+		  if (TREE_CODE (ptr) == SSA_NAME)
+		    {
+		      gimple *def_stmt = SSA_NAME_DEF_STMT (ptr);
+		      if (!gimple_nop_p (def_stmt)
+			  && !gimple_plf (def_stmt, STMT_NECESSARY))
+			gimple_set_plf (stmt, STMT_NECESSARY, false);
+		    }
+		}
 	    }
 
 	  /* If GSI is not necessary then remove it.  */
Comment 7 Martin Liška 2019-07-28 14:58:20 UTC
Patch has been just sent:
https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01708.html
Comment 8 Martin Liška 2019-07-30 11:01:14 UTC
Author: marxin
Date: Tue Jul 30 11:00:35 2019
New Revision: 273906

URL: https://gcc.gnu.org/viewcvs?rev=273906&root=gcc&view=rev
Log:
Mark 2nd argument of delete operator as needed (PR tree-optimization/91270).

2019-07-30  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/91270
	* tree-ssa-dce.c (propagate_necessity): Mark 2nd argument
	of delete operator as needed.
2019-07-30  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/91270
	* g++.dg/torture/pr91270.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr91270.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-dce.c
Comment 9 Martin Liška 2019-07-30 11:01:36 UTC
Fixed.