Bug 96085 - ICE in gfc_finish_var_decl, at fortran/trans-decl.c:694
Summary: ICE in gfc_finish_var_decl, at fortran/trans-decl.c:694
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2020-07-06 17:58 UTC by G. Steinmetz
Modified: 2020-07-08 18:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-07-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2020-07-06 17:58:38 UTC
Affects versions down to at least r5 :


$ cat z1.f90
module m
   integer, parameter :: a = 1
contains
   subroutine s
      assign 2 to a
    2 print *, a
   end
end


$ cat z2.f90
subroutine sub
   integer, parameter :: a = 1
   call s
contains
   subroutine s
      assign 2 to a
    2 print *, a
   end
end


$ gfortran-11-20200705 -c z2.f90   # accepts invalid
z2.f90:5:19:

    6 |       assign 2 to a
      |                   1
Warning: Deleted feature: ASSIGN statement at (1)


$ gfortran-11-20200705 -c z1.f90
z1.f90:5:19:

    5 |       assign 2 to a
      |                   1
Warning: Deleted feature: ASSIGN statement at (1)
z1.f90:5:0:

    5 |       assign 2 to a
      |
internal compiler error: in gfc_finish_var_decl, at fortran/trans-decl.c:694
0x72c269 gfc_finish_var_decl
        ../../gcc/fortran/trans-decl.c:694
0x72b5c1 gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc/fortran/trans-decl.c:1852
0x73a4b8 gfc_conv_variable
        ../../gcc/fortran/trans-expr.c:2735
0x7366ca gfc_conv_expr(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-expr.c:8693
0x775a36 gfc_conv_label_variable(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-stmt.c:80
0x775aac gfc_trans_label_assign(gfc_code*)
        ../../gcc/fortran/trans-stmt.c:104
0x705d97 trans_code
        ../../gcc/fortran/trans.c:1868
0x72f324 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6840
0x709c49 gfc_generate_module_code(gfc_namespace*)
        ../../gcc/fortran/trans.c:2264
0x6b6901 translate_all_program_units
        ../../gcc/fortran/parse.c:6294
0x6b6901 gfc_parse_file()
        ../../gcc/fortran/parse.c:6546
0x70284f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:212
Comment 1 Dominique d'Humieres 2020-07-07 11:48:21 UTC
Confirmed.
Comment 2 anlauf 2020-07-07 20:25:04 UTC
Patch:

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 223dcccce91..8eba7c95b4a 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -11900,6 +11902,7 @@ start:
                  || code->expr1->symtree->n.sym->ts.type != BT_INTEGER
                  || code->expr1->symtree->n.sym->ts.kind
                     != gfc_default_integer_kind
+                 || code->expr1->symtree->n.sym->attr.flavor != FL_VARIABLE
                  || code->expr1->symtree->n.sym->as != NULL))
            gfc_error ("ASSIGN statement at %L requires a scalar "
                       "default INTEGER variable", &code->expr1->where);
Comment 3 anlauf 2020-07-07 20:54:52 UTC
(In reply to anlauf from comment #2)
That one produces a strange regression with pr50392.f.

Patch that regtests fine:

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 223dcccce91..c88b76a232a 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -11900,6 +11902,7 @@ start:
                  || code->expr1->symtree->n.sym->ts.type != BT_INTEGER
                  || code->expr1->symtree->n.sym->ts.kind
                     != gfc_default_integer_kind
+                 || code->expr1->symtree->n.sym->attr.flavor == FL_PARAMETER
                  || code->expr1->symtree->n.sym->as != NULL))
            gfc_error ("ASSIGN statement at %L requires a scalar "
                       "default INTEGER variable", &code->expr1->where);
Comment 4 GCC Commits 2020-07-08 18:54:00 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:1fa08dcac686ca5b6d84e64c9f5813daef59f540

commit r11-1949-g1fa08dcac686ca5b6d84e64c9f5813daef59f540
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Jul 8 20:53:12 2020 +0200

    PR fortran/96085 - ICE in gfc_finish_var_decl, at fortran/trans-decl.c:694
    
    Legacy ASSIGN requires a scalar integer variable.  Reject parameter
    arguments.
    
    gcc/fortran/
            PR fortran/96085
            * resolve.c (gfc_resolve_code): Check whether assign target is a
            parameter.
Comment 5 anlauf 2020-07-08 18:58:39 UTC
Fixed on master for gcc-11.

Thanks for the report!