Bug 89084 - [9 Regression] ICE in get_partitioning_class, at symtab.c:1892
Summary: [9 Regression] ICE in get_partitioning_class, at symtab.c:1892
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 9.0
Assignee: Jakub Jelinek
URL:
Keywords: ice-checking, ice-on-valid-code, lto
: 70854 82009 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-01-28 07:18 UTC by Arseny Solokha
Modified: 2019-08-30 11:36 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-01-31 00:00:00


Attachments
gcc9-pr89084.patch (746 bytes, patch)
2019-02-01 17:52 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arseny Solokha 2019-01-28 07:18:03 UTC
gfortran-9.0.0-alpha20190127 snapshot (r268327) ICEs when compiling the following testcase extracted from gcc/testsuite/gfortran.dg/block_16.f08 w/ -flto:

MODULE sparse_matrix_csx_benchmark_utils
  IMPLICIT NONE
CONTAINS  
  SUBROUTINE sparse_matrix_csr_benchmark ( )
    WRITE(*,*) 'At*x: t'
    block
      integer, dimension(1), parameter :: idxs=[1]
      integer :: i, idx
      do i = 1, size(idxs)
         idx = idxs(i)
      enddo
    end block
  END SUBROUTINE sparse_matrix_csr_benchmark
END MODULE sparse_matrix_csx_benchmark_utils

% powerpc-e300c3-linux-gnu-gfortran-9.0.0-alpha20190127 -flto -c cgze3e1i.f08
during IPA pass: fnsummary
cgze3e1i.f08:13: internal compiler error: in get_partitioning_class, at symtab.c:1892
   13 |   END SUBROUTINE sparse_matrix_csr_benchmark
      | 
0x5a6e79 symtab_node::get_partitioning_class()
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/symtab.c:1892
0xc3c5b5 lto_output_varpool_node
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/lto-cgraph.c:618
0xc3c5b5 output_symtab()
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/lto-cgraph.c:981
0xc4e0d4 lto_output()
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/lto-streamer-out.c:2476
0xcc26fe write_lto
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/passes.c:2593
0xcc6090 ipa_write_summaries_1
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/passes.c:2657
0xcc6090 ipa_write_summaries()
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/passes.c:2720
0x98211c ipa_passes
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/cgraphunit.c:2529
0x98211c symbol_table::compile()
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/cgraphunit.c:2617
0x984ad8 symbol_table::finalize_compilation_unit()
	/var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-9.0.0_alpha20190127/work/gcc-9-20190127/gcc/cgraphunit.c:2862

(While my target here is powerpc, the ICE is not target-specific.)
Comment 1 David Malcolm 2019-01-31 19:41:28 UTC
Confirmed (on godbolt with x86_64 trunk, and a regression relative to gcc 8.2)
Comment 2 David Malcolm 2019-01-31 19:51:21 UTC
Fails this assertion:

1892	      gcc_checking_assert (vnode->definition);

(gdb) p vnode
$3 = <varpool_node * 0x7ffff1a65480 "idxs"/4>
Comment 3 Jakub Jelinek 2019-02-01 14:45:24 UTC
Started with r212467.
Comment 4 Jakub Jelinek 2019-02-01 16:17:03 UTC
integer function foo ( )
  write (*,*) 'foo'
  block
    integer, parameter :: idxs(3) = (/ 1, 2, 3 /)
    integer :: i
    foo = 0
    do i = 1, size(idxs)
      foo = foo + idxs(i)
    enddo
  end block
end function foo

with -O0 and no -flto (with -O0 -flto ICEs) doesn't ICE, but has undefined symbol like idxs.12345.  Strangely that goes away if the write statement is removed.
Comment 5 Jakub Jelinek 2019-02-01 16:51:28 UTC
The reason is that idxs isn't added to the BIND_EXPR vars.  This is done in
gfc_process_block_locals, generate_local_vars and 
generate_local_decl.  The last one for FL_PARAMETER adds it if:
5738	      if (sym->ns
5739		  && sym->ns->parent
5740		  && sym->ns->parent->code
5741		  && sym->ns->parent->code->op == EXEC_BLOCK)
5742		{
5743		  if (sym->attr.referenced)
5744		    gfc_get_symbol_decl (sym);
5745		  sym->mark = 1;
5746		}
Without the write stmt in there, sym->ns->parent->code->op is indeed EXEC_BLOCK and it is added, but with write stmt in there it is for some reason EXEC_WRITE instead.
Comment 6 Jakub Jelinek 2019-02-01 17:36:34 UTC
And the above mentioned tests seems to be what is flawed.
sym->ns->parent->code is the first statement in the parent namespace.
If the first statement is write, then it will be EXEC_WRITE, if the first statement is e.g. j = 1, it will be EXEC_ASSIGN.
This has been added in r229540
https://gcc.gnu.org/ml/fortran/2015-10/msg00153.html
Unfortunately, all the testcases in that PR had EXEC_BLOCK as the first statement in the parent namespace.

Either we can search for EXEC_BLOCK in the code chain and check if their ns is the ns we are looking for, but that is going to be expensive in large functions.
Or IMHO we could just test sym->ns->construct_entities, which is the flag set on the namespaces of EXEC_BLOCK.
Comment 7 Jakub Jelinek 2019-02-01 17:52:34 UTC
Created attachment 45589 [details]
gcc9-pr89084.patch

Untested fix.
Comment 8 Steve Kargl 2019-02-01 18:46:14 UTC
On Fri, Feb 01, 2019 at 05:52:34PM +0000, jakub at gcc dot gnu.org wrote:
> --- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> Created attachment 45589 [details]
>   --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45589&action=edit
> gcc9-pr89084.patch
> 
> Untested fix.
> 

Jakub, 

