Bug 85996 - [8/9 Regression] ICE: gfc_trans_select(): Bad type for case expr.
Summary: [8/9 Regression] ICE: gfc_trans_select(): Bad type for case expr.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.1.0
: P4 normal
Target Milestone: 6.5
Assignee: kargls
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 85138 86051
  Show dependency treegraph
 
Reported: 2018-05-30 11:22 UTC by Jean Beuken
Modified: 2018-06-09 18:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 6.4.0, 7.2.1, 7.3.0
Known to fail: 6.4.1, 7.3.1, 8.1.0, 9.0
Last reconfirmed: 2018-06-02 00:00:00


Attachments
source (http://nn-online.org/code/strings/strings-1.3.tar.gz) (17.08 KB, application/x-gzip)
2018-05-30 11:22 UTC, Jean Beuken
Details
reduced testcase (483 bytes, text/plain)
2018-06-03 00:40 UTC, kargls
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jean Beuken 2018-05-30 11:22:27 UTC
Created attachment 44210 [details]
source (http://nn-online.org/code/strings/strings-1.3.tar.gz)

Linux kernel 3.10 CentOS 7.4

gfortran  --version
GNU Fortran (GCC) 8.1.0

tar xzf strings-1.3.tar.gz
cd strings-1.3

gfortran -Wall -Wextra -c m_strings.F95
f951: internal compiler error: gfc_trans_select(): Bad type for case expr.
0x60128f gfc_internal_error(char const*, ...)
	../../gcc-8.1.0/gcc/fortran/error.c:1358
0x70fe59 gfc_trans_select(gfc_code*)
	../../gcc-8.1.0/gcc/fortran/trans-stmt.c:3346
0x6a2ef7 trans_code
	../../gcc-8.1.0/gcc/fortran/trans.c:1940
0x6c92cb gfc_generate_function_code(gfc_namespace*)
	../../gcc-8.1.0/gcc/fortran/trans-decl.c:6507
0x6a6879 gfc_generate_module_code(gfc_namespace*)
	../../gcc-8.1.0/gcc/fortran/trans.c:2222
0x659f4b translate_all_program_units
	../../gcc-8.1.0/gcc/fortran/parse.c:6108
0x659f4b gfc_parse_file()
	../../gcc-8.1.0/gcc/fortran/parse.c:6324
0x6a02ef gfc_be_parse_file
	../../gcc-8.1.0/gcc/fortran/f95-lang.c:204


REM : well compiled with GCC 6.4.0 and 7.1.2
Comment 1 kargls 2018-06-02 21:09:29 UTC
This is a 7000 line piece of code. Please submit a reduced testcase.
Comment 2 kargls 2018-06-03 00:40:36 UTC
Created attachment 44225 [details]
reduced testcase
Comment 3 Dominique d'Humieres 2018-06-03 10:02:35 UTC
Nice reduction!-)

The ICE appeared between revisions r258235 (2018-03-04, OK) and r258362 (2018-03-08, ICE) and the commit has been back ported to the GCC6 and GCC7 branches.

(lldb) p code->expr1->ts.type
(bt) $0 = BT_UNKNOWN
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x00000001001707f0 f951`gfc_trans_select(code=0x0000000143006230) at trans-stmt.c:3310
    frame #1: 0x00000001000e9748 f951`::trans_code(code=0x0000000143006230, cond=0x0000000000000000) at trans.c:1940
    frame #2: 0x0000000100119683 f951`gfc_generate_function_code(ns=<unavailable>) at trans-decl.c:6514
    frame #3: 0x00000001000ee1d2 f951`gfc_generate_module_code(ns=0x0000000145003000) at trans.c:2222
    frame #4: 0x000000010009ad2c f951`gfc_parse_file() at parse.c:6108
    frame #5: 0x000000010009acc3 f951`gfc_parse_file()
    frame #6: 0x00000001000e648c f951`::gfc_be_parse_file() at f95-lang.c:204
    frame #7: 0x0000000100c4667a f951`::compile_file() at toplev.c:455
    frame #8: 0x00000001012a6c7b f951`toplev::main(int, char**) at toplev.c:2133
    frame #9: 0x00000001012a87be f951`main(argc=2, argv=0x00007ffeefbff250) at main.c:39
Comment 4 Steve Kargl 2018-06-03 16:02:14 UTC
On Sun, Jun 03, 2018 at 10:02:35AM +0000, dominiq at lps dot ens.fr wrote:
>
> Nice reduction!-)
> 
> The ICE appeared between revisions r258235 (2018-03-04, OK) and r258362
> (2018-03-08, ICE) and the commit has been back ported to the GCC6 and GCC7
> branches.
> 

There are 3 commits to gcc/fortran in that range.  I
reverted what would be the obvious one that might
cause a problem and the ICE still occurs.

