public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/39894]  New: memory corruption with array section assignment of arrays with different shape
@ 2009-04-25 12:30 deji_aking at yahoo dot ca
  2009-04-25 12:33 ` [Bug fortran/39894] " deji_aking at yahoo dot ca
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: deji_aking at yahoo dot ca @ 2009-04-25 12:30 UTC (permalink / raw)
  To: gcc-bugs

The attached program produce memory corruption at runtime because of an
expression between 2 arrays of different shape using array section. I'm not
sure if it is standard conforming or not, so I'm reporting it as a bug; the
program executes OK with pgf90 and ifort (on Linux) and xlf90 (on AIX).


-- 
           Summary: memory corruption with array section assignment of
                    arrays with different shape
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: deji_aking at yahoo dot ca


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


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

* [Bug fortran/39894] memory corruption with array section assignment of arrays with different shape
  2009-04-25 12:30 [Bug fortran/39894] New: memory corruption with array section assignment of arrays with different shape deji_aking at yahoo dot ca
@ 2009-04-25 12:33 ` deji_aking at yahoo dot ca
  2009-04-25 13:38 ` dominiq at lps dot ens dot fr
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: deji_aking at yahoo dot ca @ 2009-04-25 12:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from deji_aking at yahoo dot ca  2009-04-25 12:32 -------
Created an attachment (id=17692)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17692&action=view)
Test program

gfortran work fine if I change the line;
'listgeonm(1,:) = geonm(:,1)'

to
'listgeonm(1,:) = geonm(1:p_bgeo_top,1)'


-- 


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


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

* [Bug fortran/39894] memory corruption with array section assignment of arrays with different shape
  2009-04-25 12:30 [Bug fortran/39894] New: memory corruption with array section assignment of arrays with different shape deji_aking at yahoo dot ca
  2009-04-25 12:33 ` [Bug fortran/39894] " deji_aking at yahoo dot ca
@ 2009-04-25 13:38 ` dominiq at lps dot ens dot fr
  2009-04-25 15:32 ` deji_aking at yahoo dot ca
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: dominiq at lps dot ens dot fr @ 2009-04-25 13:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dominiq at lps dot ens dot fr  2009-04-25 13:38 -------
If you compile the code in comment #1 with '-fbounds-check', you get:

At line 32 of file pr39894.f90
Fortran runtime error: Array bound mismatch, size mismatch for dimension 2 of
array 'listgeonm' (18/999)

(off by one, see pr39872). So the code is invalid and have to be fixed as
noticed in comment #1. Note that I don't see the "memory corruption" on
i686-apple-darwin9, but this is pure luck.


-- 


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


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

* [Bug fortran/39894] memory corruption with array section assignment of arrays with different shape
  2009-04-25 12:30 [Bug fortran/39894] New: memory corruption with array section assignment of arrays with different shape deji_aking at yahoo dot ca
  2009-04-25 12:33 ` [Bug fortran/39894] " deji_aking at yahoo dot ca
  2009-04-25 13:38 ` dominiq at lps dot ens dot fr
@ 2009-04-25 15:32 ` deji_aking at yahoo dot ca
  2009-04-25 16:30 ` dominiq at lps dot ens dot fr
  2009-04-25 16:37 ` kargl at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: deji_aking at yahoo dot ca @ 2009-04-25 15:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from deji_aking at yahoo dot ca  2009-04-25 15:32 -------
(In reply to comment #2)
> If you compile the code in comment #1 with '-fbounds-check', you get:
> 
> At line 32 of file pr39894.f90
> Fortran runtime error: Array bound mismatch, size mismatch for dimension 2 of
> array 'listgeonm' (18/999)
>
Thanks, I've seen that too. But bounds checking on the other compilers I have
access to doesn't show any problem. I was hoping gfortran can be smarter in
this situations like this, and use just the first portion of the array on the
right side that fits the shape of the array section on the left of the
assignment statement.


-- 


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


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

* [Bug fortran/39894] memory corruption with array section assignment of arrays with different shape
  2009-04-25 12:30 [Bug fortran/39894] New: memory corruption with array section assignment of arrays with different shape deji_aking at yahoo dot ca
                   ` (2 preceding siblings ...)
  2009-04-25 15:32 ` deji_aking at yahoo dot ca
@ 2009-04-25 16:30 ` dominiq at lps dot ens dot fr
  2009-04-25 16:37 ` kargl at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: dominiq at lps dot ens dot fr @ 2009-04-25 16:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dominiq at lps dot ens dot fr  2009-04-25 16:30 -------
> But bounds checking on the other compilers I have access to doesn't show any problem

Are you sure about that? If you use bound-checking on any compiler supporting
it, you should get an error (at least a warning).

> I was hoping gfortran can be smarter in
> this situations like this, and use just the first portion of the array on the
> right side that fits the shape of the array section on the left of the
> assignment statement.

Again, I don't think any compiler is smart with this respect. If one is, it
should emit a warning about the use of the extension. Now as I said in comment
#2, on i686-apple-darwin9 the invalid and valid codes give the same output, but
it is not because gfortran is smarter on this platform than on yours, but only
because the memory layouts are different and that the extra data are written on
i686-apple-darwin9 in a place that does not cause a problem.

Final note, you should close this pr as invalid, TIA.


-- 


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


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

* [Bug fortran/39894] memory corruption with array section assignment of arrays with different shape
  2009-04-25 12:30 [Bug fortran/39894] New: memory corruption with array section assignment of arrays with different shape deji_aking at yahoo dot ca
                   ` (3 preceding siblings ...)
  2009-04-25 16:30 ` dominiq at lps dot ens dot fr
@ 2009-04-25 16:37 ` kargl at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu dot org @ 2009-04-25 16:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from kargl at gcc dot gnu dot org  2009-04-25 16:37 -------
The Fortran 95 standard states:

  7.5.1.4    Intrinsic assignment conformance rules

  For an intrinsic assignment statement, variable and expr shall conform in
  shape, and if expr is an array, variable shall also be an array. The types
  of variable and expr shall conform with the rules of Table 7.9.

This is not a constraint, so a compiler is not required to generate a
warning or an error.  It can do anything, including corrupt memory.
As Dominique suggested, one should use the -fbounds-check option while
developing code.


-- 

kargl at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2009-04-25 16:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-25 12:30 [Bug fortran/39894] New: memory corruption with array section assignment of arrays with different shape deji_aking at yahoo dot ca
2009-04-25 12:33 ` [Bug fortran/39894] " deji_aking at yahoo dot ca
2009-04-25 13:38 ` dominiq at lps dot ens dot fr
2009-04-25 15:32 ` deji_aking at yahoo dot ca
2009-04-25 16:30 ` dominiq at lps dot ens dot fr
2009-04-25 16:37 ` kargl 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).