Bug 57116 - [OOP] ICE for pointer assignment inside SELECT TYPE
Summary: [OOP] ICE for pointer assignment inside SELECT TYPE
Status: RESOLVED DUPLICATE of bug 34640
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2013-04-29 19:53 UTC by Bader@lrz.de
Modified: 2017-09-10 17:17 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-04-29 00:00:00


Attachments
module and main program as standalone source. (359 bytes, application/octet-stream)
2013-04-29 19:53 UTC, Bader@lrz.de
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bader@lrz.de 2013-04-29 19:53:52 UTC
Created attachment 29976 [details]
module and main program as standalone source.

The attached Fortran source produces the following error message with gfortran 4.8.0:

rtti_pointerassign_02_pos.f90: In function `extract':
rtti_pointerassign_02_pos.f90:13:0: internal compiler error: Segmentation fault
        extract => this(ic:)
 ^
0x87e07f crash_signal
        ../../gcc-4.8.0/gcc/toplev.c:332
0x5d2db2 gfc_trans_pointer_assignment(gfc_expr*, gfc_expr*)
        ../../gcc-4.8.0/gcc/fortran/trans-expr.c:6555
0x5a7896 trans_code
        ../../gcc-4.8.0/gcc/fortran/trans.c:1439
0x5f0e28 gfc_trans_block_construct(gfc_code*)
        ../../gcc-4.8.0/gcc/fortran/trans-stmt.c:1342
0x5a76b7 trans_code
        ../../gcc-4.8.0/gcc/fortran/trans.c:1527
0x5f25fd gfc_trans_integer_select
        ../../gcc-4.8.0/gcc/fortran/trans-stmt.c:1990
0x5f25fd gfc_trans_select(gfc_code*)
        ../../gcc-4.8.0/gcc/fortran/trans-stmt.c:2484
0x5a76c7 trans_code
        ../../gcc-4.8.0/gcc/fortran/trans.c:1543
0x5f0e28 gfc_trans_block_construct(gfc_code*)
        ../../gcc-4.8.0/gcc/fortran/trans-stmt.c:1342
0x5a76b7 trans_code
        ../../gcc-4.8.0/gcc/fortran/trans.c:1527
0x5c4be2 gfc_generate_function_code(gfc_namespace*)
        ../../gcc-4.8.0/gcc/fortran/trans-decl.c:5397
0x5a8091 gfc_generate_module_code(gfc_namespace*)
        ../../gcc-4.8.0/gcc/fortran/trans.c:1755
0x56862b translate_all_program_units
        ../../gcc-4.8.0/gcc/fortran/parse.c:4455
0x56862b gfc_parse_file()
        ../../gcc-4.8.0/gcc/fortran/parse.c:4682
0x5a3c25 gfc_be_parse_file
        ../../gcc-4.8.0/gcc/fortran/f95-lang.c:189
Comment 1 Dominique d'Humieres 2013-04-29 21:54:39 UTC
Confirmed. The test passes if I define explicitly the bounds, i.e.,

  subroutine extract(this, v, ic)
    class(*), target :: this(:)
    real, pointer :: v(:)
    integer :: ic, m, n
    n = ubound(this,1)
    m = n-ic+1
    select type (this)
    type is (real)
       v(1:m) => this(ic:n)
    class is (foo)
       v(1:m) => this(ic:n)%v
    end select
  end subroutine extract
Comment 2 janus 2013-04-30 12:13:49 UTC
Reduced test case for the ICE, which shows that unlimited polymorphism is not required to trigger the bug:


  implicit none
  type :: foo
     real :: v
  end type

contains

  subroutine extract(this, v)
    class(foo), target :: this(:)
    real, pointer :: v(:)
    select type (this)
    class is (foo)
       v => this(1:2)%v
    end select
  end subroutine

end
Comment 3 Dominique d'Humieres 2017-06-11 12:43:04 UTC
Fixed by the patch for pr34640.

*** This bug has been marked as a duplicate of bug 34640 ***
Comment 4 Paul Thomas 2017-09-10 17:03:25 UTC
Author: pault
Date: Sun Sep 10 17:02:53 2017
New Revision: 251949

URL: https://gcc.gnu.org/viewcvs?rev=251949&root=gcc&view=rev
Log:
2017-09-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34640
	PR fortran/40737
	PR fortran/55763
	PR fortran/57019
	PR fortran/57116

	* expr.c (is_subref_array): Add class pointer array dummies
	to the list of expressions that return true.
	* trans-array.c: Add SPAN_FIELD and update indices for
	subsequent fields.
	(gfc_conv_descriptor_span, gfc_conv_descriptor_span_get,
	gfc_conv_descriptor_span_set, is_pointer_array,
	get_array_span): New functions.
	(gfc_get_descriptor_offsets_for_info): New function to preserve
	API for access to descriptor fields for trans-types.c.
	(gfc_conv_scalarized_array_ref): If the expression is a subref
	array, make sure that info->descriptor is a descriptor type.
	Otherwise, if info->descriptor is a pointer array, set 'decl'
	and fix it if it is a component reference.
	(build_array_ref): Simplify handling of class array refs by
	passing the vptr to gfc_build_array_ref rather than generating
	the pointer arithmetic in this function.
	(gfc_conv_array_ref): As in gfc_conv_scalarized_array_ref, set
	'decl'.
	(gfc_array_allocate): Set the span field if this is a pointer
	array. Use the expr3 element size if it is available, so that
	the dynamic type element size is used.
	(gfc_conv_expr_descriptor): Set the span field for pointer
	assignments.
	* trans-array.h: Prototypes for gfc_conv_descriptor_span_get
	gfc_conv_descriptor_span_set and
	gfc_get_descriptor_offsets_for_info added.
	trans-decl.c (gfc_get_symbol_decl): If a non-class pointer
	array, mark the declaration as a GFC_DECL_PTR_ARRAY_P. Remove
	the setting of GFC_DECL_SPAN.
	(gfc_trans_deferred_vars): Set the span field to zero in thge
	originating scope.
	* trans-expr.c (gfc_conv_procedure_call): Do not use copy-in/
	copy-out to pass subref expressions to a pointer dummy.
	(gfc_trans_pointer_assignment): Remove code for setting of
	GFC_DECL_SPAN. Set the 'span' field for non-class pointers to
	class function results. Likewise for rank remap. In the case
	that the target is not a whole array, use the target array ref
	for remap and, since the 'start' indices are missing, set the
	lbounds to one, as required by the standard.
	* trans-intrinsic.c (conv_expr_ref_to_caf_ref): Pick up the
	'token' offset from the field decl in the descriptor.
	(conv_isocbinding_subroutine): Set the 'span' field.
	* trans-io.c (gfc_trans_transfer): Always scalarize pointer
	array io.
	* trans-stmt.c (trans_associate_var): Set the 'span' field.
	* trans-types.c (gfc_get_array_descriptor_base): Add the 'span'
	field to the array descriptor.
	(gfc_get_derived_type): Pointer array components are marked as
	GFC_DECL_PTR_ARRAY_P.
	(gfc_get_array_descr_info): Replaced API breaking code for
	descriptor offset calling gfc_get_descriptor_offsets_for_info.
	* trans.c (get_array_span): New function.
	(gfc_build_array_ref): Simplify by calling get_array_span and
	obtain 'span' if 'decl' or 'vptr' present.
	* trans.h : Rename DECL_LANG_FLAG_6, GFC_DECL_SUBREF_ARRAY_P,
	as GFC_DECL_PTR_ARRAY_P.


2017-09-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34640
	* gfortran.dg/associate_24.f90: New test.
	* gfortran.dg/assumed_type_2.f90: Adjust some of the tree dump
	checks.
	* gfortran.dg/no_arg_check_2.f90: Likewise.
	* gfortran.dg/pointer_array_1.f90: New test.
	* gfortran.dg/pointer_array_2.f90: New test.
	* gfortran.dg/pointer_array_7.f90: New test.
	* gfortran.dg/pointer_array_8.f90: New test.
	* gfortran.dg/pointer_array_component_1.f90: New test.
	* gfortran.dg/pointer_array_component_2.f90: New test.
	* gfortran.dg/goacc/kernels-alias-4.f95: Bump up both tree scan
	counts by 1.

	PR fortran/40737
	* gfortran.dg/pointer_array_3.f90: New test.

	PR fortran/57116
	* gfortran.dg/pointer_array_4.f90: New test.

	PR fortran/55763
	* gfortran.dg/pointer_array_5.f90: New test.

	PR fortran/57019
	* gfortran.dg/pointer_array_6.f90: New test.

2017-09-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34640
	* libgfortran/libgfortran.h: Add span field to descriptor.
	* libgfortran/libtool-version : Bump up version number to 5:0:0.

Added:
    trunk/gcc/testsuite/gfortran.dg/associate_24.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_1.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_2.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_3.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_4.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_5.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_6.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_7.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_8.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_component_1.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_array_component_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-array.h
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/fortran/trans.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/assumed_type_2.f90
    trunk/gcc/testsuite/gfortran.dg/goacc/kernels-alias-4.f95
    trunk/gcc/testsuite/gfortran.dg/no_arg_check_2.f90
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/libgfortran.h
    trunk/libgfortran/libtool-version
Comment 5 Paul Thomas 2017-09-10 17:17:01 UTC
Fixed on trunk.

I am sorry that it has taken so long.

Thanks for the report.

Paul