public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types
@ 2015-08-10 16:35 templed at tcd dot ie
  2015-09-05 10:47 ` [Bug fortran/67177] " dominiq at lps dot ens.fr
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: templed at tcd dot ie @ 2015-08-10 16:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67177

            Bug ID: 67177
           Summary: MOVE_ALLOC not automatically allocating deferred
                    character arrays in derived types
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: templed at tcd dot ie
  Target Milestone: ---

(First time submitting a bug, apologies if I've messed up somewhere)

When a derived type containing a deferred-length character variable is the TO=
argument of a MOVE_ALLOC() call the character length is not correctly set and
the value of the variable is not stored.

Two workarounds for this is to either not use deferred-length character
variables (use an allocatable array of single characters), or to preallocate
the length to the variable that will be the TO= argument.

The below test program has been tested with Intel 15.0.2 (20150121) and, when
the line critical line is commented out (see code) the program correctly
allocates the deferred-length string and populates it with the correct value.
In gfortran 5.2 (and 4.9.2, FWIW) it fails to allocate the length and store the
value even though a check with allocated() returns true.


$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/support/modules/gnu-5.2/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr/support/modules/gnu-5.2
--disable-multilib
Thread model: posix
gcc version 5.2.0 (GCC) 


Test program:

program str
implicit none

type string
  character(:), Allocatable :: text
end type string

type strings
  type(string), allocatable, dimension(:) :: strlist
end type strings

type(strings) :: teststrs
type(string) :: tmpstr
integer :: strlen = 20

allocate(teststrs%strlist(1))
allocate(character(len=strlen) :: tmpstr%text)

! This is the critical line. If this is commented then
! the move_alloc fails. Whereas what should happen is that
! this variable should be allocated automatically by move_alloc
allocate(character(len=strlen) :: teststrs%strlist(1)%text)


! Needs blanking otherwise memory is leaked
tmpstr%text(1:20) = ' '
tmpstr%text(1:3) = 'foo'
! Should return "alloc?, strlen F        20" when the critical line is
commented out (shows 'T' otherwise)
write(*,*)'alloc?, strlen
',allocated(teststrs%strlist(1)%text),len(tmpstr%text)
call move_alloc(tmpstr%text,teststrs%strlist(1)%text)
! Should return "alloc?, strlen T        20"
write(*,*)'alloc?, strlen
',allocated(teststrs%strlist(1)%text),len(teststrs%strlist(1)%text)
! Should return "foo                 "
write(*,*)'"',teststrs%strlist(1)%text,'"'

end program str


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/67177] MOVE_ALLOC not automatically allocating deferred character arrays in derived types
  2015-08-10 16:35 [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types templed at tcd dot ie
@ 2015-09-05 10:47 ` dominiq at lps dot ens.fr
  2015-10-17  9:36 ` pault at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-09-05 10:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67177

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-09-05
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed for 5.2 and trunk (6.0). Note that it is in general better to post
the non working test rather the working one.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/67177] MOVE_ALLOC not automatically allocating deferred character arrays in derived types
  2015-08-10 16:35 [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types templed at tcd dot ie
  2015-09-05 10:47 ` [Bug fortran/67177] " dominiq at lps dot ens.fr
@ 2015-10-17  9:36 ` pault at gcc dot gnu.org
  2015-10-17 13:49 ` pault at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2015-10-17  9:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67177

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pault at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org

--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Dominique d'Humieres from comment #1)
> Confirmed for 5.2 and trunk (6.0). Note that it is in general better to post
> the non working test rather the working one.

The hidden component ._text_length is not being set by MOVE_ALLOC. The move of
the allocation is occurring correctly, however.

I am wading into move_alloc right now to fix the bug reported on clf by Alberto
Luaces: https://groups.google.com/forum/#!topic/comp.lang.fortran/k3bkKUbOpFU

