Bug 88552

Summary: ICE in gfc_typenode_for_spec, at fortran/trans-types.c:1120
Product: gcc Reporter: G. Steinmetz <gscfq>
Component: fortranAssignee: anlauf
Status: RESOLVED FIXED    
Severity: normal CC: anlauf
Priority: P3 Keywords: accepts-invalid, ice-on-invalid-code
Version: 9.0   
Target Milestone: 14.0   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103258
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2023-05-31 00:00:00

Description G. Steinmetz 2018-12-19 16:11:10 UTC
Without a program statement :


$ cat z1.f90
integer(len((c)) :: n
end


$ gfortran-9-20181216 -c z1.f90
$ gfortran-9-20181216 -c z1.f90 -fimplicit-none
z1.f90:1:0:

    1 | integer(len((c)) :: n
      |
internal compiler error: in gfc_typenode_for_spec, at fortran/trans-types.c:1120
0x78e59d gfc_typenode_for_spec(gfc_typespec*, int)
        ../../gcc/fortran/trans-types.c:1120
0x78c1f6 gfc_sym_type(gfc_symbol*)
        ../../gcc/fortran/trans-types.c:2243
0x71af9e gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc/fortran/trans-decl.c:1696
0x71ea47 generate_local_decl
        ../../gcc/fortran/trans-decl.c:5600
0x6d3d12 do_traverse_symtree
        ../../gcc/fortran/symbol.c:4151
0x71ff9c generate_local_vars
        ../../gcc/fortran/trans-decl.c:5800
0x71ff9c gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6444
0x69d7c6 translate_all_program_units
        ../../gcc/fortran/parse.c:6128
0x69d7c6 gfc_parse_file()
        ../../gcc/fortran/parse.c:6331
0x6e6fcf gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:204


---

Invalid syntax also silently accepted :

$ cat z3.f90
integer(m::n
end


$ gfortran-9-20181216 -c z3.f90
$ gfortran-9-20181216 -c z3.f90 -fimplicit-none
z3.f90:1:0:

    1 | integer(m::n
      |
internal compiler error: in gfc_typenode_for_spec, at fortran/trans-types.c:1120
#...
Comment 1 G. Steinmetz 2018-12-19 16:11:57 UTC
Detected :


$ cat z2.f90
program p
integer(len((c)) :: n
end


$ cat z5.f90
implicit none
integer(len((c)) :: n
end


$ gfortran-9-20181216 -c z2.f90 -fimplicit-none
z2.f90:2:14:

    2 | integer(len((c)) :: n
      |              1
Error: Symbol 'c' at (1) has no IMPLICIT type
Comment 2 Dominique d'Humieres 2018-12-19 16:38:48 UTC
Confirmed from at least 4.8 up to trunk (9.0).
Comment 3 anlauf 2023-05-31 21:08:35 UTC
I'm testing the following patch:

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 1de2b231242..2162b62608a 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -3366,6 +3372,7 @@ close_brackets:
       else
 	gfc_error ("Missing right parenthesis at %C");
       m = MATCH_ERROR;
+      goto no_match;
     }
   else
      /* All tests passed.  */
@@ -4716,6 +4723,9 @@ get_kind:
       return MATCH_ERROR;
     }
 
+  if (m == MATCH_ERROR)
+    return MATCH_ERROR;
+
   /* Defer association of the KIND expression of function results
      until after USE and IMPORT statements.  */
   if ((gfc_current_state () == COMP_NONE && gfc_error_flag_test ())
Comment 5 GCC Commits 2023-06-01 21:04:50 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:ff8f45d20f9ea6acc99442ad29212d177f58e8fe

commit r14-1477-gff8f45d20f9ea6acc99442ad29212d177f58e8fe
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Jun 1 23:04:30 2023 +0200

    Fortran: force error on bad KIND specifier [PR88552]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/88552
            * decl.cc (gfc_match_kind_spec): Use error path on missing right
            parenthesis.
            (gfc_match_decl_type_spec): Use error return when an error occurred
            during matching a KIND specifier.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/88552
            * gfortran.dg/pr88552.f90: New test.
Comment 6 anlauf 2023-06-01 21:13:50 UTC
Fixed for gcc-14.  Closing.

Thanks for the report!