public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/64854] New: No bound check for explicit-shape arrays
@ 2015-01-29 10:03 bugs at stellardeath dot org
  2015-01-29 10:59 ` [Bug fortran/64854] " dominiq at lps dot ens.fr
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bugs at stellardeath dot org @ 2015-01-29 10:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64854
           Summary: No bound check for explicit-shape arrays
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugs at stellardeath dot org

I assumed that the following would be catched by -fcheck=bounds,
array "a" is passed as an explicit-shape array to subroutine
"testsub" with the invalid bounds "n1", "n2":

program test
  use m1
  implicit none

  integer :: n1, n2
  real :: a(1:10)

  ! Setup invalid indices:
  n1 = 1024*1024
  n2 = 1024*1024*2

  call testsub(a, n1, n2)

  contains

    subroutine testsub(a, n1, n2)
      integer :: n1, n2
      real :: a(n1:n2)
      integer :: i

      do i = n1, n2
        a(i) = 0
      end do

    end subroutine

end program

But this happily produces a segfault.


My gfortran version:

#> gfortran-4.9 --version
GNU Fortran (SUSE Linux) 4.9.0
Copyright (C) 2014 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING


Kind regards,
  Lorenz


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

* [Bug fortran/64854] No bound check for explicit-shape arrays
  2015-01-29 10:03 [Bug fortran/64854] New: No bound check for explicit-shape arrays bugs at stellardeath dot org
@ 2015-01-29 10:59 ` dominiq at lps dot ens.fr
  2015-01-29 20:17 ` anlauf at gmx dot de
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-01-29 10:59 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2015-01-29
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Well, you give wrong information to the compiler. How do expect it to handle
your mistake: in testsub -fcheck=bounds checks that n1<=i<=n2 which is the
case. What you ask for is a check that a(n1:n2) is inside a(1:10), AFAIK such
check is not implemented and I don't have any idea about how difficult it is to
implement it.

I am inclined to close tis PR as INVALID or WONTFIX.


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

* [Bug fortran/64854] No bound check for explicit-shape arrays
  2015-01-29 10:03 [Bug fortran/64854] New: No bound check for explicit-shape arrays bugs at stellardeath dot org
  2015-01-29 10:59 ` [Bug fortran/64854] " dominiq at lps dot ens.fr
@ 2015-01-29 20:17 ` anlauf at gmx dot de
  2015-01-29 20:49 ` bugs at stellardeath dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gmx dot de @ 2015-01-29 20:17 UTC (permalink / raw)
  To: gcc-bugs

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

Harald Anlauf <anlauf at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gmx dot de

--- Comment #3 from Harald Anlauf <anlauf at gmx dot de> ---
(In reply to Dominique d'Humieres from comment #1)
> Well, you give wrong information to the compiler. How do expect it to handle
> your mistake: in testsub -fcheck=bounds checks that n1<=i<=n2 which is the
> case. What you ask for is a check that a(n1:n2) is inside a(1:10), AFAIK
> such check is not implemented and I don't have any idea about how difficult
> it is to implement it.

valgrind detects this issue.

I was expected that the address sanitizer is able to handle it,
but I am getting linking errors on my system.

> I am inclined to close tis PR as INVALID or WONTFIX.

The right way to fix the problem is to fix the program
by using an appropriate programming style.  Writing

      real    :: a(n1:)   ! not:  real :: a(n1:n2)

one gets the expected check:

At line 22 of file pr64854.f90
Fortran runtime error: Index '1048586' of dimension 1 of array 'a' above upper
bound of 1048585

Backtrace for this error:
  + function testsub.3321 (0x80486A4)
    from file pr64854.f90
  + in the main program
    from file pr64854.f90
  + /lib/libc.so.6(__libc_start_main+0xf3) [0xb7424003]

I also suggest to close the PR.


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

* [Bug fortran/64854] No bound check for explicit-shape arrays
  2015-01-29 10:03 [Bug fortran/64854] New: No bound check for explicit-shape arrays bugs at stellardeath dot org
  2015-01-29 10:59 ` [Bug fortran/64854] " dominiq at lps dot ens.fr
  2015-01-29 20:17 ` anlauf at gmx dot de
@ 2015-01-29 20:49 ` bugs at stellardeath dot org
  2015-01-29 22:39 ` dominiq at lps dot ens.fr
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bugs at stellardeath dot org @ 2015-01-29 20:49 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 3079 bytes --]

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

