https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96255
--- Comment #21 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:5e62a23cc3a64fa0312ffa414fcd1aaba18baa02 commit r16-5177-g5e62a23cc3a64fa0312ffa414fcd1aaba18baa02 Author: Jerry DeLisle <[email protected]> Date: Tue Nov 11 10:47:31 2025 -0800 fortran: Implement optional type spec for DO CONCURRENT [PR96255] This patch adds support for the F2008 optional integer type specification in DO CONCURRENT and FORALL headers, allowing constructs like: do concurrent (integer :: i=1:10) The implementation handles type spec matching, creates shadow variables when the type spec differs from any outer scope variable, and converts iterator expressions to match the specified type. Shadow variable implementation: When a type-spec is provided and differs from an outer scope variable, a shadow variable with the specified type is created (with _ prefix). A recursive expression walker substitutes all references to the outer variable with the shadow variable throughout the DO CONCURRENT body, including in array subscripts, substrings, and nested operations. Constraint enforcement: Sets gfc_do_concurrent_flag properly (1 for block context, 2 for mask context) to enable F2008 C1139 enforcement, ensuring only PURE procedures are allowed in DO CONCURRENT constructs. Additional fixes: - Extract apply_typespec_to_iterator() helper to eliminate duplicated shadow variable creation code (~70 lines) - Add NULL pointer checks for shadow variables - Fix iterator counting to handle both EXEC_FORALL and EXEC_DO_CONCURRENT - Skip FORALL obsolescence warning for DO CONCURRENT (F2018) - Suppress many-to-one assignment warning for DO CONCURRENT (reductions are valid, formalized with REDUCE locality-spec in F2023) PR fortran/96255 gcc/fortran/ChangeLog: * gfortran.h (gfc_forall_iterator): Add bool shadow field. * match.cc (apply_typespec_to_iterator): New helper function to consolidate shadow variable creation logic. (match_forall_header): Add type-spec parsing for DO CONCURRENT and FORALL. Create shadow variables when type-spec differs from outer scope. Replace duplicated code with apply_typespec_to_iterator. * resolve.cc (replace_in_expr_recursive): New function to recursively walk expressions and replace symbol references. (replace_in_code_recursive): New function to recursively walk code blocks and replace symbol references. (gfc_replace_forall_variable): New entry point for shadow variable substitution. (gfc_resolve_assign_in_forall): Skip many-to-one assignment warning for DO CONCURRENT. (gfc_count_forall_iterators): Handle both EXEC_FORALL and EXEC_DO_CONCURRENT with assertion. (gfc_resolve_forall): Skip F2018 obsolescence warning for DO CONCURRENT. Fix memory allocation check. Add NULL checks for shadow variables. Implement shadow variable walker. (gfc_resolve_code): Set gfc_do_concurrent_flag for DO CONCURRENT constructs to enable constraint checking. gcc/testsuite/ChangeLog: * gfortran.dg/do_concurrent_typespec_1.f90: New test covering all shadowing scenarios: undeclared variable, same kind shadowing, and different kind shadowing. Co-authored-by: Steve Kargl <[email protected]> Co-authored-by: Jerry DeLisle <[email protected]> Signed-off-by: Christopher Albert <[email protected]>
