public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/28849]  New: Missed array shape violation with RESHAPE despite -fbounds-check
@ 2006-08-25 20:39 anlauf at gmx dot de
  2006-08-25 20:41 ` [Bug fortran/28849] " anlauf at gmx dot de
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: anlauf at gmx dot de @ 2006-08-25 20:39 UTC (permalink / raw)
  To: gcc-bugs

The assignment of a RESHAPE()d array does not trigger
a run-time error with bounds-checking turned on.

% gfortran -O0 -g -fbounds-check gfcbug39_bounds_check.f90 && ./a.out
 Assignments with correct shapes after RESHAPE...
 a(:,1) =   1.000000    
 b(:,1) =   1.000000       2.000000    
 ...and with wrong shape (should fail with bounds checking on)
 a(:,1) =   1.000000    
 b(:,1) =   1.000000       2.000000    
 Must have missed an array bound violation after RESHAPE...


See the attached sample program for details.

Cheers,
-ha


-- 
           Summary: Missed array shape violation with RESHAPE despite -
                    fbounds-check
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: anlauf at gmx dot de
  GCC host triplet: i686-pc-linux-gnu


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
@ 2006-08-25 20:41 ` anlauf at gmx dot de
  2006-10-02 11:54 ` fxcoudert at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gmx dot de @ 2006-08-25 20:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from anlauf at gmx dot de  2006-08-25 20:40 -------
Created an attachment (id=12140)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12140&action=view)
Sample RESHAPE with missed array bounds violation


-- 


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
  2006-08-25 20:41 ` [Bug fortran/28849] " anlauf at gmx dot de
@ 2006-10-02 11:54 ` fxcoudert at gcc dot gnu dot org
  2006-10-11 13:17 ` fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2006-10-02 11:54 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-10-02 11:54:18
               date|                            |


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
  2006-08-25 20:41 ` [Bug fortran/28849] " anlauf at gmx dot de
  2006-10-02 11:54 ` fxcoudert at gcc dot gnu dot org
@ 2006-10-11 13:17 ` fxcoudert at gcc dot gnu dot org
  2006-10-11 13:58 ` anlauf at gmx dot de
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2006-10-11 13:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from fxcoudert at gcc dot gnu dot org  2006-10-11 13:17 -------
I'll note that the Portland, Intel and g95 compilers do not see this issue
either. SunStudio does, at runtime.


-- 


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
                   ` (2 preceding siblings ...)
  2006-10-11 13:17 ` fxcoudert at gcc dot gnu dot org
@ 2006-10-11 13:58 ` anlauf at gmx dot de
  2006-11-08 19:44 ` burnus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gmx dot de @ 2006-10-11 13:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from anlauf at gmx dot de  2006-10-11 13:58 -------
(In reply to comment #2)
> I'll note that the Portland, Intel and g95 compilers do not see this issue
> either.

Well, I get a bounds violation with current versions of g95 (0.91)
on both Linux and Cygwin:

% g95 -g -fbounds-check -ftrace=full gfcbug39_bounds_check.f90 && ./a.out 
 Assignments with correct shapes after RESHAPE...
 a(:,1) = 1.
 b(:,1) = 1. 2.
 ...and with wrong shape (should fail with bounds checking on)
At line 17 of file gfcbug39_bounds_check.f90
Traceback: not available, compile with -ftrace=frame or -ftrace=full
Fortran runtime error: Array element out of bounds: 2 in (1:1), dim=2


With xlf 9.1 on AIX:

% xlf95 -qsuffix=f=f90 -C -g gfcbug39_bounds_check.f90
% dbx a.out 
Type 'help' for help.
reading symbolic information ...
(dbx) run
 Assignments with correct shapes after RESHAPE...
 a(:,1) = 1.000000000
 b(:,1) = 1.000000000 2.000000000
 ...and with wrong shape (should fail with bounds checking on)

Trace/BPT trap in gfc_bounds_check at line 17
   17     a(:,:) = reshape (v(:), (/ 2, 1 /) )
(dbx) 


With Intel I had a discussion about this, as ifc7 reports
a shape violation, and ifort8 and ifort9 do not.  Intel
does not consider this a regression, and think that
reimplementing the old behavior in 8.x and 9.x would be
an "enhancement".


-- 


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
                   ` (3 preceding siblings ...)
  2006-10-11 13:58 ` anlauf at gmx dot de
@ 2006-11-08 19:44 ` burnus at gcc dot gnu dot org
  2006-11-08 20:08 ` burnus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2006-11-08 19:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2006-11-08 19:44 -------
See also PR 29572 (matmul(a,b) and matmul(a,transpose(b))).

sunf95 and NAG f95 catch this PR and also PR29572 and also pack().
g95 catches this PR and matmul(a,b), but not matmul(a,transpose(b))).
ifort 9.1 (and 10.0) don't implement these kinds of checks.

For pack, see:
http://gcc.gnu.org/ml/fortran/2006-11/msg00243.html

