Bug 88155 - ICE in gfc_format_decoder, at fortran/error.c:947
Summary: ICE in gfc_format_decoder, at fortran/error.c:947
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 9.0
: P4 normal
Target Milestone: 7.5
Assignee: kargls
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-22 17:23 UTC by G. Steinmetz
Modified: 2018-12-12 01:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-11-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2018-11-22 17:23:06 UTC
With a typo, down to at least gcc-5 :


$ cat z1.f90
program p
   type t
      integer :: a
   end type
   type(t) :: x
   data x /t()1/
   print *, x
end


$ gfortran-9-20181118 -c z1.f90
0x618fae gfc_format_decoder
        ../../gcc/fortran/error.c:947
0x131577e pp_format(pretty_printer*, text_info*)
        ../../gcc/pretty-print.c:1390
0x130b125 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
        ../../gcc/diagnostic.c:1015
0x618e4c gfc_error_opt
        ../../gcc/fortran/error.c:1313
0x61a3f0 gfc_error(char const*, ...)
        ../../gcc/fortran/error.c:1342
0x675e10 build_actual_constructor
        ../../gcc/fortran/primary.c:2934
0x6793f6 gfc_convert_to_structure_constructor(gfc_expr*, gfc_symbol*, gfc_expr**, gfc_actual_arglist**, bool)
        ../../gcc/fortran/primary.c:3148
0x679801 gfc_match_structure_constructor(gfc_symbol*, gfc_expr**)
        ../../gcc/fortran/primary.c:3228
0x604f2f match_data_constant
        ../../gcc/fortran/decl.c:427
0x604fe3 top_val_list
        ../../gcc/fortran/decl.c:472
0x6051ff gfc_match_data()
        ../../gcc/fortran/decl.c:616
0x66a891 match_word
        ../../gcc/fortran/parse.c:65
0x66dfd6 decode_statement
        ../../gcc/fortran/parse.c:468
0x66ebfa next_free
        ../../gcc/fortran/parse.c:1234
0x66ebfa next_statement
        ../../gcc/fortran/parse.c:1466
0x67020b parse_spec
        ../../gcc/fortran/parse.c:3858
0x672cd7 parse_progunit
        ../../gcc/fortran/parse.c:5671
0x674359 gfc_parse_file()
        ../../gcc/fortran/parse.c:6211
