public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/60370] New: TRANSPOSE on rhs of allocatable array assignment gives bounds error
@ 2014-02-28 20:05 townsend at astro dot wisc.edu
  2014-03-01 13:39 ` [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds janus at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: townsend at astro dot wisc.edu @ 2014-02-28 20:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60370
           Summary: TRANSPOSE on rhs of allocatable array assignment gives
                    bounds error
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: townsend at astro dot wisc.edu

The following code:

program foo

  real, allocatable :: a(:,:)
  real, allocatable :: b(:,:)

  allocate(a(10,5))

  a = 0.

  b = TRANSPOSE(a)

end program foo

...produces this error message at runtime, when compiled with -fcheck=all:

At line 10 of file foo.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'b' (1/5)

This is on OS X:

Using built-in specs.
COLLECT_GCC=/Applications/madsdk/bin/gfortran.exec
COLLECT_LTO_WRAPPER=/Applications/madsdk/libexec/gcc/x86_64-apple-darwin11.4.2/4.9.0/lto-wrapper
Target: x86_64-apple-darwin11.4.2
Configured with: ./configure CC='gcc -D_FORTIFY_SOURCE=0'
--build=x86_64-apple-darwin11.4.2 --prefix=/Applications/madsdk
--with-gmp=/Applications/madsdk --with-mpfr=/Applications/madsdk
--with-mpc=/Applications/madsdk --enable-languages=c,c++,fortran
--disable-multilib --disable-nls --disable-libsanitizer
Thread model: posix
gcc version 4.9.0 20140201 (experimental) (GCC)


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

* [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds
  2014-02-28 20:05 [Bug fortran/60370] New: TRANSPOSE on rhs of allocatable array assignment gives bounds error townsend at astro dot wisc.edu
@ 2014-03-01 13:39 ` janus at gcc dot gnu.org
  2014-03-01 16:00 ` anlauf at gmx dot de
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu.org @ 2014-03-01 13:39 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic, wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-03-01
                 CC|                            |janus at gcc dot gnu.org
            Summary|TRANSPOSE on rhs of         |TRANSPOSE on rhs of
                   |allocatable array           |allocatable array
                   |assignment gives bounds     |assignment gives error with
                   |error                       |-fcheck=bounds
     Ever confirmed|0                           |1

--- Comment #1 from janus at gcc dot gnu.org ---
With 4.7/4.8/trunk I get on x86_64-unknown-linux-gnu:

At line 10 of file c0.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'b' (0/5)


With 4.6 I get:

At line 10 of file c0.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'b'
(140735200374865/5)

(with large random numbers)


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

* [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds
  2014-02-28 20:05 [Bug fortran/60370] New: TRANSPOSE on rhs of allocatable array assignment gives bounds error townsend at astro dot wisc.edu
  2014-03-01 13:39 ` [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds janus at gcc dot gnu.org
@ 2014-03-01 16:00 ` anlauf at gmx dot de
  2014-03-01 18:16 ` mikael at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gmx dot de @ 2014-03-01 16:00 UTC (permalink / raw)
  To: gcc-bugs

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

Harald Anlauf <anlauf at gmx dot de> changed:

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

--- Comment #2 from Harald Anlauf <anlauf at gmx dot de> ---
PR52162 might be related.  Running the code under comment #0 under
valgrind, I get:

==31023== Memcheck, a memory error detector
==31023== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==31023== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==31023== Command: ./a.out
==31023== 
==31023== Conditional jump or move depends on uninitialised value(s)
==31023==    at 0x8049D22: MAIN__ (pr60370.f90:10)
==31023==    by 0x804A16E: main (pr60370.f90:12)
==31023== 
==31023== Conditional jump or move depends on uninitialised value(s)
==31023==    at 0x8049D59: MAIN__ (pr60370.f90:10)
==31023==    by 0x804A16E: main (pr60370.f90:12)
==31023== 
==31023== Conditional jump or move depends on uninitialised value(s)
==31023==    at 0x8049D90: MAIN__ (pr60370.f90:10)
==31023==    by 0x804A16E: main (pr60370.f90:12)
==31023== 
==31023== Conditional jump or move depends on uninitialised value(s)
==31023==    at 0x8049DC7: MAIN__ (pr60370.f90:10)
==31023==    by 0x804A16E: main (pr60370.f90:12)
==31023== 
==31023== Conditional jump or move depends on uninitialised value(s)
==31023==    at 0x8049E02: MAIN__ (pr60370.f90:10)
==31023==    by 0x804A16E: main (pr60370.f90:12)
==31023== 
At line 10 of file pr60370.f90
Fortran runtime error: ==31023== Conditional jump or move depends on
uninitialised value(s)

etc.


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

* [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds
  2014-02-28 20:05 [Bug fortran/60370] New: TRANSPOSE on rhs of allocatable array assignment gives bounds error townsend at astro dot wisc.edu
  2014-03-01 13:39 ` [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds janus at gcc dot gnu.org
  2014-03-01 16:00 ` anlauf at gmx dot de
@ 2014-03-01 18:16 ` mikael at gcc dot gnu.org
  2014-03-01 19:23 ` mikael at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mikael at gcc dot gnu.org @ 2014-03-01 18:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Mikael Morin <mikael at gcc dot gnu.org> ---
The array reallocation code must come before the bound checking code, but after
the loop bounds evaluation code.  However, at the time of reallocation
generation the two last codes have already been put in one single block.

The following doesn't work because the array reallocation code uses the loop
bounds so reallocation can't come before loop bounds evaluation.


diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 1e156ff..00b1459 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -8044,7 +8044,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr *
expr2, bool init_flag,
          ompws_flags &= ~OMPWS_SCALARIZER_WS;
          tmp = gfc_alloc_allocatable_for_assignment (&loop, expr1, expr2);
          if (tmp != NULL_TREE)
-           gfc_add_expr_to_block (&loop.code[expr1->rank - 1], tmp);
+           gfc_prepend_expr_to_block (&loop.pre, tmp);
        }

       /* Generate the copying loops.  */


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

* [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds
  2014-02-28 20:05 [Bug fortran/60370] New: TRANSPOSE on rhs of allocatable array assignment gives bounds error townsend at astro dot wisc.edu
                   ` (2 preceding siblings ...)
  2014-03-01 18:16 ` mikael at gcc dot gnu.org
@ 2014-03-01 19:23 ` mikael at gcc dot gnu.org
  2014-03-03 12:47 ` janus at gcc dot gnu.org
  2014-03-03 21:40 ` mikael at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mikael at gcc dot gnu.org @ 2014-03-01 19:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Mikael Morin <mikael at gcc dot gnu.org> ---
Created attachment 32239
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32239&action=edit
Tentative patch moving realloc code before bound checking

This patch doesn't work, so it may not be a code ordering issue after all.


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

* [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds
  2014-02-28 20:05 [Bug fortran/60370] New: TRANSPOSE on rhs of allocatable array assignment gives bounds error townsend at astro dot wisc.edu
                   ` (3 preceding siblings ...)
  2014-03-01 19:23 ` mikael at gcc dot gnu.org
@ 2014-03-03 12:47 ` janus at gcc dot gnu.org
  2014-03-03 21:40 ` mikael at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu.org @ 2014-03-03 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from janus at gcc dot gnu.org ---
(In reply to Mikael Morin from comment #4)
> This patch doesn't work, so it may not be a code ordering issue after all.

I think it *is* an ordering issue after all, and indeed your patch seems to fix
that in the sense that it makes sure that the bounds of 'b' are set before the
bounds-checking code is run.

However, it also seems to introduce another ordering issue: In particular the
bounds of 'b' are now set as

        b.dim[1].lbound = 1;
        b.dim[1].ubound = (D.2352 - D.2351) + 1;

before those temps are actually set via

      D.2351 = a.dim[0].lbound;
      D.2352 = a.dim[0].ubound;


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

* [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds
  2014-02-28 20:05 [Bug fortran/60370] New: TRANSPOSE on rhs of allocatable array assignment gives bounds error townsend at astro dot wisc.edu
                   ` (4 preceding siblings ...)
  2014-03-03 12:47 ` janus at gcc dot gnu.org
@ 2014-03-03 21:40 ` mikael at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mikael at gcc dot gnu.org @ 2014-03-03 21:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to janus from comment #5)
> However, it also seems to introduce another ordering issue: In particular
> the bounds of 'b' are now set as
> 
>         b.dim[1].lbound = 1;
>         b.dim[1].ubound = (D.2352 - D.2351) + 1;
> 
> before those temps are actually set via
> 
>       D.2351 = a.dim[0].lbound;
>       D.2352 = a.dim[0].ubound;

Hmm, no those are correctly ordered, but I see what you mean; and it's actually
diagnosed by the compiler when warnings and optimizations are enabled:
Namely this happens:

      D.2339 = b.dim[1].lbound;
      D.2340 = b.dim[1].ubound;

before b has been initialized.

So the reallocation code has to also happen before b's bounds are evaluated.
Even more tricky... :-(


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

end of thread, other threads:[~2014-03-03 21:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-28 20:05 [Bug fortran/60370] New: TRANSPOSE on rhs of allocatable array assignment gives bounds error townsend at astro dot wisc.edu
2014-03-01 13:39 ` [Bug fortran/60370] TRANSPOSE on rhs of allocatable array assignment gives error with -fcheck=bounds janus at gcc dot gnu.org
2014-03-01 16:00 ` anlauf at gmx dot de
2014-03-01 18:16 ` mikael at gcc dot gnu.org
2014-03-01 19:23 ` mikael at gcc dot gnu.org
2014-03-03 12:47 ` janus at gcc dot gnu.org
2014-03-03 21:40 ` 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).