Bug 82886 - ICE with -finit-derived in gfc_conv_expr, at fortran/trans-expr.c:7807
Summary: ICE with -finit-derived in gfc_conv_expr, at fortran/trans-expr.c:7807
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Fritz Reese
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-07 17:19 UTC by G. Steinmetz
Modified: 2017-11-13 21:18 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-11-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 2017-11-07 17:19:52 UTC
With file ./gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03 :


$ gfortran-8-20171105 -c c_ptr_tests_9.f03 -finit-derived
c_ptr_tests_9.f03:22:0:

   end subroutine sub0

internal compiler error: Segmentation fault
0xb60fdf crash_signal
        ../../gcc/toplev.c:324
0x763411 gfc_conv_expr(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-expr.c:7807
0x767c0e gfc_trans_structure_assign(tree_node*, gfc_expr*, bool, bool)
        ../../gcc/fortran/trans-expr.c:7535
0x768a2e gfc_trans_subcomponent_assign
        ../../gcc/fortran/trans-expr.c:7459
0x767a70 gfc_trans_structure_assign(tree_node*, gfc_expr*, bool, bool)
        ../../gcc/fortran/trans-expr.c:7624
0x76996f gfc_conv_structure(gfc_se*, gfc_expr*, int)
        ../../gcc/fortran/trans-expr.c:7691
0x76b089 gfc_trans_assignment_1
        ../../gcc/fortran/trans-expr.c:10002
0x74d8e0 gfc_init_default_dt(gfc_symbol*, stmtblock_t*, bool)
        ../../gcc/fortran/trans-decl.c:4010
0x754caa gfc_trans_deferred_vars(gfc_symbol*, gfc_wrapped_block*)
        ../../gcc/fortran/trans-decl.c:4688
0x756d53 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6526
0x733ac1 gfc_generate_module_code(gfc_namespace*)
        ../../gcc/fortran/trans.c:2206
0x6e8abd translate_all_program_units
        ../../gcc/fortran/parse.c:6078
0x6e8abd gfc_parse_file()
        ../../gcc/fortran/parse.c:6294
0x72d3bf gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:204
Comment 1 G. Steinmetz 2017-11-07 17:20:15 UTC
A possible reduction :


$ cat z1.f90
program p
  use, intrinsic :: iso_c_binding, only: c_ptr, c_null_ptr
  type t
    type(c_ptr) :: my_c_ptr
  end type
contains
  subroutine sub0() bind(c)
    type(t), target :: my_f90_type
    my_f90_type%my_c_ptr = c_null_ptr
  end subroutine
end
Comment 2 Dominique d'Humieres 2017-11-07 17:40:03 UTC
Confirmed. My instrumented gfortran reports

../../work/gcc/fortran/trans-expr.c:7807:16: runtime error: member access within null pointer of type 'struct gfc_expr'
Comment 3 Fritz Reese 2017-11-07 22:09:01 UTC
On it.
Comment 4 Fritz Reese 2017-11-10 21:32:19 UTC
> https://gcc.gnu.org/ml/fortran/2017-11/msg00059.html

Fix pending review.
Comment 5 Fritz Reese 2017-11-11 00:48:24 UTC
Author: foreese
Date: Sat Nov 11 00:47:53 2017
New Revision: 254648

URL: https://gcc.gnu.org/viewcvs?rev=254648&root=gcc&view=rev
Log:
2017-11-10  Fritz Reese <fritzoreese@gmail.com>

    PR fortran/82886

    gcc/fortran/ChangeLog:

	PR fortran/82886
	* gfortran.h (gfc_build_init_expr): New prototype.
	* invoke.texi (finit-derived): Update documentation.
	* expr.c (gfc_build_init_expr): New, from gfc_build_default_init_expr.
	(gfc_build_default_init_expr): Redirect to gfc_build_init_expr(,,false)
	(component_initializer): Force building initializers using
	gfc_build_init_expr(,,true).

    gcc/testsuite/ChangeLog:

	PR fortran/82886
	* gfortran.dg/init_flag_16.f03: New testcase.


Added:
    trunk/gcc/testsuite/gfortran.dg/init_flag_16.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/invoke.texi
    trunk/gcc/testsuite/ChangeLog