public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/111304] New: Problem when passing implicit arrays of characters to functions
@ 2023-09-06 11:14 mailling-lists-bd at posteo dot de
  2023-09-06 14:53 ` [Bug fortran/111304] " mailling-lists-bd at posteo dot de
  2023-09-06 17:34 ` anlauf at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: mailling-lists-bd at posteo dot de @ 2023-09-06 11:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111304
           Summary: Problem when passing implicit arrays of characters to
                    functions
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mailling-lists-bd at posteo dot de
  Target Milestone: ---

Hi,

In the following code, the first call to `func1` works as expected and prints
the content of the array `my_directory`, while the second call, with the array
defined directly in the function argument, leads to SIGABRT and prints 
```
 ARRAY = my_directory/file1my_directory/file2my_directory/dum1
my_directory/dum2
corrupted size vs. prev_size
```

I have tested with gfortran 13.2.1 (gfortran -o test program.f90), on Fedora
38. It should also be noticed that both function calls run fine if we remove
the `trim(prefix)//` from each character string.


```
program test
  implicit none

  character(len=256) :: test_array(4)
  character(len=:), allocatable :: prefix
  integer :: res

  prefix = 'my_directory'
  test_array = [ character(len=256) :: &
       & trim(prefix)//'/file1', &
       & trim(prefix)//'/file2', &
       & trim(prefix)//'/dum1', &
       & trim(prefix)//'/dum2' &
       & ]

  print *, 'Test with "res = func1(test_array)"'
  res = func1(test_array)

  print *, 'Test with "res = func1([ character(len=) :: ...] )"'
  res = func1([ character(len=256) :: &
       & trim(prefix)//'/file1', &
       & trim(prefix)//'/file2', &
       & trim(prefix)//'/dum1', &
       & trim(prefix)//'/dum2' &
       & ])


contains

  function func1(array) result(res)
    character(len=*), intent(in) :: array(:)

    integer :: res

    print *, 'ARRAY = ', array
    res = 0
  end function func1
end program test
```

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

* [Bug fortran/111304] Problem when passing implicit arrays of characters to functions
  2023-09-06 11:14 [Bug fortran/111304] New: Problem when passing implicit arrays of characters to functions mailling-lists-bd at posteo dot de
@ 2023-09-06 14:53 ` mailling-lists-bd at posteo dot de
  2023-09-06 17:34 ` anlauf at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: mailling-lists-bd at posteo dot de @ 2023-09-06 14:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Baptiste Demoulin <mailling-lists-bd at posteo dot de> ---
One comment: replacing `trim(prefix)` with `prefix(1:len_trim(prefix))` leads
to the same result, as does putting simply `prefix`, so the problem does not
seem to be related to using the `trim` function.

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

* [Bug fortran/111304] Problem when passing implicit arrays of characters to functions
  2023-09-06 11:14 [Bug fortran/111304] New: Problem when passing implicit arrays of characters to functions mailling-lists-bd at posteo dot de
  2023-09-06 14:53 ` [Bug fortran/111304] " mailling-lists-bd at posteo dot de
@ 2023-09-06 17:34 ` anlauf at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-09-06 17:34 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
                 CC|                            |anlauf at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from anlauf at gcc dot gnu.org ---
Looks like a duplicate of pr85547.

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

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

end of thread, other threads:[~2023-09-06 17:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06 11:14 [Bug fortran/111304] New: Problem when passing implicit arrays of characters to functions mailling-lists-bd at posteo dot de
2023-09-06 14:53 ` [Bug fortran/111304] " mailling-lists-bd at posteo dot de
2023-09-06 17:34 ` anlauf 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).