Bug 88980 - [9 regression] segfault on allocatable string member assignment
Summary: [9 regression] segfault on allocatable string member assignment
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 9.0
: P4 normal
Target Milestone: 9.0
Assignee: Paul Thomas
URL:
Keywords: wrong-code
Depends on:
Blocks: 68241
  Show dependency treegraph
 
Reported: 2019-01-22 15:18 UTC by Antony Lewis
Modified: 2019-02-03 14:55 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 7.4.0, 8.2.0
Known to fail: 9.0
Last reconfirmed: 2019-01-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antony Lewis 2019-01-22 15:18:12 UTC
This code gives seg fault in 9.0.0 20181010 and 9.0.0 20190103, OK in 8.2.1:
(same with P pointer or allocatable)


    program tester
    call gbug
    contains

    subroutine gbug
    type TNameValue
        character(LEN=:), allocatable :: Name
    end type TNameValue

    type TNameValue_pointer
        Type(TNameValue), allocatable :: P
    end type TNameValue_pointer

    Type TType
        type(TNameValue_pointer), dimension(:), allocatable :: Items
    end type TType
    Type(TType) T

    allocate(T%Items(2))
    allocate(T%Items(2)%P)
    T%Items(2)%P%Name =  'test'

    end subroutine gbug

    end program tester
Comment 1 Dominique d'Humieres 2019-01-23 11:22:18 UTC
> This code gives seg fault in 9.0.0 20181010 and 9.0.0 20190103, OK in 8.2.1:

Reduced range: r264722 (2018-09-30, OK) and r264810 (2018-10-03, serrault), likely r264724 (pr70752, pr72709).
Comment 2 Paul Thomas 2019-01-27 18:21:43 UTC
It seems to have been my fault and so I will take it. I am just dealing with two other regressions and then I will turn to this one.

Thanks

Paul
Comment 3 Paul Thomas 2019-02-02 09:17:15 UTC
Author: pault
Date: Sat Feb  2 09:16:44 2019
New Revision: 268473

URL: https://gcc.gnu.org/viewcvs?rev=268473&root=gcc&view=rev
Log:
2019-02-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/88980
	* trans-array.c (gfc_array_init_size): Add element_size to the
	arguments.
	(gfc_array_allocate): Remove the recalculation of the size of
	the element and use element_size from the call to the above.
	Unconditionally set the span field of the descriptor.

2019-02-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/88980
	* gfortran.dg/realloc_on_assign_32.f90 : New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/realloc_on_assign_32.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paul Thomas 2019-02-03 14:44:51 UTC
Author: pault
Date: Sun Feb  3 14:44:19 2019
New Revision: 268488

URL: https://gcc.gnu.org/viewcvs?rev=268488&root=gcc&view=rev
Log:
2019-02-02  Paul Thomas  <pault@gcc.gnu.org>

	Backport from trunk
	PR fortran/88980
	* trans-array.c (gfc_array_init_size): Add element_size to the
	arguments.
	(gfc_array_allocate): Remove the recalculation of the size of
	the element and use element_size from the call to the above.
	Unconditionally set the span field of the descriptor.

2019-02-02  Paul Thomas  <pault@gcc.gnu.org>

	Backport from trunk
	PR fortran/88980
	* gfortran.dg/realloc_on_assign_32.f90 : New test.


Added:
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/realloc_on_assign_32.f90
Modified:
    branches/gcc-8-branch/gcc/fortran/ChangeLog
    branches/gcc-8-branch/gcc/fortran/trans-array.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 5 Paul Thomas 2019-02-03 14:55:24 UTC
Fixed on 9-branch. Although it had no effect because finalization is not implemented in this case, the fix was applied to 8-branch as well so that the testcase is included in the tree.

Thanks for the report.

Paul