Bug 104845 - Wrong array size for component of CLASS array element
Summary: Wrong array size for component of CLASS array element
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2022-03-08 19:50 UTC by Tobias Burnus
Modified: 2022-04-21 17:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Testcase (test.f90) (452 bytes, text/plain)
2022-03-08 19:50 UTC, Tobias Burnus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2022-03-08 19:50:33 UTC
Created attachment 52585 [details]
Testcase  (test.f90)

The attached testcase has:

  type t2
    class(t), allocatable :: d(:,:)
  end type t2

which is allocated as:

  allocate (t   ::  var%ct2%d(3,2),  var%ct2a(5,4,2)%d(3,2))
  allocate (t   :: cvar%ct2%d(3,2), cvar%ct2a(5,4,2)%d(3,2))

Thus, the expected array size is 3*2 = 6. However, the result is
     6           0           6           0
for
  print *, size(var%ct2%d),  size(var%ct2a(5,3,2)%d), &
           size(cvar%ct2%d), size(cvar%ct2a(5,3,2)%d)

where 'ct2'  is scalar
  and 'ct2a(5,3,2)' is an array element (also scalar)
Comment 1 Tobias Burnus 2022-03-08 20:08:51 UTC
Part of the testcase is part of the patch at:
  https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591414.html

When this PR is fixed (and that patch is committed): Please uncomment the commented lines.
Comment 2 Tobias Burnus 2022-03-09 09:40:35 UTC
Mentioned patch was committed as r12-7558-ga5c9b7c4f95ef77b83da82241cabdf80d8b1cad5
Thus, when this PR is fixed, please uncomment the respective lines in
   gcc/testsuite/gfortran.dg/sizeof_6.f90
Comment 3 Mikael Morin 2022-04-21 17:26:01 UTC
(In reply to Tobias Burnus from comment #0)
> 
>   allocate (t   ::  var%ct2%d(3,2),  var%ct2a(5,4,2)%d(3,2))
>   allocate (t   :: cvar%ct2%d(3,2), cvar%ct2a(5,4,2)%d(3,2))
> 
> Thus, the expected array size is 3*2 = 6. However, the result is
>      6           0           6           0
> for
>   print *, size(var%ct2%d),  size(var%ct2a(5,3,2)%d), &
>            size(cvar%ct2%d), size(cvar%ct2a(5,3,2)%d)
> 
> where 'ct2'  is scalar
>   and 'ct2a(5,3,2)' is an array element (also scalar)

ct2a(5,3,2)%d isn’t allocated, should it be ct2a(5,4,2)%d ?