Bug 89352 - Deferred length character array pointer error
Summary: Deferred length character array pointer error
Status: RESOLVED DUPLICATE of bug 71880
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.2.0
: P4 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 68241
  Show dependency treegraph
 
Reported: 2019-02-14 13:36 UTC by Christian Langevin
Modified: 2019-02-14 19:43 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Langevin 2019-02-14 13:36:30 UTC
I have two deferred length character arrays in gfortran.  I allocate one of them, and then point the other one to it.  The pointer variable has the correct array size, but not the correct character length.  The program terminates with an error when trying to access the information in the pointer.

I see that there may be related bugs that have been fixed (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51976), but this one is present now in version 8.

I'm testing this with:
GNU Fortran (MacPorts gcc8 8.2.0_2) 8.2.0

and also
GNU Fortran (MacPorts gcc8 8.2.0_3) 8.2.0


The code below works fine with Intel Fortran on Windows.

    program test
      implicit none
      character(len=:), pointer, dimension(:) :: charvara
      character(len=:), pointer, dimension(:) :: charvara_ptr
      
      allocate(character(len=10) :: charvara(3))
      charvara(:) = '0123456789'
      print *, 'len(charvara) = ', len(charvara)
      print *, 'size(charvara) = ', size(charvara)
      print *, 'charvara = ', charvara
      
      charvara_ptr => charvara
      print *, 'associated = ', associated(charvara_ptr, charvara)
      print *, 'len(charvara_ptr) = ', len(charvara_ptr)
      print *, 'size(charvara_ptr) = ', size(charvara_ptr)
      print *, 'charvara_ptr = ', charvara_ptr
      
      print *, 'end'
     
    end program test

I would expect the length, size, and contents of charvara_ptr to be the same as charvara, but instead I get the following:

     len(charvara) =           10
     size(charvara) =            3
     charvara = 012345678901234567890123456789
     associated =  T
     len(charvara_ptr) =   1708412736
     size(charvara_ptr) =            3
    test(71321,0x7fff9e47c380) malloc: *** mach_vm_map(size=140734901800960) failed (error code=3)
    *** error: can't allocate region
    *** set a breakpoint in malloc_error_break to debug
    Operating system error: Cannot allocate memory
    Memory allocation failure in xrealloc
    
    Error termination. Backtrace:
    #0  0x10bb11f8f
    #1  0x10bb127fd
    #2  0x10bb12987
    #3  0x10bb119f9
    #4  0x10bbc8950
    #5  0x10bbbf147
    #6  0x10bbc4b61
    #7  0x10bbc7cd8
    #8  0x10bbc877e
    #9  0x10bb0ccab
    #10  0x10bb0cd6e
Comment 1 kargls 2019-02-14 18:10:23 UTC
The code works as expected with gfortran from trunk.  Whether
the patch that fixed the bud will be back ported remains to
be detemined.
Comment 2 Dominique d'Humieres 2019-02-14 19:43:19 UTC
I think it is a duplicate of pr71880.

I don't know how to read Paul's comment:

> I am trying to build up the intestinal fortitude to go back through
> some of the recent fixes and apply them to 8-branch.

*** This bug has been marked as a duplicate of bug 71880 ***