fortran: Mark the STAT= variable of team statements addressable
Fixes a Fortran compiler bug where STAT= variable values could be lost at optimization levels.
This commit corrects a bug in the Fortran compiler where the STAT= variable in TEAM statements was not being correctly marked as addressable. This led to optimization passes (like -O2) incorrectly optimizing away writes to the variable, causing its value to be lost. The fix uses gfc_build_addr_expr instead of build_fold_addr_expr to ensure the variable’s address is properly handled.
In Details
Changes gfc_trans_sync_stat to use gfc_build_addr_expr instead of build_fold_addr_expr when taking the address of the STAT= variable in TEAM statements. This ensures the variable is marked addressable, preventing a bug where its value could be lost at higher optimization levels due to incorrect aliasing assumptions.
- TEAM statement
- A Fortran construct used in coarray programming to create and manage teams of images (parallel processes). The
STAT=variable is used to report the status of the team operation. - addressable
- In compiler optimization, a variable is considered 'addressable' if its memory location can be taken, meaning it's guaranteed to exist and be accessible. If a variable is not marked addressable, the compiler might assume it's not being modified through pointers or other indirect means, potentially leading to incorrect optimizations.
- build_fold_addr_expr
- A GCC internal function used to create an expression representing the address of a variable or memory location. The original implementation did not adequately mark the resulting expression as addressable.
- gfc_build_addr_expr
- A GCC internal function, specific to the Fortran front-end, used to create an expression for a variable's address. This function correctly marks the variable as addressable, resolving issues with optimization passes.