https://gcc.gnu.org/g:55b661e3435c471fd07820ec67ca3975050554e6
commit 55b661e3435c471fd07820ec67ca3975050554e6 Author: Mikael Morin <[email protected]> Date: Tue Feb 11 21:34:11 2025 +0100 gimplify: reject non_lvalue as assignment lhs [PR122521] The previous patch made fortran array descriptor getters return references wrapped in a non_lvalue. Their usage on the left of an assignment is invalid IL, but it is actually accepted by gimplification which just unwraps the non_lvalue. This change rejects usage of non_lvalue on the left hand side of an assignment, making the invalid IL more visible. PR fortran/122521 gcc/ChangeLog: * gimplify.cc (gimplify_modify_expr): Throw an error if the left hand side is a non_lvalue. Diff: --- gcc/gimplify.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index d8725e4c5e20..58e5934dc6a1 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -7315,6 +7315,12 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, gcc_assert (TREE_CODE (*expr_p) == MODIFY_EXPR || TREE_CODE (*expr_p) == INIT_EXPR); + if (TREE_CODE (*to_p) == NON_LVALUE_EXPR) + { + error ("non-lvalue used as lhs in %qD", *expr_p); + return GS_ERROR; + } + /* Trying to simplify a clobber using normal logic doesn't work, so handle it here. */ if (TREE_CLOBBER_P (*from_p))