The ICE disappears if uppercase_c and uppercase_s are
moved up in the source code to a location that comes
before any reference to the generic uppercase.
Comment 5 Dominique d'Humieres 2018-06-03 17:05:42 UTC
> There are 3 commits to gcc/fortran in that range.  I
> reverted what would be the obvious one that might
> cause a problem and the ICE still occurs.

Was it r258347?

> The ICE disappears if uppercase_c and uppercase_s are
> moved up in the source code to a location that comes
> before any reference to the generic uppercase.

This rings some bells, but I am unable to remember for which PR this happened.
Comment 6 Steve Kargl 2018-06-03 18:11:43 UTC
On Sun, Jun 03, 2018 at 05:05:42PM +0000, dominiq at lps dot ens.fr wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85996
> 
> --- Comment #5 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> > There are 3 commits to gcc/fortran in that range.  I
> > reverted what would be the obvious one that might
> > cause a problem and the ICE still occurs.
> 
> Was it r258347?
> 

Whoops. Reverted in the wrong tree.

Appears to be related to 258347.
Comment 7 Dominique d'Humieres 2018-06-03 18:25:04 UTC
Could be related to pr85138.
Comment 8 kargls 2018-06-03 23:31:29 UTC
(In reply to Dominique d'Humieres from comment #7)
> Could be related to pr85138.

Yes, it is related if not the same.

I have a patch that fixes both PRs and passes regression testing.
Comment 9 kargls 2018-06-09 15:48:45 UTC
Author: kargl
Date: Sat Jun  9 15:47:40 2018
New Revision: 261362

URL: https://gcc.gnu.org/viewcvs?rev=261362&root=gcc&view=rev
Log:
2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85138
	PR fortran/85996
	PR fortran/86051
	* decl.c (gfc_match_char_spec): Use private namespace in attempt to
	reduce a charlen to a constant.

2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85138
	PR fortran/85996
	PR fortran/86051
	* gfortran.dg/pr85138_1.f90: New test.
	* gfortran.dg/pr85138_2.f90: Ditto.
	* gfortran.dg/pr85996.f90: Ditto.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr85138_1.f90
    trunk/gcc/testsuite/gfortran.dg/pr85138_2.f90
    trunk/gcc/testsuite/gfortran.dg/pr85996.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 10 kargls 2018-06-09 18:09:32 UTC
Author: kargl
Date: Sat Jun  9 18:09:00 2018
New Revision: 261370

URL: https://gcc.gnu.org/viewcvs?rev=261370&root=gcc&view=rev
Log:
2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85138
	PR fortran/85996
	PR fortran/86051
	* decl.c (gfc_match_char_spec): Use private namespace in attempt to
	reduce a charlen to a constant.

2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85138
	PR fortran/85996
	PR fortran/86051
	* gfortran.dg/pr85138_1.f90: New test.
	* gfortran.dg/pr85138_2.f90: Ditto.
	* gfortran.dg/pr85996.f90: Ditto.

Added:
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr85138_1.f90
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr85138_2.f90
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr85996.f90
Modified:
    branches/gcc-8-branch/gcc/fortran/ChangeLog
    branches/gcc-8-branch/gcc/fortran/decl.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 11 kargls 2018-06-09 18:30:12 UTC
Author: kargl
Date: Sat Jun  9 18:29:40 2018
New Revision: 261371

URL: https://gcc.gnu.org/viewcvs?rev=261371&root=gcc&view=rev
Log:
2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85138
	PR fortran/85996
	PR fortran/86051
	* decl.c (gfc_match_char_spec): Use private namespace in attempt to
	reduce a charlen to a constant.

2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85138
	PR fortran/85996
	PR fortran/86051
	* gfortran.dg/pr85138_1.f90: New test.
	* gfortran.dg/pr85138_2.f90: Ditto.
	* gfortran.dg/pr85996.f90: Ditto.

Added:
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr85138_1.f90
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr85138_2.f90
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr85996.f90
Modified:
    branches/gcc-7-branch/gcc/fortran/ChangeLog
    branches/gcc-7-branch/gcc/fortran/decl.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 12 kargls 2018-06-09 18:36:30 UTC
Author: kargl
Date: Sat Jun  9 18:35:58 2018
New Revision: 261372

URL: https://gcc.gnu.org/viewcvs?rev=261372&root=gcc&view=rev
Log:
2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85138
	PR fortran/85996
	PR fortran/86051
	* decl.c (gfc_match_char_spec): Use private namespace in attempt to
	reduce a charlen to a constant.

2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85138
	PR fortran/85996
	PR fortran/86051
	* gfortran.dg/pr85138_1.f90: New test.
	* gfortran.dg/pr85138_2.f90: Ditto.
	* gfortran.dg/pr85996.f90: Ditto.

Added:
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/pr85138_1.f90
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/pr85138_2.f90
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/pr85996.f90
Modified:
    branches/gcc-6-branch/gcc/fortran/ChangeLog
    branches/gcc-6-branch/gcc/fortran/decl.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 13 kargls 2018-06-09 18:37:14 UTC
Fixed on trunk and 6, 7, and 8 branches.