Bug 58793 - Wrong value for _vtab for intrinsic types with CLASS(*): storage_size of class(*) gives wrong result
Summary: Wrong value for _vtab for intrinsic types with CLASS(*): storage_size of clas...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: wrong-code
Depends on: 58851 58858
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-18 18:18 UTC by Vladimir Fuka
Modified: 2013-10-29 20:48 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-10-18 00:00:00


Attachments
Test case (435 bytes, text/plain)
2013-10-19 05:41 UTC, Tobias Burnus
Details
Fix for the PR (1.17 KB, patch)
2013-10-19 22:04 UTC, Paul Thomas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Fuka 2013-10-18 18:18:09 UTC
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
Comment 1 Tobias Burnus 2013-10-18 19:17:44 UTC
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.  */
Comment 2 Tobias Burnus 2013-10-18 19:40:16 UTC
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.
Comment 3 Tobias Burnus 2013-10-19 05:41:11 UTC
Created attachment 31048 [details]
Test case
Comment 4 Paul Thomas 2013-10-19 06:35:10 UTC
(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
Comment 5 Paul Thomas 2013-10-19 22:04:30 UTC
Created attachment 31054 [details]
Fix for the PR

This combines a rather obvious fix with Tobias' testcase.

I'll submit tomorrow.

Paul
Comment 6 Tobias Burnus 2013-10-23 05:44:04 UTC
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
Comment 7 Tobias Burnus 2013-10-23 06:01:38 UTC
(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
Comment 8 Paul Thomas 2013-10-29 20:48:05 UTC
Fixed on trunk.

Thanks for the patch

Paul