Files
Tobias Burnus 1c101fcfaa 'omp scan' struct block seq update for OpenMP 5.x
While OpenMP 5.0 required a single structured block before and after the
'omp scan' directive, OpenMP 5.1 changed this to a 'structured block sequence,
denoting 2 or more executable statements in OpenMP 5.1 (whoops!) and zero or
more in OpenMP 5.2. This commit updates C/C++ to accept zero statements (but
till requires the '{' ... '}' for the final-loop-body) and updates Fortran
to accept zero or more than one statements.

If there is no preceeding or succeeding executable statement, a warning is
shown.

gcc/c/ChangeLog:

	* c-parser.cc (c_parser_omp_scan_loop_body): Handle
	zero exec statements before/after 'omp scan'.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_omp_scan_loop_body): Handle
	zero exec statements before/after 'omp scan'.

gcc/fortran/ChangeLog:

	* openmp.cc (gfc_resolve_omp_do_blocks): Handle zero
	or more than one exec statements before/after 'omp scan'.
	* trans-openmp.cc (gfc_trans_omp_do): Likewise.

libgomp/ChangeLog:

	* testsuite/libgomp.c-c++-common/scan-1.c: New test.
	* testsuite/libgomp.c/scan-23.c: New test.
	* testsuite/libgomp.fortran/scan-2.f90: New test.

gcc/testsuite/ChangeLog:

	* g++.dg/gomp/attrs-7.C: Update dg-error/dg-warning.
	* gfortran.dg/gomp/loop-2.f90: Likewise.
	* gfortran.dg/gomp/reduction5.f90: Likewise.
	* gfortran.dg/gomp/reduction6.f90: Likewise.
	* gfortran.dg/gomp/scan-1.f90: Likewise.
	* gfortran.dg/gomp/taskloop-2.f90: Likewise.
	* c-c++-common/gomp/scan-6.c: New test.
	* gfortran.dg/gomp/scan-8.f90: New test.
2023-04-25 16:29:14 +02:00

122 lines
2.4 KiB
C

/* { dg-require-effective-target size32plus } */
/* Same as scan-9.c, instead of using { ... } it simply uses multiple
executable stmt before 'omp scan'. */
extern void abort (void);
int r, a[1024], b[1024], x, y, z;
__attribute__((noipa)) void
foo (int *a, int *b)
{
#pragma omp for reduction (inscan, +:r) lastprivate (conditional: z) firstprivate (x) private (y)
for (int i = 0; i < 1024; i++)
{
y = a[i];
r += y + x + 12;
#pragma omp scan inclusive(r)
b[i] = r;
if ((i & 1) == 0 && i < 937)
z = r;
}
}
__attribute__((noipa)) int
bar (void)
{
int s = 0;
#pragma omp parallel
#pragma omp for reduction (inscan, +:s) firstprivate (x) private (y) lastprivate (z)
for (int i = 0; i < 1024; i++)
{
y = 2 * a[i]; s += y; z = y;
#pragma omp scan inclusive(s)
y = s; b[i] = y + x + 12;
}
return s;
}
__attribute__((noipa)) void
baz (int *a, int *b)
{
#pragma omp parallel for reduction (inscan, +:r) firstprivate (x) lastprivate (x)
for (int i = 0; i < 1024; i++)
{
r += a[i] + x + 12; if (i == 1023) x = 29;
#pragma omp scan inclusive(r)
b[i] = r;
}
}
__attribute__((noipa)) int
qux (void)
{
int s = 0;
#pragma omp parallel for reduction (inscan, +:s) lastprivate (conditional: x, y)
for (int i = 0; i < 1024; i++)
{
s += 2 * a[i]; if ((a[i] & 1) == 1 && i < 825) x = a[i];
#pragma omp scan inclusive(s)
b[i] = s; if ((a[i] & 1) == 0 && i < 829) y = a[i];
}
return s;
}
int
main ()
{
int s = 0;
x = -12;
for (int i = 0; i < 1024; ++i)
{
a[i] = i;
b[i] = -1;
asm ("" : "+g" (i));
}
#pragma omp parallel
foo (a, b);
if (r != 1024 * 1023 / 2 || x != -12 || z != b[936])
abort ();
for (int i = 0; i < 1024; ++i)
{
s += i;
if (b[i] != s)
abort ();
else
b[i] = 25;
}
if (bar () != 1024 * 1023 || x != -12 || z != 2 * 1023)
abort ();
s = 0;
for (int i = 0; i < 1024; ++i)
{
s += 2 * i;
if (b[i] != s)
abort ();
else
b[i] = -1;
}
r = 0;
baz (a, b);
if (r != 1024 * 1023 / 2 || x != 29)
abort ();
s = 0;
for (int i = 0; i < 1024; ++i)
{
s += i;
if (b[i] != s)
abort ();
else
b[i] = -25;
}
if (qux () != 1024 * 1023 || x != 823 || y != 828)
abort ();
s = 0;
for (int i = 0; i < 1024; ++i)
{
s += 2 * i;
if (b[i] != s)
abort ();
}
return 0;
}