On Wed, 26 Oct 2022 12:39:39 +0200 Tobias Burnus wrote: > The ICE seems to be because gcc/fortran/trans-openmp.cc's > gfc_split_omp_clauses mishandles this as the dump shows the following: > > #pragma omp target firstprivate(a) map(tofrom:a) > #pragma omp parallel firstprivate(a) > > * * * > > In contrast, for the C testcase: > > void foo(int x) { > #pragma omp target parallel for simd map(x) firstprivate(x) > for (int k = 0; k < 1; ++k) > x = 1; > } > > the dump is as follows, which seems to be sensible: > > #pragma omp target map(tofrom:x) > #pragma omp parallel firstprivate(x) > #pragma omp for nowait > #pragma omp simd First, here's a patch to address this bit... This patch fixes a case where a combined directive (e.g. "!$omp target parallel ...") contains both a map and a firstprivate clause for the same variable. When the combined directive is split into two nested directives, the outer "target" gets the "map" clause, and the inner "parallel" gets the "firstprivate" clause, like so: !$omp target parallel map(x) firstprivate(x) --> !$omp target map(x) !$omp parallel firstprivate(x) ... When there is no map of the same variable, the firstprivate is distributed to both directives, e.g. for 'y' in: !$omp target parallel map(x) firstprivate(y) --> !$omp target map(x) firstprivate(y) !$omp parallel firstprivate(y) ... This is not a recent regression, but appears to fix a long-standing ICE. (The included testcase is based on one by Tobias.) Tested with offloading to NVPTX, alongside previously-posted patches (in review or approved but waiting for other patches), i.e.: OpenMP/OpenACC: Rework clause expansion and nested struct handling OpenMP/OpenACC: Refine condition for when map clause expansion happens OpenMP: Pointers and member mappings and the patch following. OK? 2022-12-06 Julian Brown gcc/fortran/ * trans-openmp.cc (gfc_add_firstprivate_if_unmapped): New function. (gfc_split_omp_clauses): Call above. libgomp/ * testsuite/libgomp.fortran/combined-directive-splitting-1.f90: New test.