diff options
author | Andre Vehreschild <vehre@gcc.gnu.org> | 2025-02-25 14:17:16 +0100 |
---|---|---|
committer | Andre Vehreschild <vehre@gcc.gnu.org> | 2025-02-26 09:26:47 +0100 |
commit | 751b37047b2ad3a358d41ac792487b42430e9901 (patch) | |
tree | 8b1773963c222cfbcfedfa7125c377dc2ceba357 /gcc/fortran/trans-expr.cc | |
parent | ebe7cd9f2833a79877fbc56829c4f37a518a9b1d (diff) | |
download | gcc-751b37047b2ad3a358d41ac792487b42430e9901.zip gcc-751b37047b2ad3a358d41ac792487b42430e9901.tar.gz gcc-751b37047b2ad3a358d41ac792487b42430e9901.tar.bz2 |
Fortran: Remove SAVE_EXPR on lhs in assign [PR108233]
With vectorial shaped datatypes like e.g. complex numbers, fold_convert
inserts a SAVE_EXPR. Using that on the lhs in an assignment prevented
the update of the variable, when in a coarray.
PR fortran/108233
gcc/fortran/ChangeLog:
* trans-expr.cc (gfc_trans_assignment_1): Remove SAVE_EXPR on lhs.
gcc/testsuite/ChangeLog:
* gfortran.dg/coarray/complex_1.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-expr.cc')
-rw-r--r-- | gcc/fortran/trans-expr.cc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 8a3e737..ab55940 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -13017,11 +13017,14 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, else { gfc_conv_expr (&lse, expr1); - if (gfc_option.rtcheck & GFC_RTCHECK_MEM - && !init_flag - && gfc_expr_attr (expr1).allocatable - && expr1->rank - && !expr2->rank) + /* For some expression (e.g. complex numbers) fold_convert uses a + SAVE_EXPR, which is hazardous on the lhs, because the value is + not updated when assigned to. */ + if (TREE_CODE (lse.expr) == SAVE_EXPR) + lse.expr = TREE_OPERAND (lse.expr, 0); + + if (gfc_option.rtcheck & GFC_RTCHECK_MEM && !init_flag + && gfc_expr_attr (expr1).allocatable && expr1->rank && !expr2->rank) { tree cond; const char* msg; |