0x6bc97f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:204
Comment 1 kargls 2018-11-22 23:09:10 UTC
(In reply to G. Steinmetz from comment #0)
> With a typo, down to at least gcc-5 :
> 
> 
> $ cat z1.f90
> program p
>    type t
>       integer :: a
>    end type
>    type(t) :: x
>    data x /t()1/
>    print *, x
> end
> 
> 
> $ gfortran-9-20181118 -c z1.f90
> 0x618fae gfc_format_decoder
>         ../../gcc/fortran/error.c:947
> 0x131577e pp_format(pretty_printer*, text_info*)
>         ../../gcc/pretty-print.c:1390
> 0x130b125 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
>         ../../gcc/diagnostic.c:1015
> 0x618e4c gfc_error_opt
>         ../../gcc/fortran/error.c:1313
> 0x61a3f0 gfc_error(char const*, ...)
>         ../../gcc/fortran/error.c:1342
> 0x675e10 build_actual_constructor
>         ../../gcc/fortran/primary.c:2934

Interesting bug.  The pointer components of gfc_current_locus are NULL.
Changing the use of %C to %L in gfc_error and using comp->loc yields

troutmask:sgk[203] gfcx -c a.f90
a.f90:3:18:

    3 |       integer :: a
      |                  1
Error: No initializer for component 'a' given in the structure constructor at (1)

which is of course the bogus locus.  Completely suppressing %C
yields an error message but not a locus and source line output.
Comment 2 kargls 2018-11-23 19:11:18 UTC
(In reply to kargl from comment #1)
> (In reply to G. Steinmetz from comment #0)
> > With a typo, down to at least gcc-5 :
> > 
> > 
> > $ cat z1.f90
> > program p
> >    type t
> >       integer :: a
> >    end type
> >    type(t) :: x
> >    data x /t()1/
> >    print *, x
> > end
> > 
> > 
> > $ gfortran-9-20181118 -c z1.f90
> > 0x618fae gfc_format_decoder
> >         ../../gcc/fortran/error.c:947
> > 0x131577e pp_format(pretty_printer*, text_info*)
> >         ../../gcc/pretty-print.c:1390
> > 0x130b125 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
> >         ../../gcc/diagnostic.c:1015
> > 0x618e4c gfc_error_opt
> >         ../../gcc/fortran/error.c:1313
> > 0x61a3f0 gfc_error(char const*, ...)
> >         ../../gcc/fortran/error.c:1342
> > 0x675e10 build_actual_constructor
> >         ../../gcc/fortran/primary.c:2934
> 
> Interesting bug.  The pointer components of gfc_current_locus are NULL.
> Changing the use of %C to %L in gfc_error and using comp->loc yields
> 
> troutmask:sgk[203] gfcx -c a.f90
> a.f90:3:18:
> 
>     3 |       integer :: a
>       |                  1
> Error: No initializer for component 'a' given in the structure constructor
> at (1)
> 
> which is of course the bogus locus.  Completely suppressing %C
> yields an error message but not a locus and source line output.

This sets the locus correctly.

Index: primary.c
===================================================================
--- primary.c   (revision 266386)
+++ primary.c   (working copy)
@@ -3212,6 +3212,7 @@ gfc_match_structure_constructor (gfc_symbol *sym, gfc_
   e = gfc_get_expr ();
   e->symtree = symtree;
   e->expr_type = EXPR_FUNCTION;
+  e->where = gfc_current_locus;
 
   gcc_assert (gfc_fl_struct (sym->attr.flavor)
              && symtree->n.sym->attr.flavor == FL_PROCEDURE);
Comment 3 kargls 2018-12-12 00:53:39 UTC
Author: kargl
Date: Wed Dec 12 00:53:08 2018
New Revision: 267041

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

	PR fortran/88155
	* primary.c (gfc_match_structure_constructor):  Set the locus of
	an expression to avoid a NULL pointer dereference.

2018-12-11  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/88155
	* gfortran.dg/pr70870_1.f90: Update testcase to use -std=gnu.
	* gfortran.dg/pr88155.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr88155.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/primary.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/pr70870_1.f90
Comment 4 kargls 2018-12-12 01:15:42 UTC
Author: kargl
Date: Wed Dec 12 01:14:58 2018
New Revision: 267042

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

	PR fortran/88155
	* primary.c (gfc_match_structure_constructor):  Set the locus of
	an expression to avoid a NULL pointer dereference.

2018-12-11  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/88155
	* gfortran.dg/pr70870_1.f90: Update testcase to use -std=gnu.
	* gfortran.dg/pr88155.f90: New test.

Added:
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr88155.f90
Modified:
    branches/gcc-8-branch/gcc/fortran/ChangeLog
    branches/gcc-8-branch/gcc/fortran/primary.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr70870_1.f90
Comment 5 kargls 2018-12-12 01:26:44 UTC
Author: kargl
Date: Wed Dec 12 01:26:12 2018
New Revision: 267043

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

	PR fortran/88155
	* primary.c (gfc_match_structure_constructor):  Set the locus of
	an expression to avoid a NULL pointer dereference.

2018-12-11  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/88155
	* gfortran.dg/pr70870_1.f90: Update testcase to use -std=gnu.
	* gfortran.dg/pr88155.f90: New test.

Added:
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr88155.f90
Modified:
    branches/gcc-7-branch/gcc/fortran/ChangeLog
    branches/gcc-7-branch/gcc/fortran/primary.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr70870_1.f90
Comment 6 kargls 2018-12-12 01:27:06 UTC
Fixed on trunk, branch-8, and branch-7.