public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/97039] New: -fbounds-check misses violation with slice of array but not an element
@ 2020-09-13 15:04 anthony.debeus at gmail dot com
2020-09-13 16:35 ` [Bug fortran/97039] " kargl at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: anthony.debeus at gmail dot com @ 2020-09-13 15:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97039
Bug ID: 97039
Summary: -fbounds-check misses violation with slice of array
but not an element
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: anthony.debeus at gmail dot com
Target Milestone: ---
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC)
gfortran -Wall -Wextra -fbounds-check -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -fsanitize=undefined arrays.f90 test.f90
or just
gfortran -fbounds-check arrays.f90 test.f90
test.f90
PROGRAM test
USE arrays
call init_mat(MM,N,RM)
write(*,*) RM%r(257,:) ! this prints out the out-of-bounds slice INCORRECTLY
write(*,*) RM%r(257,1) ! this is caught correctly (line 7 below)
write(*,*) size(RM%r)
END
arrays.f90
MODULE arrays
INTEGER, PARAMETER :: MM=180, N=22
TYPE RMatrix
REAL, ALLOCATABLE :: r(:,:)
END TYPE RMatrix
TYPE(RMatrix) :: RM
CONTAINS
subroutine init_mat(MM,N,RM) ! allocate arrays
INTEGER, INTENT(IN) :: MM,N
TYPE(RMatrix) :: RM
allocate (RM%r(MM,N))
end subroutine init_mat
end module
produces
./a.out
0.00000000 0.00000000 0.00000000 0.00000000
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
0.00000000 0.00000000 0.00000000 0.00000000
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
0.00000000 0.00000000 0.00000000 0.00000000
At line 7 of file test.f90
Fortran runtime error: Index '257' of dimension 1 of array 'rm%r' above upper
bound of 180
Error termination. Backtrace:
#0 0x55edbad311c8 in ???
#1 0x55edbad31394 in ???
#2 0x7fc2b3ff7151 in ???
#3 0x55edbad2f16d in ???
#4 0xffffffffffffffff in ???
the correct result from the PGI/NVIDIA (v 20.7) compiler follows
pgf90 -C arrays.f90 test.f90
./a.out
0: Subscript out of range for array rm%r (test.f90: 6)
subscript=257, lower bound=1, upper bound=180, dimension=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/97039] -fbounds-check misses violation with slice of array but not an element
2020-09-13 15:04 [Bug fortran/97039] New: -fbounds-check misses violation with slice of array but not an element anthony.debeus at gmail dot com
@ 2020-09-13 16:35 ` kargl at gcc dot gnu.org
2020-10-15 23:00 ` anthony.debeus at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: kargl at gcc dot gnu.org @ 2020-09-13 16:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97039
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #1 from kargl at gcc dot gnu.org ---
(In reply to Anthony M de Beus from comment #0)
>
> the correct result from the PGI/NVIDIA (v 20.7) compiler follows
>
As the Fortran code is invalid, there are no correct results.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/97039] -fbounds-check misses violation with slice of array but not an element
2020-09-13 15:04 [Bug fortran/97039] New: -fbounds-check misses violation with slice of array but not an element anthony.debeus at gmail dot com
2020-09-13 16:35 ` [Bug fortran/97039] " kargl at gcc dot gnu.org
@ 2020-10-15 23:00 ` anthony.debeus at gmail dot com
2020-10-16 20:43 ` anlauf at gcc dot gnu.org
2023-09-15 18:21 ` anlauf at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: anthony.debeus at gmail dot com @ 2020-10-15 23:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97039
--- Comment #2 from Anthony M de Beus <anthony.debeus at gmail dot com> ---
Clarification for anyone confused, "correct" results by a fortran compiler with
bounds-checking enabled would include finding/checking incorrect bounds in
(deliberately) incorrect fortran code given in the illustrative example.
Hence in the example given, the pgf90 v.20.7 compiler correctly identifies the
incorrect fortran code involving the array slice, whereas the gfortran compiler
only catches the second error in the code, involving a specific element, but
not the first error, involving a slice.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/97039] -fbounds-check misses violation with slice of array but not an element
2020-09-13 15:04 [Bug fortran/97039] New: -fbounds-check misses violation with slice of array but not an element anthony.debeus at gmail dot com
2020-09-13 16:35 ` [Bug fortran/97039] " kargl at gcc dot gnu.org
2020-10-15 23:00 ` anthony.debeus at gmail dot com
@ 2020-10-16 20:43 ` anlauf at gcc dot gnu.org
2023-09-15 18:21 ` anlauf at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-16 20:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97039
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Last reconfirmed| |2020-10-16
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
CC| |anlauf at gcc dot gnu.org
--- Comment #3 from anlauf at gcc dot gnu.org ---
Reduced testcase:
program test
implicit none
integer, parameter :: m=2, n=3
real, allocatable :: r(:,:)
allocate (r(m,n))
write(*,*) r(m+1,:)
write(*,*) r(m+1,1)
end
Looking at the tree dump, there are array bounds checks generated for both
dimensions in the latter write, but there are suspiciously looking checks
for dimension 2 for the first case (r(m+1,:)).
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/97039] -fbounds-check misses violation with slice of array but not an element
2020-09-13 15:04 [Bug fortran/97039] New: -fbounds-check misses violation with slice of array but not an element anthony.debeus at gmail dot com
` (2 preceding siblings ...)
2020-10-16 20:43 ` anlauf at gcc dot gnu.org
@ 2023-09-15 18:21 ` anlauf at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-09-15 18:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97039
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|NEW |RESOLVED
--- Comment #4 from anlauf at gcc dot gnu.org ---
Should be fixed by r14-4039-g1cbf18978aa384 for pr30802.
Thus marking as duplicate.
*** This bug has been marked as a duplicate of bug 30802 ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-09-15 18:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-13 15:04 [Bug fortran/97039] New: -fbounds-check misses violation with slice of array but not an element anthony.debeus at gmail dot com
2020-09-13 16:35 ` [Bug fortran/97039] " kargl at gcc dot gnu.org
2020-10-15 23:00 ` anthony.debeus at gmail dot com
2020-10-16 20:43 ` anlauf at gcc dot gnu.org
2023-09-15 18:21 ` 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).