public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/113671] New: Passing allocatable character(:) slices with negative stride: invalid memory access / segfault
@ 2024-01-30 16:32 orbisvicis+gcc at gmail dot com
2024-01-30 18:48 ` [Bug fortran/113671] " kargl at gcc dot gnu.org
2024-01-30 19:50 ` anlauf at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: orbisvicis+gcc at gmail dot com @ 2024-01-30 16:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113671
Bug ID: 113671
Summary: Passing allocatable character(:) slices with negative
stride: invalid memory access / segfault
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: orbisvicis+gcc at gmail dot com
Target Milestone: ---
Created attachment 57262
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57262&action=edit
Various conditions to explore the invalid memory access
When passing an allocatable character(:) slice with negative stride, gfortran
either segfaults or accesses invalid memory.
* GNU Fortran (GCC) 11.4.0 on Cygwin 3.4.7-1.x86_64 segfaults (invalid memory
access)
* x86_64 GFortran 13.2|trunk on godbolt.org accesses invalid memory
Actual output:
```
testing: 1 3 5
one
!
```
Expected output:
```
testing: 1 3 5
three
two
one
```
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug fortran/113671] Passing allocatable character(:) slices with negative stride: invalid memory access / segfault
2024-01-30 16:32 [Bug fortran/113671] New: Passing allocatable character(:) slices with negative stride: invalid memory access / segfault orbisvicis+gcc at gmail dot com
@ 2024-01-30 18:48 ` kargl at gcc dot gnu.org
2024-01-30 19:50 ` anlauf at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: kargl at gcc dot gnu.org @ 2024-01-30 18:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113671
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
CC| |kargl at gcc dot gnu.org
Last reconfirmed| |2024-01-30
Status|UNCONFIRMED |NEW
Priority|P3 |P4
--- Comment #1 from kargl at gcc dot gnu.org ---
Reduced testcase.
program arrays10
implicit none
character(:), allocatable :: b(:)
allocate(character(len=1) :: b(1)) ! <- remove a bunch of uninitialized
! <-1 -Wall warnings.
b = [ character(5) :: "one", "two", "three"]
call test03(b(size(b):1:-1))
contains
subroutine test03(a)
character(*), intent(in) :: a(*)
print *, "testing: ", rank(a), size(a(:3)), len(a(1))
end subroutine test03
end program arrays10
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug fortran/113671] Passing allocatable character(:) slices with negative stride: invalid memory access / segfault
2024-01-30 16:32 [Bug fortran/113671] New: Passing allocatable character(:) slices with negative stride: invalid memory access / segfault orbisvicis+gcc at gmail dot com
2024-01-30 18:48 ` [Bug fortran/113671] " kargl at gcc dot gnu.org
@ 2024-01-30 19:50 ` anlauf at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-01-30 19:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113671
--- Comment #2 from anlauf at gcc dot gnu.org ---
Another reduced variant:
program arrays10
implicit none
character(5), allocatable :: a(:)
character(:), allocatable :: b(:)
a = [ character(5) :: "one", "two", "three"]
b = [ character(5) :: "one", "two", "three"]
call test02 (a) ! OK
call test02 (b) ! OK
call test02 (a(size(a):1:-1)) ! OK
call test02 (b(size(b):1:-1)) ! random junk or crash
contains
subroutine test02 (a)
character(*), intent(in) :: a(:)
print *, a
end
end
This prints at runtime e.g.
% ./a.out | cat -ev
one two three$
one two three$
threetwo one $
one ^@^@^@^@^@^@^@!^@^@$
Forcing an explicit temporary helps, as with
call test02((b(size(b):1:-1)))
***
The uninitialized warnings Steve mentions corresponds to issues visible
in the tree dump: it appears the the length .b is used before it is set.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-30 19:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 16:32 [Bug fortran/113671] New: Passing allocatable character(:) slices with negative stride: invalid memory access / segfault orbisvicis+gcc at gmail dot com
2024-01-30 18:48 ` [Bug fortran/113671] " kargl at gcc dot gnu.org
2024-01-30 19:50 ` 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).