Hello Jerry, The patch looks OK in principle. However, the chunk in trans-stmt.cc did not apply cleanly and, more importantly, trans-expr.cc (gfc_conv_expr_op): Copy a parenthesized scalar is missing, together with the corresponding entry in trans.h.
Cheers Paul On Fri, 6 Nov 2026 at 23:13, Jerry D <[email protected]> wrote: > > The following attached patch regression tested on x86_64 and arm. > > OK for mainline? > > Regards, > > Jerry > > --- > > [PATCH] fortran: [PR128478] Copy a parenthesized scalar CLASS actual argument > > A parenthesized scalar CLASS variable passed as an actual argument was > not copied, so the dummy aliased the variable, and passing it to a TYPE > dummy with allocatable components segfaulted, because the components of > the CLASS container were copied and freed as if it were the derived > type. Make the value of a parenthesized scalar CLASS variable a copy in > gfc_conv_expr_op, which also serves the ASSOCIATE selector, keep the > free of the copy until after the call, and leave its components to the > copy's own finalization. > > Assisted-by: Claude Opus 5.5 > > PR fortran/128478 > > gcc/fortran/ChangeLog: > > * trans-expr.cc (gfc_conv_expr_op): Copy a parenthesized scalar > CLASS variable. > (gfc_conv_procedure_call): Do not copy or free the allocatable > components of the copy of a parenthesized scalar CLASS variable. > (gfc_conv_expr_reference): Keep the free of that copy in se->post. > * trans-stmt.cc (trans_associate_var): Remove the copy of a > parenthesized CLASS selector, now done by gfc_conv_expr_op. > > gcc/testsuite/ChangeLog: > > * gfortran.dg/asan/paren_class_copy_1.f90: New test. > ---
