Bug 83146 - [6/7/8/9 Regression] ICE on SELECT CASE statement with associate name
Summary: [6/7/8/9 Regression] ICE on SELECT CASE statement with associate name
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.0
: P4 normal
Target Milestone: 6.5
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2017-11-24 16:27 UTC by Neil Carlson
Modified: 2018-10-14 09:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.5
Known to fail: 4.9.3, 5.5.0, 6.4.0, 7.2.0, 8.0
Last reconfirmed: 2017-11-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Neil Carlson 2017-11-24 16:27:32 UTC
The current 8.0 trunk gives an ICE on the following example.  6.4.1 also gives an ICE.

type foo
  integer n
end type
type bar
  type(foo) array(2)
end type
type(bar) b
associate (n_array => b%array%n)
  select case (n_array(1))
  case default
  end select
end associate
end

Here's the traceback

$ gfortran -c gfortran-20171124.f90 
gfortran-20171124.f90:9:0:

   select case (n_array(1))
 
internal compiler error: in gfc_get_element_type, at fortran/trans-types.c:1231
0x5a5da8 gfc_get_element_type(tree_node*)
	../../gcc/fortran/trans-types.c:1231
0x95d247 trans_associate_var
	../../gcc/fortran/trans-stmt.c:1632
0x95d247 gfc_trans_block_construct(gfc_code*)
	../../gcc/fortran/trans-stmt.c:1890
0x8e48c7 trans_code
	../../gcc/fortran/trans.c:1924
0x90e7a8 gfc_generate_function_code(gfc_namespace*)
	../../gcc/fortran/trans-decl.c:6437
0x89d036 translate_all_program_units
	../../gcc/fortran/parse.c:6091
0x89d036 gfc_parse_file()
	../../gcc/fortran/parse.c:6294
0x8e0eaf gfc_be_parse_file
	../../gcc/fortran/f95-lang.c:204
Comment 1 Neil Carlson 2017-11-24 16:59:50 UTC
I thought that assigning the select case expression to a temporary integer and using that variable in the select case statement would be a workaround, but no. You can put anything unrelated to the associate name in the select case and you still get an ICE.  It seems the the associate block itself is the problem.  Here's the tweaked example

type foo
  integer n
end type
type bar
  type(foo) array(2)
end type
type(bar) b
integer :: m=0
associate (n_array => b%array%n)
  select case (m)
  case default
  end select
end associate
end
Comment 2 Neil Carlson 2017-11-24 17:07:54 UTC
Turns out you don't need anything at all in the associate block to get an ICE:

type foo
  integer n
end type
type bar
  type(foo) array(2)
end type
type(bar) b
associate (n_array => b%array%n)
end associate
end
Comment 3 Dominique d'Humieres 2017-11-24 18:22:41 UTC
Regression occurring between revisions r205210 (2013-11-21, OK) and r207996 (2014-02-21, ICE).
Comment 4 Dominique d'Humieres 2018-05-20 10:46:26 UTC
AFAICT this seems fixed by a recent patch, likely r260414 for pr49636.
Comment 5 Paul Thomas 2018-10-14 09:25:46 UTC
Author: pault
Date: Sun Oct 14 09:25:13 2018
New Revision: 265148

URL: https://gcc.gnu.org/viewcvs?rev=265148&root=gcc&view=rev
Log:
2018-10-14  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/83146
	* gfortran.dg/associate_43.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/associate_43.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 6 Paul Thomas 2018-10-14 09:27:48 UTC
Indeed, Dominique this has been fixed. I have added a testcase to trunk to make sure that it remains nailed to the floor. I do not think that this is necessary for 8-branch.

Thanks for the report.

Paul