https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94672
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Further examples, one for which should be rejected: subroutine s1 (array) real, optional :: array(:) !$omp parallel default(none) ! { dg-error "" } if (.not.present (array)) stop 1 ! { dg-error "" } !$omp end parallel end subroutine subroutine s2 (arg) real, optional :: arg !$omp parallel default(none) ! { dg-error "" } if (.not.present (arg)) stop 1 ! { dg-error "" } !$omp end parallel end subroutine subroutine s3 (arg) real, value, optional :: arg !$omp parallel default(none) ! { dg-error "" } if (.not.present (arg)) stop 1 ! { dg-error "" } !$omp end parallel end subroutine and one that should be accepted: subroutine s1 (array) real, optional :: array(:) !$omp parallel default(none) firstprivate (array) if (present (array)) array(:) = 3 !$omp end parallel end subroutine subroutine s2 (array) real, optional :: array(:) !$omp parallel default(none) shared (array) !$omp master if (present (array)) array(:) = 3 !$omp end master !$omp end parallel end subroutine subroutine s3 (array) real, optional :: array(:) !$omp parallel default(none) private (array) if (present (array)) array(:) = 3 !$omp end parallel end subroutine subroutine s4 (arg) real, optional :: arg !$omp parallel default(none) firstprivate (arg) if (present (arg)) arg = 3 !$omp end parallel end subroutine subroutine s5 (arg) real, optional :: arg !$omp parallel default(none) shared (arg) !$omp master if (present (arg)) arg = 3 !$omp end master !$omp end parallel end subroutine subroutine s6 (arg) real, optional :: arg !$omp parallel default(none) private (arg) if (present (arg)) arg = 3 !$omp end parallel end subroutine subroutine s7 (arg) real, value, optional :: arg !$omp parallel default(none) firstprivate (arg) if (present (arg)) arg = 3 !$omp end parallel end subroutine subroutine s8 (arg) real, value, optional :: arg !$omp parallel default(none) shared (arg) !$omp master if (present (arg)) arg = 3 !$omp end master !$omp end parallel end subroutine subroutine s9 (arg) real, value, optional :: arg !$omp parallel default(none) private (arg) if (present (arg)) arg = 3 !$omp end parallel end subroutine etc. Note, even just adding the artificial firstprivate clause is not enough, the data sharing on the OPTIONAL parameters doesn't work as the standard says so. E.g. for private clause on OPTIONAL scalar without VALUE, we set the privatized arg to &arg.1 and then compare that in the present check against NULL (which it always is). The spec says: "If a list item that appears in a directive or clause is an optional dummy argument that is not present, the directive or clause for that list item is ignored. If the variable referenced inside a construct is an optional dummy argument that is not present, any explicitly determined, implicitly determined, or predetermined data-sharing and data-mapping attribute rules for that variable are ignored. Otherwise, if the variable is an optional dummy argument that is present, it is present inside the construct."