From: Mikael Morin <[email protected]>

I noticed this while working on the PR128349 fix.
Fortran-tested on aarch64-unknown-linux-gnu.
I plan to push to mainline tomorrow or so.

-- >8 --

In trans_scalar_class_assign, some tree nodes that are created are not used
if the early return path is taken.  Delay their creation.

gcc/fortran/ChangeLog:

        * trans-expr.cc (trans_scalar_class_assign): Delay creation of tree
        nodes after early return.
---
 gcc/fortran/trans-expr.cc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index c81051f7162..b477ead6900 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1982,11 +1982,6 @@ trans_scalar_class_assign (stmtblock_t *block, gfc_se 
*lse, gfc_se *rse)
     class_data = gfc_conv_descriptor_data_get (class_data);
   class_data = gfc_evaluate_now (class_data, block);
 
-  zero = build_int_cst (TREE_TYPE (class_data), 0);
-  cond = fold_build2_loc (input_location, NE_EXPR,
-                         logical_type_node,
-                         class_data, zero);
-
   /* Copy the rhs to the lhs.  */
   fcn = gfc_vptr_copy_get (gfc_class_vptr_get (rse_expr));
   fcn = build_fold_indirect_ref_loc (input_location, fcn);
@@ -2000,6 +1995,11 @@ trans_scalar_class_assign (stmtblock_t *block, gfc_se 
*lse, gfc_se *rse)
   if (not_call_expr)
     return true;
 
+  zero = build_int_cst (TREE_TYPE (class_data), 0);
+  cond = fold_build2_loc (input_location, NE_EXPR,
+                         logical_type_node,
+                         class_data, zero);
+
   /* Finalize the class data if needed.  */
   gfc_init_block (&inner_block);
   fcn = gfc_vptr_final_get (gfc_class_vptr_get (rse_expr));
-- 
2.53.0

Reply via email to