https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125427
--- Comment #4 from Mikael Morin <mikael at gcc dot gnu.org> --- Created attachment 64613 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64613&action=edit Alternative draft patch This is the patch I have waiting in my tree (I'm not working on it at the moment). It fixes the testcase in this PR, but doesn't fix the PR125428 testcase as I expected it would, for reasons that I haven't investigated. The class.cc and expr.cc parts fix wrong expression ranks I encountered while working on the patch, but those are an independent problem. The patch adds a tree argument to the finalization generation functions, so that an existing reference can be reused from that argument instead of regenerating it a second time from the gfc_expr one. There is a disabled conditional (if (false && ...)); that code is probably necessary, but the testcase doesn't seem to exercise it. The patch is supposed to work for both scalar and array cases (I think the problem applies to both), but the testcase lacks an array case.
