public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/104651] New: [OOP] CLASS with assumed-size/assumed-rank array
@ 2022-02-22 21:24 burnus at gcc dot gnu.org
2022-02-22 22:01 ` [Bug fortran/104651] " kargl at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2022-02-22 21:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104651
Bug ID: 104651
Summary: [OOP] CLASS with assumed-size/assumed-rank array
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
Target Milestone: ---
The following looks valid - but gfortran complains:
7 | call bar(A)
| 1
Error: Rank mismatch in argument ‘x’ at (1) (rank-1 and rank-2)
8 | call bar2(B)
| 1
Error: Rank mismatch in argument ‘y’ at (1) (rank-2 and rank-1)
Additionally, I had expected that the array is passed just to class->_data, but
the dump shows that there is a full array descriptor, i.e. class->_data.data
for the dummy argument.
In trans-types.cc's gfc_get_derived_type, the code path taken is:
if (c->attr.pointer || c->attr.allocatable || c->attr.pdt_array)
...
field_type = gfc_build_array_type (field_type, c->as, akind,
and not:
else
field_type = gfc_get_nodesc_array_type (field_type, c->as,
PACKED_STATIC,
!c->attr.target);
implicit none (type, external)
type t
integer :: i
end type t
type(t) :: A(10,10), B(10)
call bar(A)
call bar2(B)
contains
subroutine bar(x)
class(t) :: x(*)
x(1)%i = x(2)%i
end
subroutine bar2(y)
class(t) :: y(5,10)
y(1,1)%i = y(2,2)%i
end
end
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug fortran/104651] [OOP] CLASS with assumed-size/assumed-rank array
2022-02-22 21:24 [Bug fortran/104651] New: [OOP] CLASS with assumed-size/assumed-rank array burnus at gcc dot gnu.org
@ 2022-02-22 22:01 ` kargl at gcc dot gnu.org
2022-02-23 8:03 ` burnus at gcc dot gnu.org
2022-02-23 8:59 ` burnus at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-02-22 22:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104651
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #1 from kargl at gcc dot gnu.org ---
(In reply to Tobias Burnus from comment #0)
> The following looks valid - but gfortran complains:
>
> 7 | call bar(A)
> | 1
> Error: Rank mismatch in argument ‘x’ at (1) (rank-1 and rank-2)
>
> 8 | call bar2(B)
> | 1
> Error: Rank mismatch in argument ‘y’ at (1) (rank-2 and rank-1)
>
>
> Additionally, I had expected that the array is passed just to class->_data,
> but the dump shows that there is a full array descriptor, i.e.
> class->_data.data for the dummy argument.
>
>
> In trans-types.cc's gfc_get_derived_type, the code path taken is:
>
> if (c->attr.pointer || c->attr.allocatable || c->attr.pdt_array)
> ...
> field_type = gfc_build_array_type (field_type, c->as, akind,
>
> and not:
> else
> field_type = gfc_get_nodesc_array_type (field_type, c->as,
> PACKED_STATIC,
> !c->attr.target);
>
>
> implicit none (type, external)
> type t
> integer :: i
> end type t
> type(t) :: A(10,10), B(10)
>
> call bar(A)
> call bar2(B)
> contains
> subroutine bar(x)
> class(t) :: x(*)
> x(1)%i = x(2)%i
> end
> subroutine bar2(y)
> class(t) :: y(5,10)
> y(1,1)%i = y(2,2)%i
> end
> end
Error look correct to me. Interfaces are resolved by type, kind, and rank;
sometimes referred to TKR. Is there an exception for class?
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug fortran/104651] [OOP] CLASS with assumed-size/assumed-rank array
2022-02-22 21:24 [Bug fortran/104651] New: [OOP] CLASS with assumed-size/assumed-rank array burnus at gcc dot gnu.org
2022-02-22 22:01 ` [Bug fortran/104651] " kargl at gcc dot gnu.org
@ 2022-02-23 8:03 ` burnus at gcc dot gnu.org
2022-02-23 8:59 ` burnus at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2022-02-23 8:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104651
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Additionally, for the following (from
gcc/testsuite/gfortran.dg/finalize_15.f90),
class(t1), allocatable :: x(:,:)
call fin_test_1(x(::2,::3))
with
subroutine fin_test_1(x)
class(t1), intent(out) :: x(5,4)
I had expected a copy in/copy out - but in reality, fin_test_1 receives a
noncontiguous array.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug fortran/104651] [OOP] CLASS with assumed-size/assumed-rank array
2022-02-22 21:24 [Bug fortran/104651] New: [OOP] CLASS with assumed-size/assumed-rank array burnus at gcc dot gnu.org
2022-02-22 22:01 ` [Bug fortran/104651] " kargl at gcc dot gnu.org
2022-02-23 8:03 ` burnus at gcc dot gnu.org
@ 2022-02-23 8:59 ` burnus at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2022-02-23 8:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104651
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to kargl from comment #1)
> (In reply to Tobias Burnus from comment #0)
> > Error: Rank mismatch in argument ‘x’ at (1) (rank-1 and rank-2)
> > Error: Rank mismatch in argument ‘y’ at (1) (rank-2 and rank-1)
> >
> > subroutine bar(x)
> > class(t) :: x(*)
> >
> > subroutine bar2(y)
> > class(t) :: y(5,10)
>
> Error look correct to me. Interfaces are resolved by type, kind, and rank;
> sometimes referred to TKR. Is there an exception for class?
Passing an array of any rank or even array element to ASSUMED-SIZE and
EXPLICIT-SIZE ARRAYS is a Fortran 66 feature which still exists. For those, the
simple (contiguous) byte stream ("storage sequence") is passed – and the
partition of that stream into array bounds/elements is determined by the
callee.
Example:
integer A(10), B(10,10), C(10,10,10)
call foo(A,A); call foo(B,B); call foo(C,C)
contains
subroutine foo(x,y)
integer, intent(in) :: x(5:7,*), y(5,2)
end
end
This works just fine in gfortran. But for CLASS the like-wise code does not
work.
>From the standard (allocatable/pointers and deferred-shape arrays are in
section):
Fortran 2018, "15.5.2.4 Ordinary dummy variables":
"If a dummy argument is an assumed-shape array, the rank of the actual argument
shall be the same as the rank of the dummy argument ..."
As this restriction does not exist for assumed-size/explicit-size array
dummies, those are permitted. Some more wording is then in "15.5.2.11 Sequence
association":
"Sequence association only applies when the dummy argument is an explicit-shape
or assumed-size array. The rest of this subclause only applies in that case.
"An actual argument represents an element sequence if it is an array
expression, an array element designator, a default character scalar, or a
scalar of type character with the C character kind (18.2.2). [...]"
For details, see the two sections mentioned above as I did leave out some bits
related to this discussion.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-23 8:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 21:24 [Bug fortran/104651] New: [OOP] CLASS with assumed-size/assumed-rank array burnus at gcc dot gnu.org
2022-02-22 22:01 ` [Bug fortran/104651] " kargl at gcc dot gnu.org
2022-02-23 8:03 ` burnus at gcc dot gnu.org
2022-02-23 8:59 ` burnus 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).