I think there are two possible solutions:
Specific checks for known functions (reshape, matmul etc.), which is seemingly
what g95 does.
Or a solution for general functions, which seems to be what NAG f95/sunf95 do.

For the latter, a test case is (imagine also pointer, allocatable, in different
modules etc.):
program check
  implicit none
  real, dimension(2) :: r
  r = foo(5)
contains
  function foo(n)
    integer :: n
    real, dimension(n) :: foo
    foo = 42.0
  end function foo
end program check


-- 


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
                   ` (4 preceding siblings ...)
  2006-11-08 19:44 ` burnus at gcc dot gnu dot org
@ 2006-11-08 20:08 ` burnus at gcc dot gnu dot org
  2006-11-08 20:48 ` burnus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2006-11-08 20:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from burnus at gcc dot gnu dot org  2006-11-08 20:08 -------
Postscriptum:
sunf95 already finds the problem in the program "check" at compile time.

For non-intrinsics (non libgfortran) routines, one way to do it is too do it in
the function called. (Internally called as  foo (&parm.5, D.1358);)
That way one could even detect the problem if one moves the "foo" function out
of the "program" and uses an "interface". In this case neither sunf95 nor
NAGf95 find the error.

But what would be the best way for the library? Adding a check version to it?
Adding a if(flag) to it (may slow down)? Both NAG f95 and sunf95 seem to expand
those intrinsics (pack, reshape, transpose) rather than using a library call
and add then the check directly in the tree.


-- 


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
                   ` (5 preceding siblings ...)
  2006-11-08 20:08 ` burnus at gcc dot gnu dot org
@ 2006-11-08 20:48 ` burnus at gcc dot gnu dot org
  2007-01-02 14:30 ` fxcoudert at gcc dot gnu dot org
  2009-04-04 18:30 ` dfranke at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2006-11-08 20:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from burnus at gcc dot gnu dot org  2006-11-08 20:48 -------
> In this case neither sunf95 nor NAGf95 find the error.
This is actually wrong; both find it.

In my example the original tree looks like (shortend): foo (__result, n)
    ubound.0 = (int8) *n;
      S.4 = 1;
      while (1)
        {
          if (S.4 > ubound.0) goto L.1; else (void) 0;
          (*__result.0)[NON_LVALUE_EXPR <S.4> * D.1347 + D.1345] = 4.2e+1;
          S.4 = S.4 + 1;
        }
      L.1:;
Thus one should check
   "ubound.0*stride.1+offset.2 > __result->dim[0].ubound"
and
   "1 *stride.1+offset.2 < __result->dim[0].lbound"


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu dot
                   |                            |org


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
                   ` (6 preceding siblings ...)
  2006-11-08 20:48 ` burnus at gcc dot gnu dot org
@ 2007-01-02 14:30 ` fxcoudert at gcc dot gnu dot org
  2009-04-04 18:30 ` dfranke at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-01-02 14:30 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|fxcoudert at gcc dot gnu dot|unassigned at gcc dot gnu
                   |org                         |dot org
             Status|ASSIGNED                    |NEW


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


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

* [Bug fortran/28849] Missed array shape violation with RESHAPE despite -fbounds-check
  2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
                   ` (7 preceding siblings ...)
  2007-01-02 14:30 ` fxcoudert at gcc dot gnu dot org
@ 2009-04-04 18:30 ` dfranke at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2009-04-04 18:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from dfranke at gcc dot gnu dot org  2009-04-04 18:29 -------
$ gfortran-4.3.3 -Wall -g -W -fbounds-check pr28849.f90 && ./a.out
 Assignments with correct shapes after RESHAPE...
 a(:,1) =   1.0000000
 b(:,1) =   1.0000000       2.0000000
 ...and with wrong shape (should fail with bounds checking on)
Fortran runtime error: Incorrect extent in return value of RESHAPE intrinsic in
dimension 1: is 1, should be 2

Same for 4.4.0 and 4.5.0.
Closing. Please reopen if anything else is left.


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dfranke at gcc dot gnu dot
                   |                            |org
             Status|NEW                         |RESOLVED
      Known to work|                            |4.3.3
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2009-04-04 18:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-25 20:39 [Bug fortran/28849] New: Missed array shape violation with RESHAPE despite -fbounds-check anlauf at gmx dot de
2006-08-25 20:41 ` [Bug fortran/28849] " anlauf at gmx dot de
2006-10-02 11:54 ` fxcoudert at gcc dot gnu dot org
2006-10-11 13:17 ` fxcoudert at gcc dot gnu dot org
2006-10-11 13:58 ` anlauf at gmx dot de
2006-11-08 19:44 ` burnus at gcc dot gnu dot org
2006-11-08 20:08 ` burnus at gcc dot gnu dot org
2006-11-08 20:48 ` burnus at gcc dot gnu dot org
2007-01-02 14:30 ` fxcoudert at gcc dot gnu dot org
2009-04-04 18:30 ` dfranke at gcc dot gnu dot 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).