Hi! On 2020-12-09T12:06:21+0100, Tobias Burnus <tob...@codesourcery.com> wrote: > On 08.12.20 13:30, Jakub Jelinek wrote: >> On Tue, Dec 08, 2020 at 01:13:07PM +0100, Tobias Burnus wrote: >>> + case EXEC_OMP_SCAN: >>> + /* Flag is only used to checking, hence, it is unset afterwards. */ >>> + if (!code->ext.omp_clauses->if_present) >> Isn't if_present used also for OpenACC? Then can't it with -fopenmp >> -fopenacc allow >> !$acc ... if_present... >> !$omp scan inclusive(...) >> !$add end ... >> ?
Yeah, that re-purposing of 'if_present' made me raise an eyebrow, too. > !$acc ends up in a different ST_OMP_/EXEC_OMP_; additionally, due to the > tight restrictions imposed by 'inscan'/'omp scan' adding something > inbetween is difficult. (It can be added in 'block ... end block' but it > still does not make much sense for 'omp scan' and it still ends up in a > different statement.) I'm confirming that it seems to work (that is, doesn't seem to cause any obvious interference); OK to verify/document that as in the attached "Add 'gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90'"? Regarding my comment "As long as '!$omp scan' inside '!$acc host_data' (generally, all constructs using 'if_present') reliably results in a compile-time error, [...]": do we need a more elaborate testcase for that, like not directly nesting '!$omp scan' inside '!$acc host_data'? .., or, well..., just implement this '!$omp scan' checking differently? ;-) Grüße Thomas ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter
>From ceff1cdbd0fae3884efe9558704644add4ac9257 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge <tho...@codesourcery.com> Date: Wed, 9 Dec 2020 12:33:12 +0100 Subject: [PATCH] Add 'gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90' ... as a "Variant of '../gomp/scan-1.f90', checking 'code->ext.omp_clauses->if_present' implementation detail". gcc/testsuite/ * gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90: New. * gfortran.dg/gomp/scan-1.f90: Refer. gcc/fortran/ * openmp.c (gfc_resolve_omp_do_blocks, gfc_resolve_omp_directive): Refer 'gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90'. --- gcc/fortran/openmp.c | 6 ++- .../goacc-gomp/omp-scan-1-if_present.f90 | 38 +++++++++++++++++++ gcc/testsuite/gfortran.dg/gomp/scan-1.f90 | 2 + 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90 diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index b1f009785e3..8010ce91478 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -6222,7 +6222,8 @@ gfc_resolve_omp_do_blocks (gfc_code *code, gfc_namespace *ns) gfc_error ("With INSCAN at %L, expected loop body with !$OMP SCAN " "between two structured-block-sequences", loc); else - /* Mark as checked; flag will be unset later. */ + /* Mark as checked; flag will be unset later. + (See 'gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90'.) */ c->block->next->next->ext.omp_clauses->if_present = true; } } @@ -7123,7 +7124,8 @@ gfc_resolve_omp_directive (gfc_code *code, gfc_namespace *ns) "except when omp_sync_hint_none is used", &code->loc); break; case EXEC_OMP_SCAN: - /* Flag is only used to checking, hence, it is unset afterwards. */ + /* Flag is only used to checking, hence, it is unset afterwards. + See 'gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90'. */ if (!code->ext.omp_clauses->if_present) gfc_error ("Unexpected !$OMP SCAN at %L outside loop construct with " "%<inscan%> REDUCTION clause", &code->loc); diff --git a/gcc/testsuite/gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90 b/gcc/testsuite/gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90 new file mode 100644 index 00000000000..08b21e0cbf5 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc-gomp/omp-scan-1-if_present.f90 @@ -0,0 +1,38 @@ +! Variant of '../gomp/scan-1.f90', checking 'code->ext.omp_clauses->if_present' implementation detail. + +! As long as '!$omp scan' inside '!$acc host_data' (generally, all constructs +! using 'if_present') reliably results in a compile-time error, we don't have +! to worry about the case where the checking done for an '!$omp scan' might +! inadvertently alter 'if_present' for an outer '!$acc host_data'. + +module m + integer a, b +end module m + +subroutine f1 + use m + !$acc host_data if_present + !$omp scan inclusive (a) ! { dg-error "Unexpected ..OMP SCAN at .1. outside loop construct with 'inscan' REDUCTION clause" } + ! { dg-error "The ..OMP SCAN directive cannot be specified within a ..ACC HOST_DATA region" "" { target *-*-* } .-1 } + !$omp scan exclusive (b) ! { dg-error "Unexpected ..OMP SCAN at .1. outside loop construct with 'inscan' REDUCTION clause" } + ! { dg-error "The ..OMP SCAN directive cannot be specified within a ..ACC HOST_DATA region" "" { target *-*-* } .-1 } + !$acc end host_data +end + +subroutine f9 + use m + implicit none + integer i + !$acc host_data if_present +! The first error (exit) causes two follow-up errors: + !$omp simd reduction (inscan, +: a) ! { dg-error "With INSCAN at .1., expected loop body with ..OMP SCAN between two structured-block-sequences" } + ! { dg-error "The ..OMP SIMD directive cannot be specified within a ..ACC HOST_DATA region" "" { target *-*-* } .-1 } + do i = 1, 64 + if (i == 23) & + exit ! { dg-error "EXIT statement at .1. terminating ..OMP DO loop" } */ + !$omp scan exclusive (a) ! { dg-error "Unexpected ..OMP SCAN at .1. outside loop construct with 'inscan' REDUCTION clause" } + ! { dg-error "The ..OMP SCAN directive cannot be specified within a ..ACC HOST_DATA region" "" { target *-*-* } .-1 } + a = a + 1 + end do + !$acc end host_data +end diff --git a/gcc/testsuite/gfortran.dg/gomp/scan-1.f90 b/gcc/testsuite/gfortran.dg/gomp/scan-1.f90 index 8c879fd98b9..91be4147db1 100644 --- a/gcc/testsuite/gfortran.dg/gomp/scan-1.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/scan-1.f90 @@ -1,3 +1,5 @@ +! See also '../goacc-gomp/omp-scan-1-if_present.f90'. + module m integer a, b end module m -- 2.17.1