https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118937
Bug ID: 118937 Summary: DO CONCURRENT: Add a warning if 'SHARED' (or LOCAL(_INIT)) is not specified but multiple loop iterations modify a variable Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org Target Milestone: --- EXPECTED: Add a WARNING (-Wsurprising?) for the following. In my opinion, the following code is invalid - in the sense that the code expects that all of 'A' is defined at the end of the loop/subroutine. However, as multiple loop iterations (namely: all) modify the same variable (here: A) and no locality has been specified, A is undefined at the end of the loop. On the other hand, this pattern is very common and could not be implemented in Fortran 2008 (= added 'do concurrent') at all, as 'shared' is new in 2018. subroutine init(A) implicit none integer, intent(out) :: A(:) integer :: i do concurrent (i=1:size(A)) ! shared(A) A(i) = i end do ! without shared, A is undefined end I think we should detect 'var_without_locality = …' and possibly also other variable definition contexts (e.g. intent(out) to pure function) where this code is executed unconditionally. Namely, the following would be okay: do concurrent (i=1:size(A)) if (i == 1) & A(i) = i end do as it only modifies the variable in one loop. Specification has (here 2023; 2008 looks similar): " 11.1.7 DO construct > … > 11.1.7.5 Additional semantics for DO CONCURRENT constructs > … > If a variable has unspecified locality, if it is referenced in an iteration > it shall either be previously defined during that iteration, or shall not be > defined or become undefined during any other iteration; if it is defined or > becomes undefined by more than one iteration it becomes undefined when the > loop terminates