public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31119]  New: Bogus "array abound mismatch" for -fbounds-check
@ 2007-03-10  8:39 burnus at gcc dot gnu dot org
  2007-03-10  8:47 ` [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking burnus at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-03-10  8:39 UTC (permalink / raw)
  To: gcc-bugs

The following program produces the wrong error:

 ivec_=           1           2
Fortran runtime error: Array bound mismatch, size mismatch for dimension 1 of
array 'ivec' (in file 'x.f90', at line 20)
with -fbounds-check.

Taken from:

http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/b8313f7232d8a5f5/


module sub_mod
contains
elemental subroutine set_optional(i,idef,iopt)
! set i to (iopt,idef) if iopt (is,is not) PRESENT
integer, intent(out)          :: i
integer, intent(in)           :: idef
integer, intent(in), optional :: iopt
if (present(iopt)) then
   i = iopt
else
   i = idef
end if
end subroutine set_optional
!
subroutine sub(ivec)
integer          , intent(in), optional :: ivec(:)
integer                                 :: ivec_(2)
call set_optional(ivec_,(/1,2/))
print*,"ivec_=",ivec_
call set_optional(ivec_,(/1,2/),ivec)
print*,"ivec_=",ivec_
end subroutine sub
end module sub_mod

program main
use sub_mod, only: sub
call sub()
end program main


-- 
           Summary: Bogus "array abound mismatch" for -fbounds-check
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code, diagnostic
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org
OtherBugsDependingO 27766
             nThis:


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
  2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
@ 2007-03-10  8:47 ` burnus at gcc dot gnu dot org
  2007-03-10 12:43 ` fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-03-10  8:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2007-03-10 08:47 -------
The problem is that the bounds of an optional argument are checked,
regardlessly whether it is present.

  int8 ubound.0;
  if (ivec != 0B)
    {
        ubound.0 = (ivec->dim[0].ubound - ivec->dim[0].lbound) + 1;
    }
  {
    int8 D.1373;
    if ((logical4) __builtin_expect ((int8) (D.1373 > 0 && ubound.0 <= 0), 0))
      {
        _gfortran_runtime_error ("Array reference out of bounds, upper bound of
dimension 1 of array \'ivec\' exceeded (in file \'x.f90


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Bogus "array abound         |-fbounds-check: Check for
                   |mismatch" for -fbounds-check|presence of optional
                   |                            |arguments before bound
                   |                            |checking


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
  2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
  2007-03-10  8:47 ` [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking burnus at gcc dot gnu dot org
@ 2007-03-10 12:43 ` fxcoudert at gcc dot gnu dot org
  2007-03-18 17:49 ` fxcoudert at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-10 12:43 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-03-10 12:43:31
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
  2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
  2007-03-10  8:47 ` [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking burnus at gcc dot gnu dot org
  2007-03-10 12:43 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-18 17:49 ` fxcoudert at gcc dot gnu dot org
  2007-03-19  9:05 ` fxcoudert at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-18 17:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from fxcoudert at gcc dot gnu dot org  2007-03-18 17:49 -------
*** Bug 31148 has been marked as a duplicate of this bug. ***


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vivekrao4 at yahoo dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
  2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-03-18 17:49 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-19  9:05 ` fxcoudert at gcc dot gnu dot org
  2007-05-09  7:09 ` fxcoudert at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-19  9:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fxcoudert at gcc dot gnu dot org  2007-03-19 09:05 -------
Created an attachment (id=13229)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13229&action=view)
Patch that fixes the issue reported

The attached patch fixes the issue for the reported testcase. I checked that we
still issue errors when the optional parameter is present and has the wrong
size; the code below will error out as expected if one of the commented lines
is uncommented:

module sub_mod
contains
elemental subroutine set_optional(i,idef,iopt)
! set i to (iopt,idef) if iopt (is,is not) PRESENT
integer, intent(out)          :: i
integer, intent(in)           :: idef
integer, intent(in), optional :: iopt
if (present(iopt)) then
   i = iopt
else
   i = idef
end if
end subroutine set_optional

  subroutine sub(ivec)
    integer          , intent(in), optional :: ivec(:)
    integer                                 :: ivec_(2)
    call set_optional(ivec_,(/1,2/))
    print*,"ivec_=",ivec_
    call set_optional(ivec_,(/1,2/),ivec)
    print*,"ivec_=",ivec_
  end subroutine sub
end module sub_mod

program main
  use sub_mod, only: sub
  call sub()
  call sub((/4,5/))
!  call sub((/4/))
!  call sub((/4,5,6/))
end program main


Anyway, the other calls to checking routines need to be audited for similar
problems with optional args. That probably includes making a testcase for each
situation, and see if optional arg can be used in each context.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
  2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-03-19  9:05 ` fxcoudert at gcc dot gnu dot org
@ 2007-05-09  7:09 ` fxcoudert at gcc dot gnu dot org
  2007-07-04  6:35 ` jv244 at cam dot ac dot uk
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-05-09  7:09 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-03-10 12:43:31         |2007-05-09 08:09:33
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
  2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2007-05-09  7:09 ` fxcoudert at gcc dot gnu dot org
@ 2007-07-04  6:35 ` jv244 at cam dot ac dot uk
  2007-09-18 21:26 ` fxcoudert at gcc dot gnu dot org
  2007-09-18 21:34 ` fxcoudert at gcc dot gnu dot org
  7 siblings, 0 replies; 13+ messages in thread
From: jv244 at cam dot ac dot uk @ 2007-07-04  6:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jv244 at cam dot ac dot uk  2007-07-04 06:35 -------
patch ping ?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
  2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2007-07-04  6:35 ` jv244 at cam dot ac dot uk
@ 2007-09-18 21:26 ` fxcoudert at gcc dot gnu dot org
  2007-09-18 21:34 ` fxcoudert at gcc dot gnu dot org
  7 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-09-18 21:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fxcoudert at gcc dot gnu dot org  2007-09-18 21:25 -------
Subject: Bug 31119

Author: fxcoudert
Date: Tue Sep 18 21:25:40 2007
New Revision: 128587

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128587
Log:
        PR fortran/31119

        * trans-array.c (gfc_conv_ss_startstride): Only perform bounds
        checking for optional args when they are present.

        * gfortran.dg/bounds_check_9.f90: New test.
        * gfortran.dg/bounds_check_fail_2.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/bounds_check_9.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_check_fail_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
  2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2007-09-18 21:26 ` fxcoudert at gcc dot gnu dot org
@ 2007-09-18 21:34 ` fxcoudert at gcc dot gnu dot org
  7 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-09-18 21:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fxcoudert at gcc dot gnu dot org  2007-09-18 21:34 -------
Fixed.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
       [not found] <bug-31119-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2012-10-20 15:43 ` dominiq at lps dot ens.fr
@ 2012-10-21 13:53 ` mikael at gcc dot gnu.org
  3 siblings, 0 replies; 13+ messages in thread
From: mikael at gcc dot gnu.org @ 2012-10-21 13:53 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119

Mikael Morin <mikael at gcc dot gnu.org> changed:

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

--- Comment #10 from Mikael Morin <mikael at gcc dot gnu.org> 2012-10-21 13:52:35 UTC ---
(In reply to comment #8)
> Actually, the situation is a bit bizarre. There are no conforming programs for
> which bounds-checking can trigger... all these bounds-checking statements can
> be just optimized away :-). That's not quite what the users want...

Well, if the middle-end is able to prove that the bounds checking code is
useless, it may as well remove it.  In the case of a bogus array access, that
code is useful, so the middle-end shouldn't be able to prove that it isn't, and
the it won't be removed.
For the other case (code removed where it should stay) there is a bug in the
compiler, but that's not what -fbounds-check is supposed to check ;-).


Regarding the initial question:
> Hi,
> can someone fortran aware please double-check that the tests
> 
>     * gfortran.dg/bounds_check_9.f90: New test.
>     * gfortran.dg/bounds_check_fail_2.f90: New test.
> 
> do not contain out of bounds access?

There should be none, as the -fbounds-check instrumentation is supposed to
catch out of bounds early enough, so that the code is valid from a middle-end
point of view.


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
       [not found] <bug-31119-4@http.gcc.gnu.org/bugzilla/>
  2012-10-20 14:38 ` hubicka at gcc dot gnu.org
  2012-10-20 14:59 ` Joost.VandeVondele at mat dot ethz.ch
@ 2012-10-20 15:43 ` dominiq at lps dot ens.fr
  2012-10-21 13:53 ` mikael at gcc dot gnu.org
  3 siblings, 0 replies; 13+ messages in thread
From: dominiq at lps dot ens.fr @ 2012-10-20 15:43 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119

--- Comment #9 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2012-10-20 15:43:13 UTC ---
> can someone fortran aware please double-check that the tests
>
>    * gfortran.dg/bounds_check_9.f90: New test.
>    * gfortran.dg/bounds_check_fail_2.f90: New test.
>
> do not contain out of bounds access? ...

AFAICT the only difference (ignoring spaces) between the two tests is the line

   call sub((/4/))

in the second test.
So there is no out of bounds access for the first test, but in the second one
the call to sub((/4/)) in which an array of length 1 is copied in an array of
length 2, gives an out of bounds access triggering the error:

Fortran runtime error: Array bound mismatch for dimension 1 of array 'ivec'
(1/2)

when compiled with -fbounds-check.

IMO these tests are a misuse of the elemental subroutine set_optional in the
subroutine sub. The test being valid only if sub is called without argument or
with an array of length 2.

>From the 2008 standard

12.8.3 Elemental subroutine actual arguments

An elemental subroutine has only scalar dummy arguments, but may have array
actual arguments. 

In a reference to an elemental subroutine, either all actual arguments shall be
scalar, or all actual arguments corresponding to INTENT (OUT) and INTENT
(INOUT) dummy arguments shall be arrays of the same shape and the remaining
actual arguments shall be conformable with them. 

In the case that the actual arguments corresponding to INTENT (OUT) and INTENT
(INOUT) dummy arguments are arrays, the values of the elements, if any, of the
results are the same as would be obtained if the subroutine had been applied
separately, in array element order, to corresponding elements of each array
actual argument.


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
       [not found] <bug-31119-4@http.gcc.gnu.org/bugzilla/>
  2012-10-20 14:38 ` hubicka at gcc dot gnu.org
@ 2012-10-20 14:59 ` Joost.VandeVondele at mat dot ethz.ch
  2012-10-20 15:43 ` dominiq at lps dot ens.fr
  2012-10-21 13:53 ` mikael at gcc dot gnu.org
  3 siblings, 0 replies; 13+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2012-10-20 14:59 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119

--- Comment #8 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> 2012-10-20 14:59:08 UTC ---
(In reply to comment #7)
> Hi,
> can someone fortran aware please double-check that the tests
> 
>     * gfortran.dg/bounds_check_9.f90: New test.
>     * gfortran.dg/bounds_check_fail_2.f90: New test.
> 
> do not contain out of bounds access?  I am working on path to bound number of
> loop iterations better based on array accesses and what I see is array A.9
> containing values {1,2} that is accessed in the loop header.
> We bound number of iterations of that loop to 1 (that is one loopback edge
> iteration to walk both parts of the array) and then the testcases start
> failing.
> 
> I do not understand the testcase.
> Perhaps the bounds-check instrumentation happens too late or we need to disable
> this logic with -fbounds-check?
> 
> Honza

According to me, the first testcase (bounds_check_9.f90) should contain no
out-of-bounds access (at least from the fortran point of view, and also
according to valgrind), while the second testcase (bounds_check_fail_2.f90)
does contain out-of-bounds access (by design). Of course, -fbounds-check is
designed to catch out-of-bounds at runtime (which the second testcase tests).
Of course, fortran programs with out-of-bounds access are not standard
conforming. 

Actually, the situation is a bit bizarre. There are no conforming programs for
which bounds-checking can trigger... all these bounds-checking statements can
be just optimized away :-). That's not quite what the users want... I run
-fbounds-check -O2 quite often. I don't think one should switch off
optimization in the presence of -fbounds-check. Maybe the docs should be
enhanced and mention that bounds checking is most effective at -O0 ?


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

* [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking
       [not found] <bug-31119-4@http.gcc.gnu.org/bugzilla/>
@ 2012-10-20 14:38 ` hubicka at gcc dot gnu.org
  2012-10-20 14:59 ` Joost.VandeVondele at mat dot ethz.ch
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu.org @ 2012-10-20 14:38 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

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

--- Comment #7 from Jan Hubicka <hubicka at gcc dot gnu.org> 2012-10-20 14:38:05 UTC ---
Hi,
can someone fortran aware please double-check that the tests

    * gfortran.dg/bounds_check_9.f90: New test.
    * gfortran.dg/bounds_check_fail_2.f90: New test.

do not contain out of bounds access?  I am working on path to bound number of
loop iterations better based on array accesses and what I see is array A.9
containing values {1,2} that is accessed in the loop header.
We bound number of iterations of that loop to 1 (that is one loopback edge
iteration to walk both parts of the array) and then the testcases start
failing.

I do not understand the testcase.
Perhaps the bounds-check instrumentation happens too late or we need to disable
this logic with -fbounds-check?

Honza


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

end of thread, other threads:[~2012-10-21 13:53 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-10  8:39 [Bug fortran/31119] New: Bogus "array abound mismatch" for -fbounds-check burnus at gcc dot gnu dot org
2007-03-10  8:47 ` [Bug fortran/31119] -fbounds-check: Check for presence of optional arguments before bound checking burnus at gcc dot gnu dot org
2007-03-10 12:43 ` fxcoudert at gcc dot gnu dot org
2007-03-18 17:49 ` fxcoudert at gcc dot gnu dot org
2007-03-19  9:05 ` fxcoudert at gcc dot gnu dot org
2007-05-09  7:09 ` fxcoudert at gcc dot gnu dot org
2007-07-04  6:35 ` jv244 at cam dot ac dot uk
2007-09-18 21:26 ` fxcoudert at gcc dot gnu dot org
2007-09-18 21:34 ` fxcoudert at gcc dot gnu dot org
     [not found] <bug-31119-4@http.gcc.gnu.org/bugzilla/>
2012-10-20 14:38 ` hubicka at gcc dot gnu.org
2012-10-20 14:59 ` Joost.VandeVondele at mat dot ethz.ch
2012-10-20 15:43 ` dominiq at lps dot ens.fr
2012-10-21 13:53 ` mikael 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).