public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly
@ 2011-08-29 13:46 arjen.markus895 at gmail dot com
2011-08-29 14:01 ` [Bug fortran/50225] " dominiq at lps dot ens.fr
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: arjen.markus895 at gmail dot com @ 2011-08-29 13:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50225
Bug #: 50225
Summary: The allocation status for polymorphic allocatable
variables is not set properly
Classification: Unclassified
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: arjen.markus895@gmail.com
If you compile the program below with "-fcheck=all", it fails, claiming that
the result variable in the function add_vector() is already allocated. The
error disappears when you change "class(point2d)" to "type(point2d)".
(In a more elaborate version of the program, it also fails without this option
and with this option there is a segmentation fault.)
module points2d3d
implicit none
type point2d
real :: x, y
end type
contains
subroutine print( point )
class(point2d) :: point
write(*,'(2f10.4)') point%x, point%y
end subroutine
subroutine random_vector( point )
class(point2d) :: point
call random_number( point%x )
call random_number( point%y )
point%x = 2.0 * (point%x - 0.5)
point%y = 2.0 * (point%y - 0.5)
end subroutine
function add_vector( point, vector )
class(point2d), intent(in) :: point, vector
class(point2d), allocatable :: add_vector
allocate( add_vector )
add_vector%x = point%x + vector%x
add_vector%y = point%y + vector%y
end function
end module points2d3d
program random_walk
use points2d3d
type(point2d), target :: point_2d, vector_2d
class(point2d), pointer :: point, vector
integer :: i
point => point_2d
vector => vector_2d
write(*,*) 'Two-dimensional walk:'
do i=1,10
call random_vector(point)
call random_vector(vector)
call print(add_vector(point, vector))
end do
end program random_walk
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50225] The allocation status for polymorphic allocatable variables is not set properly
2011-08-29 13:46 [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly arjen.markus895 at gmail dot com
@ 2011-08-29 14:01 ` dominiq at lps dot ens.fr
2011-08-29 14:28 ` [Bug fortran/50225] [OOP] " burnus at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: dominiq at lps dot ens.fr @ 2011-08-29 14:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50225
--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2011-08-29 13:49:48 UTC ---
On x86_64-apple-darwin10 I don't need the option -fcheck=all to get the
run-timr error. However the error goes away with any optimization above -O1 (at
least all those I have tried;-). This is also true for the original code posted
at http://gcc.gnu.org/ml/fortran/2011-08/msg00239.html which gives
Two-dimensional walk:
1.0883 0.1832
1.0618 0.1794
0.9765 0.0804
0.9459 0.0489
0.8895 -0.0245
0.9696 -0.0471
0.9587 -0.0147
0.8620 0.0154
0.8912 -0.0200
0.9624 -0.0397
Three-dimensional walk:
-0.5517 0.9285 0.1628
-0.6316 0.9795 0.1839
-0.5878 1.0590 0.2156
-0.6576 1.0815 0.3113
-0.5578 1.0328 0.3215
-0.5260 1.0436 0.4170
-0.4456 1.0752 0.4628
-0.4651 1.1609 0.3924
-0.4302 1.2149 0.3602
-0.5070 1.2377 0.4244
if compiled with -O1 or above. Note also that the executable obtained with -O1
run under valgrind without error. Apparently the "wrong part" is removed by
some optimization starting at -O1.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50225] [OOP] The allocation status for polymorphic allocatable variables is not set properly
2011-08-29 13:46 [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly arjen.markus895 at gmail dot com
2011-08-29 14:01 ` [Bug fortran/50225] " dominiq at lps dot ens.fr
@ 2011-08-29 14:28 ` burnus at gcc dot gnu.org
2011-08-29 17:08 ` janus at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-08-29 14:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50225
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
CC| |burnus at gcc dot gnu.org,
| |janus at gcc dot gnu.org
Summary|The allocation status for |[OOP] The allocation status
|polymorphic allocatable |for polymorphic allocatable
|variables is not set |variables is not set
|properly |properly
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-08-29 14:00:45 UTC ---
For what it is worth: The 2D example here and the 2D and 3D examples at
http://gcc.gnu.org/ml/fortran/2011-08/msg00239.html work with PGI 11.5, the 2D
example also works with Cray 7.1.4.111 but the 3D example causes an ICE.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50225] [OOP] The allocation status for polymorphic allocatable variables is not set properly
2011-08-29 13:46 [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly arjen.markus895 at gmail dot com
2011-08-29 14:01 ` [Bug fortran/50225] " dominiq at lps dot ens.fr
2011-08-29 14:28 ` [Bug fortran/50225] [OOP] " burnus at gcc dot gnu.org
@ 2011-08-29 17:08 ` janus at gcc dot gnu.org
2011-08-30 0:23 ` [Bug fortran/50225] [OOP] The allocation status for polymorphic allocatable function results " janus at gcc dot gnu.org
2011-08-30 1:12 ` janus at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-29 17:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50225
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2011-08-29
Ever Confirmed|0 |1
--- Comment #3 from janus at gcc dot gnu.org 2011-08-29 16:31:29 UTC ---
Preliminary patch which seems to fix the test case:
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c (revision 178183)
+++ gcc/fortran/trans-decl.c (working copy)
@@ -5215,17 +5215,25 @@ gfc_generate_function_code (gfc_namespace * ns)
{
tree result = get_proc_result (sym);
- if (result != NULL_TREE
- && sym->attr.function
- && !sym->attr.pointer)
+ if (result != NULL_TREE && sym->attr.function && !sym->attr.pointer)
{
if (sym->attr.allocatable && sym->attr.dimension == 0
&& sym->result == sym)
gfc_add_modify (&init, result, fold_convert (TREE_TYPE (result),
null_pointer_node));
+ else if (sym->ts.type == BT_CLASS
+ && CLASS_DATA (sym)->attr.allocatable
+ && sym->attr.dimension == 0 && sym->result == sym)
+ {
+ tmp = CLASS_DATA (sym)->backend_decl;
+ tmp = fold_build3_loc (input_location, COMPONENT_REF,
+ TREE_TYPE (tmp), result, tmp, NULL_TREE);
+ gfc_add_modify (&init, tmp, fold_convert (TREE_TYPE (tmp),
+ null_pointer_node));
+ }
else if (sym->ts.type == BT_DERIVED
- && sym->ts.u.derived->attr.alloc_comp
- && !sym->attr.allocatable)
+ && sym->ts.u.derived->attr.alloc_comp
+ && !sym->attr.allocatable)
{
rank = sym->as ? sym->as->rank : 0;
tmp = gfc_nullify_alloc_comp (sym->ts.u.derived, result, rank);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50225] [OOP] The allocation status for polymorphic allocatable function results is not set properly
2011-08-29 13:46 [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly arjen.markus895 at gmail dot com
` (2 preceding siblings ...)
2011-08-29 17:08 ` janus at gcc dot gnu.org
@ 2011-08-30 0:23 ` janus at gcc dot gnu.org
2011-08-30 1:12 ` janus at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-30 0:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50225
--- Comment #4 from janus at gcc dot gnu.org 2011-08-29 21:55:16 UTC ---
Author: janus
Date: Mon Aug 29 21:55:10 2011
New Revision: 178262
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178262
Log:
2011-08-29 Janus Weil <janus@gcc.gnu.org>
PR fortran/50225
* trans-decl.c (gfc_generate_function_code): Nullify polymorphic
allocatable function results.
2011-08-29 Janus Weil <janus@gcc.gnu.org>
PR fortran/50225
* gfortran.dg/class_result_1.f03: New.
Added:
trunk/gcc/testsuite/gfortran.dg/class_result_1.f03
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/trans-decl.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50225] [OOP] The allocation status for polymorphic allocatable function results is not set properly
2011-08-29 13:46 [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly arjen.markus895 at gmail dot com
` (3 preceding siblings ...)
2011-08-30 0:23 ` [Bug fortran/50225] [OOP] The allocation status for polymorphic allocatable function results " janus at gcc dot gnu.org
@ 2011-08-30 1:12 ` janus at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: janus at gcc dot gnu.org @ 2011-08-30 1:12 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50225
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #5 from janus at gcc dot gnu.org 2011-08-29 21:57:33 UTC ---
Fixed with r178262. Closing.
Thanks for the report, Arjen!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-08-29 21:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-29 13:46 [Bug fortran/50225] New: The allocation status for polymorphic allocatable variables is not set properly arjen.markus895 at gmail dot com
2011-08-29 14:01 ` [Bug fortran/50225] " dominiq at lps dot ens.fr
2011-08-29 14:28 ` [Bug fortran/50225] [OOP] " burnus at gcc dot gnu.org
2011-08-29 17:08 ` janus at gcc dot gnu.org
2011-08-30 0:23 ` [Bug fortran/50225] [OOP] The allocation status for polymorphic allocatable function results " janus at gcc dot gnu.org
2011-08-30 1:12 ` janus 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).