--- Comment #4 from Lorenz Hüdepohl <bugs at stellardeath dot org> ---
> The right way to fix the problem is to fix the program
> by using an appropriate programming style.  Writing
>
>      real    :: a(n1:)   ! not:  real :: a(n1:n2)
>
> one gets the expected check

I realize that, and when I write my own code I would never
use such a construction. However, sometimes one is burdened
with existing code in which small treasures such as this kind
of bug are hidden.

I was hoping that with -fcheck=bounds I could find this.

If the code was correct already there would be no need for
any kind of runtime checks, right?
>From gcc-bugs-return-475454-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jan 29 21:01:40 2015
Return-Path: <gcc-bugs-return-475454-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 20273 invoked by alias); 29 Jan 2015 21:01:38 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 20211 invoked by uid 48); 29 Jan 2015 21:01:27 -0000
From: "emsr at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/64351] std::uniform_real_distribution<float>(0, 1) returns 1
Date: Thu, 29 Jan 2015 21:01:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Version: 3.3.6
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: emsr at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc attachments.created
Message-ID: <bug-64351-4-Z98QBfIzo6@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64351-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64351-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-01/txt/msg03448.txt.bz2
Content-length: 576

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd351

emsr at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |emsr at gcc dot gnu.org

--- Comment #1 from emsr at gcc dot gnu.org ---
Created attachment 34621
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id4621&actioníit
Just keep trying in generate_canonical...

I'm going to test this...

Just keep looping until you get less that one in generate_canonical.


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

* [Bug fortran/64854] No bound check for explicit-shape arrays
  2015-01-29 10:03 [Bug fortran/64854] New: No bound check for explicit-shape arrays bugs at stellardeath dot org
                   ` (2 preceding siblings ...)
  2015-01-29 20:49 ` bugs at stellardeath dot org
@ 2015-01-29 22:39 ` dominiq at lps dot ens.fr
  2015-01-29 22:41 ` anlauf at gmx dot de
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-01-29 22:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Note that the error is detected if the code is compiled with
-fsanitize=address. And IMO the right way to use the array in a 'contains' is
a(:) (for which -fcheck=bounds works).


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

* [Bug fortran/64854] No bound check for explicit-shape arrays
  2015-01-29 10:03 [Bug fortran/64854] New: No bound check for explicit-shape arrays bugs at stellardeath dot org
                   ` (3 preceding siblings ...)
  2015-01-29 22:39 ` dominiq at lps dot ens.fr
