Hi Harald, In answer to your question: void gfc_replace_expr (gfc_expr *dest, gfc_expr *src) { free_expr0 (dest); *dest = *src; free (src); } So it does indeed do the job.
I should perhaps have remarked that, following the divide error, gfc_simplify_expr was returning a mutilated version of the expression and this was somehow connected with successfully simplifying the parentheses. Copying and replacing on no errors deals with the problem. Thanks Paul On Wed, 7 Jun 2023 at 19:38, Harald Anlauf <anl...@gmx.de> wrote: > > Hi Paul! > > On 6/7/23 18:10, Paul Richard Thomas via Gcc-patches wrote: > > Hi All, > > > > Three more fixes for PR87477. Please note that PR99350 was a blocker > > but, as pointed out in comment #5 of the PR, this has nothing to do > > with the associate construct. > > > > All three fixes are straight forward and the .diff + ChangeLog suffice > > to explain them. 'rankguessed' was made redundant by the last PR87477 > > fix. > > > > Regtests on x86_64 - good for mainline? > > > > Paul > > > > Fortran: Fix some more blockers in associate meta-bug [PR87477] > > > > 2023-06-07 Paul Thomas <pa...@gcc.gnu.org> > > > > gcc/fortran > > PR fortran/99350 > > * decl.cc (char_len_param_value): Simplify a copy of the expr > > and replace the original if there is no error. > > This seems to lack a gfc_free_expr (p) in case the gfc_replace_expr > is not executed, leading to a possible memleak. Can you check? > > @@ -1081,10 +1082,10 @@ char_len_param_value (gfc_expr **expr, bool > *deferred) > if (!gfc_expr_check_typed (*expr, gfc_current_ns, false)) > return MATCH_ERROR; > > - /* If gfortran gets an EXPR_OP, try to simplify it. This catches things > - like CHARACTER(([1])). */ > - if ((*expr)->expr_type == EXPR_OP) > - gfc_simplify_expr (*expr, 1); > + /* Try to simplify the expression to catch things like > CHARACTER(([1])). */ > + p = gfc_copy_expr (*expr); > + if (gfc_is_constant_expr (p) && gfc_simplify_expr (p, 1)) > + gfc_replace_expr (*expr, p); > else > gfc_free_expr (p); > > > * gfortran.h : Remove the redundant field 'rankguessed' from > > 'gfc_association_list'. > > * resolve.cc (resolve_assoc_var): Remove refs to 'rankguessed'. > > > > PR fortran/107281 > > * resolve.cc (resolve_variable): Associate names with constant > > or structure constructor targets cannot have array refs. > > > > PR fortran/109451 > > * trans-array.cc (gfc_conv_expr_descriptor): Guard expression > > character length backend decl before using it. Suppress the > > assignment if lhs equals rhs. > > * trans-io.cc (gfc_trans_transfer): Scalarize transfer of > > associate variables pointing to a variable. Add comment. > > * trans-stmt.cc (trans_associate_var): Remove requirement that > > the character length be deferred before assigning the value > > returned by gfc_conv_expr_descriptor. Also, guard the backend > > decl before testing with VAR_P. > > > > gcc/testsuite/ > > PR fortran/99350 > > * gfortran.dg/pr99350.f90 : New test. > > > > PR fortran/107281 > > * gfortran.dg/associate_5.f03 : Changed error message. > > * gfortran.dg/pr107281.f90 : New test. > > > > PR fortran/109451 > > * gfortran.dg/associate_61.f90 : New test > > Otherwise LGTM. > > Thanks for the patch! > > Harald > > -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein