public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anthony.debeus at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/97039] New: -fbounds-check misses violation with slice of array but not an element
Date: Sun, 13 Sep 2020 15:04:38 +0000	[thread overview]
Message-ID: <bug-97039-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2020-09-13 15:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-13 15:04 anthony.debeus at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97039-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).