https://gcc.gnu.org/g:27c1e4575c0c44a15b6a6eec2d2c91043c0873d6
commit r17-5072-g27c1e4575c0c44a15b6a6eec2d2c91043c0873d6 Author: Jerry DeLisle <[email protected]> Date: Mon Oct 5 18:13:33 2026 -0700 fortran: Mark the STAT= variable of team statements addressable gfc_trans_sync_stat took the address of the STAT= variable with build_fold_addr_expr, which does not mark the variable addressable, so at -O2 the value stored by the library was lost and the variable kept its old value. Use gfc_build_addr_expr instead. gcc/fortran/ChangeLog: * trans-stmt.cc (gfc_trans_sync_stat): Use gfc_build_addr_expr to take the address of the STAT= variable. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/team_stat_1.f90: New test. Diff: --- gcc/fortran/trans-stmt.cc | 2 +- gcc/testsuite/gfortran.dg/coarray/team_stat_1.f90 | 24 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc index b1bd044ff058..19817180acdb 100644 --- a/gcc/fortran/trans-stmt.cc +++ b/gcc/fortran/trans-stmt.cc @@ -836,7 +836,7 @@ gfc_trans_sync_stat (struct sync_stat *sync_stat, gfc_se *se, tree *stat, *stat = build_fold_addr_expr (tstat); } else - *stat = build_fold_addr_expr (argse.expr); + *stat = gfc_build_addr_expr (NULL_TREE, argse.expr); } else *stat = null_pointer_node; diff --git a/gcc/testsuite/gfortran.dg/coarray/team_stat_1.f90 b/gcc/testsuite/gfortran.dg/coarray/team_stat_1.f90 new file mode 100644 index 000000000000..3177a97ba9ff --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/team_stat_1.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! +! The STAT= variable of the team statements must receive the value the +! library stores; without the fix it kept its old value at -O2. + +program team_stat_1 + use iso_fortran_env, only : team_type + implicit none + type(team_type) :: t + integer :: st + + st = 42 + form team (1, t, stat=st) + if (st /= 0) error stop 1 + st = 42 + change team (t, stat=st) + if (st /= 0) error stop 2 + st = 42 + sync team (t, stat=st) + if (st /= 0) error stop 3 + st = 42 + end team (stat=st) + if (st /= 0) error stop 4 +end program team_stat_1
