https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122521

--- Comment #38 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Mikael Morin <[email protected]>:

https://gcc.gnu.org/g:05d8603dca5ab3031c124d3ee715932700d1f3f8

commit r17-6973-g05d8603dca5ab3031c124d3ee715932700d1f3f8
Author: Mikael Morin <[email protected]>
Date:   Tue Dec 1 11:54:11 2026 +0100

    fortran: array descriptor: Guess size from declared type [PR122521]

    When associating a polymorphic scalar with a polymorphic assumed-rank
dummy,
    make sure that the type size is guessed from the declared type, not the
    class descriptor type, to initialize the array descriptor elem_len field.

    Before this change, the size was set to that of the class descriptor,
    causing the intrinsic SIZEOF to return a wrong value.  Fortunately, I
    couldn't find any observable effect except for this (non-standard)
    intrinsic.

    The use of the declared type as source of type size makes it possible to
    have void that comes out as source, in the scalar unlimited polymorphic
    case.  This causes the dtype value construction to trip on an assert
because
    it's not prepared for a void type, as there's no size that can be guessed
    from it.  This is corrected by skipping the element length initialization
if
    the input type is void.

    Note: This is replacing an initialization of the element length with a
wrong
    value (the class descriptor size) by an initialization with another wrong
    value (zero) in the scalar unlimited polymorphic case, or a sometimes right
    value in other polymorphic cases.  The last patch (9/9) in this series will
    correct this for the scalar case by immediately overwriting that value with
    the right one taken from the virtual table.

            PR fortran/122521

    gcc/fortran/ChangeLog:

            * trans-descriptor.cc (gfc_build_dtype_constructor): Accept NULL
            size argument.  Don't build any initialization of the elem_len
field
            if size is NULL.
            * trans-types.cc (get_class_declared_type): New function.
            (gfc_get_dtype_rank_type): Clear the size by default.  If the type
            is a class container type, use the data target type to guess the
            size, and don't set any size if it is void as in the scalar
            unlimited polymorphic case.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/sizeof_7.f90: New test.

Reply via email to