Thanks for analyzing the bug.  I think your patch is
correct.  The only place that sym->ns-construct_entities
is set in

/* Set up the local namespace for a BLOCK construct.  */

gfc_namespace*
gfc_build_block_ns (gfc_namespace *parent_ns)
{
  gfc_namespace* my_ns;
  static int numblock = 1;

  my_ns = gfc_get_namespace (parent_ns, 1);
  my_ns->construct_entities = 1;

Thus, the sym appears in a block construct.

Learn something new everyday.
Comment 9 Steve Kargl 2019-02-01 19:10:45 UTC
On Fri, Feb 01, 2019 at 06:46:14PM +0000, sgk at troutmask dot apl.washington.edu wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89084
> 
> --- Comment #8 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
> On Fri, Feb 01, 2019 at 05:52:34PM +0000, jakub at gcc dot gnu.org wrote:
> > --- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> > Created attachment 45589 [details]
> >   --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45589&action=edit
> > gcc9-pr89084.patch
> > 
> > Untested fix.
> > 
> 

Jakub, 

Your patch may also fix PR83246

I'm in the middle of regression testing a different issue,
so can't test your patch for another hour or so.
Comment 10 Steve Kargl 2019-02-01 19:16:04 UTC
On Fri, Feb 01, 2019 at 07:10:45PM +0000, sgk at troutmask dot apl.washington.edu wrote:
> 
> Jakub, 
> 
> Your patch may also fix PR83246
> 

Add PR82009 as possibly related.
Comment 11 Jakub Jelinek 2019-02-01 19:25:31 UTC
I'll include the PR83246 testcase (which is fixed with this patch too) in the patch as well.  PR82009 is indeed the same thing, but the testcase from this PR and PR82009 is actually the same it seems.  I'm not getting ICEs without -flto, just undefined symbols that can't be defined elsewhere.
I'll do my bootstraps in 90 minutes or so (together with other patches).
Comment 12 Steve Kargl 2019-02-01 19:43:47 UTC
On Fri, Feb 01, 2019 at 07:25:31PM +0000, jakub at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89084
> 
> --- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> I'll include the PR83246 testcase (which is fixed with this patch
> too) in the patch as well.  PR82009 is indeed the same thing, but
> the testcase from this PR and PR82009 is actually the same it seems.
> I'm not getting ICEs without -flto, just undefined symbols that
> can't be defined elsewhere.
> I'll do my bootstraps in 90 minutes or so (together with other patches).

It looks like you hit the goldmine of bug fixes.
The patch seems to fix PR70854 as well.
Comment 13 Jakub Jelinek 2019-02-01 22:54:37 UTC
Author: jakub
Date: Fri Feb  1 22:54:05 2019
New Revision: 268462

URL: https://gcc.gnu.org/viewcvs?rev=268462&root=gcc&view=rev
Log:
	PR fortran/83246
	PR fortran/89084
	* trans-decl.c (generate_local_decl): Add referenced FL_PARAMETERs
	if sym->ns->construct_entities rather than if
	sym->ns->parent->code->op == EXEC_BLOCK.

	* gfortran.dg/pr89084.f90: New test.
	* gfortran.dg/lto/pr89084_0.f90: New test.
	* gfortran.dg/pr83246.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/lto/pr89084_0.f90
    trunk/gcc/testsuite/gfortran.dg/pr83246.f90
    trunk/gcc/testsuite/gfortran.dg/pr89084.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 14 Jakub Jelinek 2019-02-01 22:58:03 UTC
Fixed.
Comment 15 Jakub Jelinek 2019-02-01 23:56:24 UTC
*** Bug 82009 has been marked as a duplicate of this bug. ***
Comment 16 Jakub Jelinek 2019-02-01 23:56:38 UTC
*** Bug 70854 has been marked as a duplicate of this bug. ***
Comment 17 Jakub Jelinek 2019-02-07 14:53:14 UTC
Author: jakub
Date: Thu Feb  7 14:52:41 2019
New Revision: 268642

URL: https://gcc.gnu.org/viewcvs?rev=268642&root=gcc&view=rev
Log:
	Backported from mainline
	2019-02-01  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/83246
	PR fortran/89084
	* trans-decl.c (generate_local_decl): Add referenced FL_PARAMETERs
	if sym->ns->construct_entities rather than if
	sym->ns->parent->code->op == EXEC_BLOCK.

	* gfortran.dg/pr89084.f90: New test.
	* gfortran.dg/lto/pr89084_0.f90: New test.
	* gfortran.dg/pr83246.f90: New test.

Added:
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/lto/pr89084_0.f90
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr83246.f90
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr89084.f90
Modified:
    branches/gcc-8-branch/gcc/fortran/ChangeLog
    branches/gcc-8-branch/gcc/fortran/trans-decl.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 18 Jakub Jelinek 2019-08-30 11:36:42 UTC
Author: jakub
Date: Fri Aug 30 11:36:10 2019
New Revision: 275096

URL: https://gcc.gnu.org/viewcvs?rev=275096&root=gcc&view=rev
Log:
	Backported from mainline
	2019-02-01  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/83246
	PR fortran/89084
	* trans-decl.c (generate_local_decl): Add referenced FL_PARAMETERs
	if sym->ns->construct_entities rather than if
	sym->ns->parent->code->op == EXEC_BLOCK.

	* gfortran.dg/pr89084.f90: New test.
	* gfortran.dg/lto/pr89084_0.f90: New test.
	* gfortran.dg/pr83246.f90: New test.

Added:
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/lto/pr89084_0.f90
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr83246.f90
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr89084.f90
Modified:
    branches/gcc-7-branch/gcc/fortran/ChangeLog
    branches/gcc-7-branch/gcc/fortran/trans-decl.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog