Complex variable has storage size of only real a variable when passed as class(*). module m contains subroutine s(o) class(*) :: o write (*,*) storage_size(o) select type (o) type is (complex) print *,storage_size(o) type is (complex(8)) print *,storage_size(o) type is (complex(16)) print *,storage_size(o) end select end end program p use m call s((1._4,2._4)) call s((1._8,2._8)) call s((1._16,2._16)) end gcc version 4.8.2 20131003 Expected output: 64 64 128 128 256 256 Actual output: 32 64 64 128 128 256
Confirmed. Patch: diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c index be4959a..8d911bb 100644 --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -2504,5 +2504,7 @@ gfc_find_intrinsic_vtab (gfc_typespec *ts) else c->initializer = gfc_get_int_expr (gfc_default_integer_kind, - NULL, ts->kind); + NULL, + ts->type == BT_COMPLEX + ? 2*ts->kind : ts->kind); /* Add component _extends. */
Actually, that patch is wrong: The expected values are for KIND / REAL / COMPLEX 4 32 64 8 64 128 10 128 256 << 16 128 256 And the marked line one cannot get from the kind number. The proper way it use use target-memory.c's size_complex() - which is not publicly exported. There is gfc_element_size, but that operates on an expression and not on a type spec.
Created attachment 31048 [details] Test case
(In reply to Tobias Burnus from comment #3) > Created attachment 31048 [details] > Test case Tobias, Are you taking this one, or is this a low-lying bug that you are dangling under my nose :-) ? Cheers Paul
Created attachment 31054 [details] Fix for the PR This combines a rather obvious fix with Tobias' testcase. I'll submit tomorrow. Paul
Author: burnus Date: Wed Oct 23 05:44:02 2013 New Revision: 203945 URL: http://gcc.gnu.org/viewcvs?rev=203945&root=gcc&view=rev Log: 2013-10-23 Tobias Burnus <burnus@net-b.de> PR fortran/58793 * interface.c (compare_parameter): Reject passing TYPE(*) to CLASS(*). 2013-10-23 Tobias Burnus <burnus@net-b.de> PR fortran/58793 * gfortran.dg/assumed_type_8.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/assumed_type_8.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/interface.c trunk/gcc/testsuite/ChangeLog
(In reply to Paul Thomas from comment #5) > Created attachment 31054 [details] - Fix for the PR which was committed as follows. Comment 6 is about one side issue found during review; pending is a patch for another side issue: Holleriths. Author: pault Date: Tue Oct 22 04:40:57 2013 New Revision: 203915 URL: http://gcc.gnu.org/viewcvs?rev=203915&root=gcc&view=rev Log: 2013-10-22 Paul Thomas <pault@gcc.gnu.org> PR fortran 57893 * class.c : Include target-memory.h. (gfc_find_intrinsic_vtab) Build a minimal expression so that gfc_element_size can be used to obtain the storage size, rather that the kind value. 2013-10-22 Paul Thomas <pault@gcc.gnu.org> PR fortran 57893 * gfortran.dg/unlimited_polymorphic_13.f90 : New test. Added: trunk/gcc/testsuite/gfortran.dg/unlimited_polymorphic_13.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/class.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk. Thanks for the patch Paul