public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized
@ 2008-11-06 14:25 pault at gcc dot gnu dot org
2008-11-06 14:26 ` [Bug fortran/38033] " pault at gcc dot gnu dot org
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-06 14:25 UTC (permalink / raw)
To: gcc-bugs
Following thread from Thomas Breuel,
http://gcc.gnu.org/ml/fortran/2008-11/msg00044.html
program test
integer, parameter :: n = 100
real, pointer :: a(:),temp(:) ! pointer or allocatable have the same effect
allocate(a(n), temp(n))
temp(1:size(a)) = a
end program
produces
test ()
{
struct array01_real(kind=4) a;
struct array01_real(kind=4) temp;
static integer(kind=4) options.0[8] = {68, 255, 0, 0, 0, 1, 0, 1};
a.data = 0B;
temp.data = 0B;
_gfortran_set_options (8, (void *) &options.0);
{
void * D.646;
a.dtype = 281;
a.dim[0].lbound = 1;
a.dim[0].ubound = 100;
a.dim[0].stride = 1;
D.646 = __builtin_malloc (400);
if (D.646 == 0B)
{
_gfortran_os_error (&"Out of memory"[1]{lb: 1 sz: 1});
}
a.data = D.646;
a.offset = -1;
}
{
void * D.647;
temp.dtype = 281;
temp.dim[0].lbound = 1;
temp.dim[0].ubound = 100;
temp.dim[0].stride = 1;
D.647 = __builtin_malloc (400);
if (D.647 == 0B)
{
_gfortran_os_error (&"Out of memory"[1]{lb: 1 sz: 1});
}
temp.data = D.647;
temp.offset = -1;
}
{
integer(kind=4) D.664;
void * D.662;
void * D.661;
integer(kind=4) D.660;
integer(kind=4) D.659;
logical(kind=4) D.658;
struct array01_real(kind=4) atmp.1;
struct array01_real(kind=4) * D.656;
integer(kind=4) D.655;
struct array01_real(kind=4) * D.654;
integer(kind=4) D.653;
real(kind=4)[0:] * D.652;
integer(kind=4) D.651;
integer(kind=4) D.650;
integer(kind=4) D.649;
real(kind=4)[0:] * D.648;
D.648 = (real(kind=4)[0:] *) a.data;
D.649 = a.offset;
D.650 = a.dim[0].lbound;
D.651 = a.dim[0].ubound;
D.652 = (real(kind=4)[0:] *) temp.data;
D.653 = temp.offset;
D.654 = &a;
D.655 = _gfortran_size0 (D.654);
D.656 = &a;
atmp.1.dtype = 281;
atmp.1.dim[0].stride = 1;
atmp.1.dim[0].lbound = 0;
atmp.1.dim[0].ubound = _gfortran_size0 (D.656) + -1;
D.658 = _gfortran_size0 (D.656) <= 0;
D.659 = _gfortran_size0 (D.656);
D.660 = D.658 ? 0 : D.659 * 4;
if (D.660 < 0)
{
_gfortran_runtime_error (&"Attempt to allocate a negative amount of
memo
ry."[1]{lb: 1 sz: 1});
}
D.661 = __builtin_malloc (MAX_EXPR <D.660, 1>);
if (D.661 == 0B)
{
_gfortran_os_error (&"Memory allocation failed"[1]{lb: 1 sz: 1});
}
D.662 = D.661;
atmp.1.data = D.662;
atmp.1.offset = 0;
D.664 = NON_LVALUE_EXPR <D.650>;
{
integer(kind=4) D.667;
integer(kind=4) D.666;
integer(kind=4) S.2;
D.666 = a.dim[0].stride;
D.667 = temp.dim[0].stride;
S.2 = 0;
while (1)
{
if (_gfortran_size0 (D.656) + -1 < S.2) goto L.1;
(*(real(kind=4)[0:] *) atmp.1.data)[S.2] = (*D.648)[(S.2 + D.664) *
D.
666 + D.649];
S.2 = S.2 + 1;
}
L.1:;
S.2 = 0;
while (1)
{
if (_gfortran_size0 (D.656) + -1 < S.2) goto L.2;
(*D.652)[(S.2 + 1) * D.667 + D.653] = (*(real(kind=4)[0:] *)
atmp.1.da
ta)[S.2];
S.2 = S.2 + 1;
}
L.2:;
}
{
void * D.663;
D.663 = atmp.1.data;
if (D.663 != 0B)
{
__builtin_free (D.663);
}
}
}
}
Calls to gfortran_size0 are appearing withing the scalarized loop because the
expression for the upper bound of atmp is not stabilized.
--
Summary: Bounds of a pointer/allocatable array not stabilized
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Keywords: wrong-code, missed-optimization
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pault at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
@ 2008-11-06 14:26 ` pault at gcc dot gnu dot org
2008-11-06 21:10 ` pault at gcc dot gnu dot org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-06 14:26 UTC (permalink / raw)
To: gcc-bugs
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |pault at gcc dot gnu dot org
|dot org |
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-11-06 14:24:59
date| |
Summary|Bounds of a |Bounds of a
|pointer/allocatable array |pointer/allocatable array
|not stabilized |not stabilized
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
2008-11-06 14:26 ` [Bug fortran/38033] " pault at gcc dot gnu dot org
@ 2008-11-06 21:10 ` pault at gcc dot gnu dot org
2008-11-07 14:01 ` pault at gcc dot gnu dot org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-06 21:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pault at gcc dot gnu dot org 2008-11-06 21:09 -------
(In reply to comment #0)
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c (revision 141655)
+++ gcc/fortran/trans-array.c (working copy)
@@ -645,13 +645,16 @@
{
n = loop->order[dim];
if (n < loop->temp_dim)
- gcc_assert (integer_zerop (loop->from[n]));
+ gcc_assert (integer_zerop (loop->from[n]));
else
{
/* Callee allocated arrays may not have a known bound yet. */
if (loop->to[n])
- loop->to[n] = fold_build2 (MINUS_EXPR, gfc_array_index_type,
- loop->to[n], loop->from[n]);
+ {
+ tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type,
+ loop->to[n], loop->from[n]);
+ loop->to[n] = gfc_evaluate_now (tmp, pre);
+ }
loop->from[n] = gfc_index_zero_node;
}
Removes the _gfortran_size0 calls from the loop but I have not yet located the
doubling up of calls here:
D.1551 = temp.offset;
D.1552 = &a;
D.1553 = (integer(kind=8)) (integer(kind=4)) _gfortran_size0 (D.1552);
D.1554 = &a;
D.1555 = (integer(kind=8)) (integer(kind=4)) _gfortran_size0 (D.1554) + -1;
atmp.1.dtype = 281;
atmp.1.dim[0].stride = 1;
atmp.1.dim[0].lbound = 0;
atmp.1.dim[0].ubound = D.1555;
D.1557 = D.1555 + 1 <= 0;
D.1558 = D.1555 + 1;
D.1559 = D.1557 ? 0 : D.1558 * 4;
if (D.1559 < 0)
{
_gfortran_runtime_error (&"Attempt to allocate a negative amount of
memory."[1]{lb: 1 sz: 1});
}
D.1560 = __builtin_malloc (MAX_EXPR <D.1559, 1>);
if (D.1560 == 0B)
{
_gfortran_os_error (&"Memory allocation failed"[1]{lb: 1 sz: 1});
}
D.1561 = D.1560;
atmp.1.data = D.1561;
atmp.1.offset = 0;
D.1563 = NON_LVALUE_EXPR <D.1548>;
{
integer(kind=8) D.1566;
integer(kind=8) D.1565;
integer(kind=8) S.2;
D.1565 = a.dim[0].stride;
D.1566 = temp.dim[0].stride;
S.2 = 0;
while (1)
{
if (S.2 > D.1555) goto L.1;
(*(real(kind=4)[0:] *) atmp.1.data)[S.2] = (*D.1546)[(S.2 + D.1563) *
D.1565 + D.1547];
S.2 = S.2 + 1;
}
L.1:;
S.2 = 0;
while (1)
{
if (S.2 > D.1555) goto L.2;
(*D.1550)[(S.2 + 1) * D.1566 + D.1551] = (*(real(kind=4)[0:] *)
atmp.1.data)[S.2];
S.2 = S.2 + 1;
}
L.2:;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
2008-11-06 14:26 ` [Bug fortran/38033] " pault at gcc dot gnu dot org
2008-11-06 21:10 ` pault at gcc dot gnu dot org
@ 2008-11-07 14:01 ` pault at gcc dot gnu dot org
2008-11-13 15:03 ` pault at gcc dot gnu dot org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-07 14:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pault at gcc dot gnu dot org 2008-11-07 13:59 -------
(In reply to comment #1)
> (In reply to comment #0)
> Removes the _gfortran_size0 calls from the loop but I have not yet located the
> doubling up of calls here:
>
> D.1551 = temp.offset;
> D.1552 = &a;
> D.1553 = (integer(kind=8)) (integer(kind=4)) _gfortran_size0 (D.1552);
> D.1554 = &a;
> D.1555 = (integer(kind=8)) (integer(kind=4)) _gfortran_size0 (D.1554) + -1
The second call and stabilization of &a comes from the patch in #1. The first
is from gfc_conv_section_startstride, after:
/* Similarly calculate the end. Although this is not used in the
scalarizer, it is needed when checking bounds and where the end
is an expression with side-effects. */
Thus, rather than using loop->to[n], we will probably have to detect
GFC_SS_SECTION && ss->data.info.end[n] and the use ss->data.info.start[n] and
ss->data.info.end[n].
I'm working on it!
Paul
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
` (2 preceding siblings ...)
2008-11-07 14:01 ` pault at gcc dot gnu dot org
@ 2008-11-13 15:03 ` pault at gcc dot gnu dot org
2008-11-13 19:07 ` mikael at gcc dot gnu dot org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-13 15:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pault at gcc dot gnu dot org 2008-11-13 15:01 -------
Created an attachment (id=16662)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16662&action=view)
Patch for PR
This is not regtested yet but it fixes the testcase completely. Watch this
space!
Paul
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
` (3 preceding siblings ...)
2008-11-13 15:03 ` pault at gcc dot gnu dot org
@ 2008-11-13 19:07 ` mikael at gcc dot gnu dot org
2008-11-14 11:17 ` pault at gcc dot gnu dot org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mikael at gcc dot gnu dot org @ 2008-11-13 19:07 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from mikael at gcc dot gnu dot org 2008-11-13 19:05 -------
Maybe we can drop gfc_conv_section_upper_bound completely.
It looks redundant with how info->end[n] is calculated in
gfc_conv_section_startstride.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
` (4 preceding siblings ...)
2008-11-13 19:07 ` mikael at gcc dot gnu dot org
@ 2008-11-14 11:17 ` pault at gcc dot gnu dot org
2008-11-14 12:55 ` mikael at gcc dot gnu dot org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-14 11:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pault at gcc dot gnu dot org 2008-11-14 11:16 -------
Mikael,
(In reply to comment #4)
> Maybe we can drop gfc_conv_section_upper_bound completely.
> It looks redundant with how info->end[n] is calculated in
> gfc_conv_section_startstride.
>
I tried that and generated a load of regressions. I didn't analyse this but
stuck with the patch as is. I maybe will think about it some more but I am
inclined to put a TODO in there.
Thanks
Paul
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
` (5 preceding siblings ...)
2008-11-14 11:17 ` pault at gcc dot gnu dot org
@ 2008-11-14 12:55 ` mikael at gcc dot gnu dot org
2008-11-14 18:05 ` pault at gcc dot gnu dot org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mikael at gcc dot gnu dot org @ 2008-11-14 12:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from mikael at gcc dot gnu dot org 2008-11-14 12:54 -------
(In reply to comment #5)
> I tried that and generated a load of regressions.
Fine. Let's keep it as is then.
>
> Thanks
Thanks to you.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
` (6 preceding siblings ...)
2008-11-14 12:55 ` mikael at gcc dot gnu dot org
@ 2008-11-14 18:05 ` pault at gcc dot gnu dot org
2008-11-14 18:41 ` pault at gcc dot gnu dot org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-14 18:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from pault at gcc dot gnu dot org 2008-11-14 18:04 -------
Subject: Bug 38033
Author: pault
Date: Fri Nov 14 18:03:05 2008
New Revision: 141861
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141861
Log:
2008-10-14 Paul Thomas <pault@gcc.gnu.org>
PR fortran/38033
* trans-array.c (gfc_trans_create_temp_array): Stabilize the
'to' expression.
(gfc_conv_loop_setup): Use the end expression for the loop 'to'
if it is available.
2008-10-14 Paul Thomas <pault@gcc.gnu.org>
PR fortran/38033
* gfortran.dg/array_section_2.f90: New test.
Added:
trunk/gcc/testsuite/gfortran.dg/array_section_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=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
` (7 preceding siblings ...)
2008-11-14 18:05 ` pault at gcc dot gnu dot org
@ 2008-11-14 18:41 ` pault at gcc dot gnu dot org
2008-11-24 21:39 ` pault at gcc dot gnu dot org
2008-11-24 21:39 ` pault at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-14 18:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from pault at gcc dot gnu dot org 2008-11-14 18:39 -------
Fixed on trunk
Paul
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
` (9 preceding siblings ...)
2008-11-24 21:39 ` pault at gcc dot gnu dot org
@ 2008-11-24 21:39 ` pault at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-24 21:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from pault at gcc dot gnu dot org 2008-11-24 21:37 -------
Subject: Bug 38033
Author: pault
Date: Mon Nov 24 21:36:05 2008
New Revision: 142174
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142174
Log:
2008-11-24 Paul Thomas <pault@gcc.gnu.org>
PR fortran/38033
* trans-array.c (gfc_trans_create_temp_array): Stabilize the
'to' expression.
(gfc_conv_loop_setup): Use the end expression for the loop 'to'
if it is available.
2008-11-24 Paul Thomas <pault@gcc.gnu.org>
PR fortran/38033
* gfortran.dg/array_section_2.f90: New test.
Added:
branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/array_section_2.f90
Modified:
branches/gcc-4_3-branch/gcc/fortran/ChangeLog
branches/gcc-4_3-branch/gcc/fortran/trans-array.c
branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/38033] Bounds of a pointer/allocatable array not stabilized
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
` (8 preceding siblings ...)
2008-11-14 18:41 ` pault at gcc dot gnu dot org
@ 2008-11-24 21:39 ` pault at gcc dot gnu dot org
2008-11-24 21:39 ` pault at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-24 21:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from pault at gcc dot gnu dot org 2008-11-24 21:38 -------
Fixed on trunk and 4.3.
Thanks for the report.
Paul
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38033
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2008-11-24 21:39 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-06 14:25 [Bug fortran/38033] New: Bounds of a pointer/allocatable array not stabilized pault at gcc dot gnu dot org
2008-11-06 14:26 ` [Bug fortran/38033] " pault at gcc dot gnu dot org
2008-11-06 21:10 ` pault at gcc dot gnu dot org
2008-11-07 14:01 ` pault at gcc dot gnu dot org
2008-11-13 15:03 ` pault at gcc dot gnu dot org
2008-11-13 19:07 ` mikael at gcc dot gnu dot org
2008-11-14 11:17 ` pault at gcc dot gnu dot org
2008-11-14 12:55 ` mikael at gcc dot gnu dot org
2008-11-14 18:05 ` pault at gcc dot gnu dot org
2008-11-14 18:41 ` pault at gcc dot gnu dot org
2008-11-24 21:39 ` pault at gcc dot gnu dot org
2008-11-24 21:39 ` pault 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).