@ 2015-01-29 22:41 ` anlauf at gmx dot de
  2015-01-30 12:54 ` bugs at stellardeath dot org
  2015-08-29 13:53 ` dominiq at lps dot ens.fr
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gmx dot de @ 2015-01-29 22:41 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 3640 bytes --]

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

--- Comment #6 from Harald Anlauf <anlauf at gmx dot de> ---
(In reply to Lorenz Hüdepohl from comment #4)
> > The right way to fix the problem is to fix the program
> > by using an appropriate programming style.  Writing
> >
> >      real    :: a(n1:)   ! not:  real :: a(n1:n2)
> >
> > one gets the expected check
> 
> I realize that, and when I write my own code I would never
> use such a construction. However, sometimes one is burdened
> with existing code in which small treasures such as this kind
> of bug are hidden.
> 
> I was hoping that with -fcheck=bounds I could find this.

As Dominique pointed out, this is not the way bounds checking
is usually implemented.  Checks are local.

Fortran allows you to intentionally bypass all checks by
using explicit size specifications.  You can even use different
ranks of the array in the caller and the callee.  If you lie to
the compiler in that situation about proper sizes, then you lose.

> If the code was correct already there would be no need for
> any kind of runtime checks, right?

Right.  But IMHO bounds check are not applicable here.
Try other compilers.  I'd expect them to behave similarly.

Use valgrind or -fsanitize=address to detect this kind of
memory problems.  (I solved my linking problem by updating
to current trunk).
>From gcc-bugs-return-475468-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Jan 30 00:18:25 2015
Return-Path: <gcc-bugs-return-475468-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 29260 invoked by alias); 30 Jan 2015 00:18:23 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 29172 invoked by uid 48); 30 Jan 2015 00:18:17 -0000
From: "dodji at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug preprocessor/64803] [5 Regression] __LINE__ inside macro is not constant
Date: Fri, 30 Jan 2015 00:18:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: preprocessor
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: dodji at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P1
X-Bugzilla-Assigned-To: dodji at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 5.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: attachments.created
Message-ID: <bug-64803-4-lyJhiNckHX@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64803-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64803-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-01/txt/msg03462.txt.bz2
Content-length: 462

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd803

--- Comment #6 from Dodji Seketeli <dodji at gcc dot gnu.org> ---
Created attachment 34622
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id4622&actioníit
Refined candidate fix patch with regression test and cover letter

I have successfully tested this refined patch locally and I am
currently bootstrapping it.  I'll submit it right away if it passes
bootstrap.  Thanks for testing the previous one!


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

* [Bug fortran/64854] No bound check for explicit-shape arrays
  2015-01-29 10:03 [Bug fortran/64854] New: No bound check for explicit-shape arrays bugs at stellardeath dot org
                   ` (4 preceding siblings ...)
  2015-01-29 22:41 ` anlauf at gmx dot de
@ 2015-01-30 12:54 ` bugs at stellardeath dot org
  2015-08-29 13:53 ` dominiq at lps dot ens.fr
  6 siblings, 0 replies; 8+ messages in thread
From: bugs at stellardeath dot org @ 2015-01-30 12:54 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 2689 bytes --]

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

--- Comment #7 from Lorenz Hüdepohl <bugs at stellardeath dot org> ---
> Use valgrind or -fsanitize=address to detect this kind of
> memory problems.

I can live with that, thanks for your comments!
>From gcc-bugs-return-475518-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Jan 30 13:05:41 2015
Return-Path: <gcc-bugs-return-475518-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 4112 invoked by alias); 30 Jan 2015 13:05:40 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 4011 invoked by uid 48); 30 Jan 2015 13:05:30 -0000
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/64670] -fsanitize=vptr leads to "undefined reference to `typeinfo for class'"
Date: Fri, 30 Jan 2015 13:05:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: sanitizer
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: wrong-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: burnus at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: attachments.isobsolete attachments.created
Message-ID: <bug-64670-4-ZXkxQT5GVn@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64670-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64670-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-01/txt/msg03512.txt.bz2
Content-length: 576

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd670

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #34487|0                           |1
        is obsolete|                            |

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 34627
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id4627&actioníit
Updated test case (part 1/2): [main file] compile with g++ -fsanitize=vptr


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

* [Bug fortran/64854] No bound check for explicit-shape arrays
  2015-01-29 10:03 [Bug fortran/64854] New: No bound check for explicit-shape arrays bugs at stellardeath dot org
                   ` (5 preceding siblings ...)
  2015-01-30 12:54 ` bugs at stellardeath dot org
@ 2015-08-29 13:53 ` dominiq at lps dot ens.fr
  6 siblings, 0 replies; 8+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-08-29 13:53 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #8 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Per comment 7, closing as WONTFIX.


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

end of thread, other threads:[~2015-08-29 13:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-29 10:03 [Bug fortran/64854] New: No bound check for explicit-shape arrays bugs at stellardeath dot org
2015-01-29 10:59 ` [Bug fortran/64854] " dominiq at lps dot ens.fr
2015-01-29 20:17 ` anlauf at gmx dot de
2015-01-29 20:49 ` bugs at stellardeath dot org
2015-01-29 22:39 ` dominiq at lps dot ens.fr
2015-01-29 22:41 ` anlauf at gmx dot de
2015-01-30 12:54 ` bugs at stellardeath dot org
2015-08-29 13:53 ` dominiq at lps dot ens.fr

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).