I'll take a swing at this bug this afternoon. Right now I have to paint
shutters :-(

Paul


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/67177] MOVE_ALLOC not automatically allocating deferred character arrays in derived types
  2015-08-10 16:35 [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types templed at tcd dot ie
  2015-09-05 10:47 ` [Bug fortran/67177] " dominiq at lps dot ens.fr
  2015-10-17  9:36 ` pault at gcc dot gnu.org
@ 2015-10-17 13:49 ` pault at gcc dot gnu.org
  2015-10-18  9:32 ` pault at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2015-10-17 13:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67177

--- Comment #3 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Paul Thomas from comment #2)
> (In reply to Dominique d'Humieres from comment #1)
> > Confirmed for 5.2 and trunk (6.0). Note that it is in general better to post
> > the non working test rather the working one.
> 
> The hidden component ._text_length is not being set by MOVE_ALLOC. The move
> of the allocation is occurring correctly, however.
> 
> I am wading into move_alloc right now to fix the bug reported on clf by
> Alberto Luaces:
> https://groups.google.com/forum/#!topic/comp.lang.fortran/k3bkKUbOpFU
> 
> I'll take a swing at this bug this afternoon. Right now I have to paint
> shutters :-(
> 
> Paul

In fact, the move_alloc part is one of two bugs exposed by this testcase.

The other bug is contained in:
! Needs blanking otherwise memory is leaked
tmpstr%text(1:20) = ' '
tmpstr%text(1:3) = 'foo'

and has been reported as PR67977. I'll fix this one as well, whilst I am about
it.

Cheers

Paul


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/67177] MOVE_ALLOC not automatically allocating deferred character arrays in derived types
  2015-08-10 16:35 [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types templed at tcd dot ie
                   ` (2 preceding siblings ...)
  2015-10-17 13:49 ` pault at gcc dot gnu.org
@ 2015-10-18  9:32 ` pault at gcc dot gnu.org
  2015-10-26 17:25 ` pault at gcc dot gnu.org
  2015-10-26 17:27 ` pault at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2015-10-18  9:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67177

--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Sun Oct 18 09:31:21 2015
New Revision: 228940

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

        PR fortran/67177
        PR fortran/67977
        * primary.c (match_substring): Add an argument 'deferred' to
        flag that a substring reference with null start and end should
        not be optimized away for deferred length strings.
        (match_string_constant, gfc_match_rvalue): Set the argument.
        * trans-expr.c (alloc_scalar_allocatable_for_assignment): If
        there is a substring reference return.
        * trans-intrinsic.c (conv_intrinsic_move_alloc): For deferred
        characters, assign the 'from' string length to the 'to' string
        length. If the 'from' expression is deferred, set its string
        length to zero. If the 'to' expression has allocatable
        components, deallocate them.

2015-10-18  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/67177
        * gfortran.dg/move_alloc_15.f90: New test
        * gfortran.dg/move_alloc_16.f90: New test

        PR fortran/67977
        * gfortran.dg/deferred_character_assignment_1.f90: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/deferred_character_assignment_1.f90
    trunk/gcc/testsuite/gfortran.dg/move_alloc_15.f90
    trunk/gcc/testsuite/gfortran.dg/move_alloc_16.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/67177] MOVE_ALLOC not automatically allocating deferred character arrays in derived types
  2015-08-10 16:35 [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types templed at tcd dot ie
                   ` (3 preceding siblings ...)
  2015-10-18  9:32 ` pault at gcc dot gnu.org
@ 2015-10-26 17:25 ` pault at gcc dot gnu.org
  2015-10-26 17:27 ` pault at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2015-10-26 17:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67177

--- Comment #5 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Mon Oct 26 17:25:03 2015
New Revision: 229386

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

        PR fortran/67177
        PR fortran/67977
        * primary.c (match_substring): Add an argument 'deferred' to
        flag that a substring reference with null start and end should
        not be optimized away for deferred length strings.
        (match_string_constant, gfc_match_rvalue): Set the argument.
        * trans-expr.c (alloc_scalar_allocatable_for_assignment): If
        there is a substring reference return.
        * trans-intrinsic.c (conv_intrinsic_move_alloc): For deferred
        characters, assign the 'from' string length to the 'to' string
        length. If the 'from' expression is deferred, set its string
        length to zero. If the 'to' expression has allocatable
        components, deallocate them.

2015-10-26  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/67177
        * gfortran.dg/move_alloc_15.f90: New test
        * gfortran.dg/move_alloc_16.f90: New test

        PR fortran/67977
        * gfortran.dg/deferred_character_assignment_1.f90: New test

Added:
   
branches/gcc-5-branch/gcc/testsuite/gfortran.dg/deferred_character_assignment_1.f90
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/move_alloc_15.f90
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/move_alloc_16.f90
Modified:
    branches/gcc-5-branch/gcc/fortran/ChangeLog
    branches/gcc-5-branch/gcc/fortran/primary.c
    branches/gcc-5-branch/gcc/fortran/trans-expr.c
    branches/gcc-5-branch/gcc/fortran/trans-intrinsic.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/67177] MOVE_ALLOC not automatically allocating deferred character arrays in derived types
  2015-08-10 16:35 [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types templed at tcd dot ie
                   ` (4 preceding siblings ...)
  2015-10-26 17:25 ` pault at gcc dot gnu.org
@ 2015-10-26 17:27 ` pault at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2015-10-26 17:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67177

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
Fixed on trunk and 5 branch.

Many thanks for the report

Paul


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-26 17:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10 16:35 [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types templed at tcd dot ie
2015-09-05 10:47 ` [Bug fortran/67177] " dominiq at lps dot ens.fr
2015-10-17  9:36 ` pault at gcc dot gnu.org
2015-10-17 13:49 ` pault at gcc dot gnu.org
2015-10-18  9:32 ` pault at gcc dot gnu.org
2015-10-26 17:25 ` pault at gcc dot gnu.org
2015-10-26 17:27 ` pault at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).