On 11/22/26 11:40 AM, Mikael Morin wrote:
From: Mikael Morin <[email protected]>
Hello,
This is the second version of part 7 of the array descriptor series.
The first version was posted in early september [1].
The plan was to fix a PR first [2] before coming back to this series, to
make a merge conflict resolution easier in the implementation of ASSOCIATED
and have first better testing coverage there. Starting from that PR, and
following regressions, I have been producing wrong-code PRs faster than I
have been fixing them since then.
Now stage 1 has ended, and I would like to push the series before it's too
late. It was first posted in september, and it fixes a couple of minor
bugs, so it qualifies as stage 3 material. I have dropped the patch
changing ASSOCIATED, and amended the other patches considering Jerry's
comments. For patch 4, the simple suggested changes have been included,
but the redundant reference walking is eliminated separately in a follow-up
patch. Finally, the cobounds copy, which was propagated to the three scalar
descriptor initialization functions in the first version, is no longer
moved to the factored function and only remains in the function it was
already present in. It was causing regressions with static coarrays
initialization.
I fortran-tested the series again on x86_64-pc-linux-gnu without new
failure. OK for mainline? I plan to push the series in the second half of
the coming week if I don't get any further comment.
[1] Version 1:
https://inbox.sourceware.org/fortran/[email protected]/t/#u
https://gcc.gnu.org/pipermail/gcc-patches/2026-September/729953.html
[2] PR127233: ASSOCIATED ignores element length:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127233
--
this is the seventh part of the array descriptor series. The previous part
isolated the initialization of scalar descriptors to three dedicated
functions. These three functions do more or less the same thing, but with
subtle differences, either caused by bugs, useless code, or different
requirements or assumptions about their input.
This part fixes the bugs, removes useless differences and unifies the three
implementations.
Patches 1, 4 and 9 fix bugs in the descriptor initialization. They are
affecting either the elem_len value (patches 1 and 9) or the type value
(patch 4).
Patch 3 fixes a possible ICE bug.
Patches 2 and 7 remove useless work in the descriptor initialization
generation.
Patches 6 and 8 factor common code to a shared function.
Patch 5 integrates more tightly class container extraction and value pointer
reference extraction.
--
v1 to v2 changes:
01->01: Keep assertion but loosen the condition to allow non-pointers in the
untyped (i.e. unlimited polymorphic) case. Move a comment so that
it is obvious what it applies to. Add a comment regarding the
non-initialization of element length.
04->04: Always initialize class_ref variable. Use a checking-only assert.
()->05: New patch: integrate extraction of the value pointer to the
reference walk so that it's not done redundantly.
05->06: Keep cobounds copy out of the factored function.
06->(): Drop patch.
08->08: Adjust as a consequence of the removal of patch 06.
--
Previous parts in the array descriptor series:
part 6 (pushed): fortran: Move scalar descriptor init
part 5 (pushed): fortran: Move null- or default-initialization
part 4 (pushed): fortran: Move dtype fields constants
part 3 (dropped): fortran: Ensure read-only getters
part 2 (pushed): fortran: Add getters and setters
part 1 (pushed): fortran: Move existing functions to a separate file
Mikael Morin (9):
fortran: array descriptor: Guess size from declared type [PR122521]
fortran: array descriptor: Simplify scalar dtype initialization
[PR122521]
fortran: array descriptor: Add a check for class container type
[PR122521]
fortran: array descriptor: Mark polymorphic descriptors as such
[PR122521]
fortran: array descriptor: Extract class container with its data
pointer [PR122521]
fortran: array descriptor: Factor scalar descriptor init 1/2
[PR122521]
fortran: array descriptor: Remove redundant array type unwrapping
[PR122521]
fortran: array descriptor: Factor scalar descriptor init 2/2
[PR122521]
fortran: array descriptor: Set polymorphic elem_len value [PR122521]
gcc/fortran/trans-descriptor.cc | 179 ++++++++++++++----
gcc/fortran/trans-descriptor.h | 6 +-
gcc/fortran/trans-expr.cc | 4 +-
gcc/fortran/trans-types.cc | 55 +++++-
gcc/testsuite/gfortran.dg/assumed_rank_26.f90 | 26 +++
gcc/testsuite/gfortran.dg/assumed_rank_27.f90 | 39 ++++
gcc/testsuite/gfortran.dg/sizeof_7.f90 | 30 +++
gcc/testsuite/gfortran.dg/sizeof_8.f90 | 33 ++++
8 files changed, 328 insertions(+), 44 deletions(-)
create mode 100644 gcc/testsuite/gfortran.dg/assumed_rank_26.f90
create mode 100644 gcc/testsuite/gfortran.dg/assumed_rank_27.f90
create mode 100644 gcc/testsuite/gfortran.dg/sizeof_7.f90
create mode 100644 gcc/testsuite/gfortran.dg/sizeof_8.f90
Here are comments on the whole series of Part 7. The only real issue is in 9/9
Branch mikael-pr122521 on gcc-test: all 9 patches applied cleanly with
plain git am on top of 6f8e63ffd1a (PR128936). Built and installed in
objtst. I applied these to my worktree to make sure no conflicts with my
pending work. All good
Testsuite (test-gcc-test, -m64):
gfortran: 54955 PASS, 2 FAIL (pr49213 -O2/-O3, known upstream IPA
regression, not from this series)
libgomp: 6202 PASS, 0 FAIL
New tests sizeof_7, sizeof_8, assumed_rank_26, assumed_rank_27 pass.
Review, in patch order
======================
1/9 Guess size from declared type
Minor/unconfirmed reachability: for a CLASS(*) container whose _data
is a descriptor, get_class_declared_type returns void * (the element
type is ptr_type_node), not void. The BT_CLASS VOID_TYPE_P check
then misses it and the size becomes sizeof (void *) instead of
NULL_TREE. The comment says the unlimited polymorphic case gets no
size; that holds only for scalar containers. I did not find an input
that reaches this.
2/9 Simplify scalar dtype initialization
Behaviour-preserving as far as I can see.
Nit: the comments on the 4-arg gfc_set_descriptor_from_scalar and on
gfc_set_descriptor_from_scalar_class still mention SCALAR_EXPR, the
argument this patch removes.
3/9 Add a check for class container type
OK. Replaced by 5/9 anyway.
4/9 Mark polymorphic descriptors as such
gcc_checking_assert (is_class) is followed by TREE_TYPE (class_ref).
With release checking, a false return is a NULL dereference instead
of a clean ICE; use gcc_assert.
Style: the helper could return the class container tree (NULL_TREE
if not polymorphic) instead of bool plus an out parameter.
5/9 Extract class container with its data pointer
Latent bug: class_container is only assigned when class_ref !=
nullptr, then gcc_assert (class_container != nullptr). A call using
the advertised default arguments ICEs on every polymorphic ref. The
only caller passes both, so latent; assign class_container
unconditionally.
Question: a top-level ARRAY_REF is never taken as the value-pointer
candidate, so its index would be dropped. Array-element and
pointer-component variations came out right, so possibly
unreachable. In other words, its not a problem at this time.
6/9, 7/9, 8/9 Factor / remove redundant unwrapping
OK. The data/cobounds store reorder in 6/9 is harmless
(independent fields).
9/9 Set polymorphic elem_len value -- BUG
elem_len is set to vptr->_size without scaling by _len. A CLASS(*)
scalar holding a character value gets the character kind size, not
the length:
class(*), allocatable :: y
y = 'abcdefg'
call s1(y) ! s1: class(*) a(..) -> s2: type(*) a(..); sizeof(a)
Series: 1. Trunk: 24. Correct: 7. The rank-1 path gets it right
(14 for 2 x len 7). Fix:
gfc_resize_class_size_with_len (&b, class_ref,
gfc_vptr_size_get (vptr))
and add a sizeof test for that case.
Tests (nit): none of the 4 new tests has a "PR fortran/122521" line.
On the 9/9 bug I attached a reproducer to clarify.
So patches 1 thru 8 are OK to commit at your discretion.
On the reproducer, you can make it a new PR to track and commit 9/9 if it helps
moving forward
Regards and thanks for the work!
Regards,
Jerry
! { dg-do run }
!
! PR 122521
program prog
implicit none
type :: t
integer :: c(3)
end type
class(*), allocatable :: y
integer :: nfail = 0
character(len=7) :: c1 = 'abcdefg'
character(kind=4, len=5) :: c4 = 4_'vwxyz'
y = c1
call s1(y, 7_8, 1)
y = c4
call s1(y, 20_8, 2)
y = 42_8
call s1(y, 8_8, 3)
y = t([1, 2, 3])
call s1(y, 12_8, 4)
if (nfail /= 0) error stop nfail
contains
subroutine s1(a, e, n)
class(*), intent(in) :: a(..)
integer(kind=8), intent(in) :: e
integer, intent(in) :: n
call s2(a, e, n)
end subroutine
subroutine s2(a, e, n)
type(*), intent(in) :: a(..)
integer(kind=8), intent(in) :: e
integer, intent(in) :: n
if (sizeof(a) /= e) then
print *, n, 'sizeof', sizeof(a), 'expected', e
nfail = nfail + 1
end if
end subroutine
end program