Hi Paul,

I see that you are either not a fan of worms or just vegan...

Well, this looks like a not so easy thing to fix.
Your (partial) patch at least improves the situation.
Unless someone else objects, proceed on mainline,
and wait a while before considering backporting.
Also update the PR accordingly.

Thanks,
Harald

> Gesendet: Freitag, 3. April 2026 um 18:48
> Von: "Paul Richard Thomas" <[email protected]>
> An: "Harald Anlauf" <[email protected]>
> CC: "[email protected]" <[email protected]>
> Betreff: Re: [Patch, fortran] PR100155 - [13/14/15/16 Regression] ICE in 
> gfc_conv_intrinsic_size, at fortran/trans-intrinsic.c:805
>
> Hello Harald,
> 
> Your testcase opened up a can of worms. The fix for the parentheses is
> straightforward:
> 
>    /* Assign the 'data' of a class object to a derived type.  */
>    if (lhs-&gt;ts.type == BT_DERIVED
>        &amp;&amp; rhs-&gt;ts.type == BT_CLASS
> -      &amp;&amp; rhs-&gt;expr_type != EXPR_ARRAY)
> +      &amp;&amp; (rhs-&gt;expr_type != EXPR_ARRAY
> +         &amp;&amp; rhs-&gt;expr_type != EXPR_OP))
>      gfc_add_data_component (rhs);
> 
>    /* Make sure there is a vtable and, in particular, a _copy for the
> 
> However, the following has faults as shown, with or without parentheses:
> program p
>    integer :: i
>    type :: t
>      integer, allocatable :: i(:)
>    end type
>    type (t), allocatable :: src(:), ans(:)
>    src = [t([1,2]), t([3,4])] ! Leaks memory 16 bytes in 2 blocks;
>                               ! familiar from PDT memory leaks :-(
>    ans = f(src)
>    do i = 1,2
>      print *, "src = ", src(i)%i, "ans = ",ans(i)%i
>      deallocate (ans(i)%i, src(i)%i)
>    enddo
>    deallocate (ans, src)
> contains
>    function f(x) result(z)
>      class(t), intent(inout) :: x(:)
>      type(t)  :: z (size(x))
>      class(t), allocatable :: a(:)
>      class(t), allocatable :: b(:)
>      allocate (a(size(x)))
>      select type (x)
>        type is (t)
> !         a = x                                ! Mangles src and causes
>                                                ! double free at line 11
>      end select
>      b = x
>      z = (b)                                  ! ICE, without patch
>    end
> end
> 
> Cheers
> 
> Paul
> 
> On Thu, 2 Apr 2026 at 19:49, Harald Anlauf <[email protected]> wrote:
> &gt;
> &gt; Hi Paul,
> &gt;
> &gt; On 4/2/26 11:36, Paul Richard Thomas wrote:
> &gt; &gt; Hi All,
> &gt; &gt;
> &gt; &gt; The attached fixes the PR and cures the memory leak in pr105168.
> &gt; &gt;
> &gt; &gt; Regtested on FC43/x86_64. OK for mainline and later backporting?
> &gt;
> &gt; as you say, the patch is indeed not too pretty, although
> &gt; it works with the testcase that comes with it.
> &gt;
> &gt; It does not fix the following variation for me:
> &gt;
> &gt; program p
> &gt;    type :: t
> &gt;    end type
> &gt; contains
> &gt;    recursive function f(x) result(z)
> &gt;      class(*), intent(in) :: x(:)
> &gt;      type(t)  :: z (size(x))
> &gt;      class(t), allocatable :: a(:)
> &gt;      class(t), allocatable :: b(:)
> &gt;      allocate (a(size(x)))
> &gt;      b = f((a))
> &gt;      z = b   ! no ICE
> &gt;      z = (b) ! ICE
> &gt;    end
> &gt; end
> &gt;
> &gt; % gfc-16 pr100155.f90
> &gt; f951: internal compiler error: Segmentation fault
> &gt; 0x26ba694 internal_error(char const*, ...)
> &gt;          ../../gcc-trunk/gcc/diagnostic-global-context.cc:787
> &gt; 0x127c0af crash_signal
> &gt;          ../../gcc-trunk/gcc/toplev.cc:325
> &gt; 0xa2bc63 gfc_add_component_ref(gfc_expr*, char const*)
> &gt;          ../../gcc-trunk/gcc/fortran/class.cc:217
> &gt; 0xaf6642 resolve_ordinary_assign
> &gt;          ../../gcc-trunk/gcc/fortran/resolve.cc:13223
> &gt; 0xaf6642 gfc_resolve_code(gfc_code*, gfc_namespace*)
> &gt;          ../../gcc-trunk/gcc/fortran/resolve.cc:14336
> &gt; 0xaf7c62 resolve_codes
> &gt;          ../../gcc-trunk/gcc/fortran/resolve.cc:20289
> &gt; 0xaf7ba3 resolve_codes
> &gt;          ../../gcc-trunk/gcc/fortran/resolve.cc:20270
> &gt; 0xaf7d02 gfc_resolve(gfc_namespace*)
> &gt;          ../../gcc-trunk/gcc/fortran/resolve.cc:20324
> &gt; 0xae2ac9 resolve_all_program_units
> &gt;          ../../gcc-trunk/gcc/fortran/parse.cc:7531
> &gt; 0xae2ac9 gfc_parse_file()
> &gt;          ../../gcc-trunk/gcc/fortran/parse.cc:7793
> &gt; 0xb41caf gfc_be_parse_file
> &gt;          ../../gcc-trunk/gcc/fortran/f95-lang.cc:247
> &gt;
> &gt; You might proceed nevertheless for 16-trunk, and either keep
> &gt; an eye on the above, or add it to the present (or a new) PR.
> &gt; (It could be a different existing PR; haven't searched bugzilla.
> &gt; In that case just go ahead.)
> &gt;
> &gt; Thanks,
> &gt; Harald
> &gt;
> &gt;</[email protected]>

Reply via email to