gcc/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
Richard Biener d42088e453 Avoid -latomic for amdgcn offloading
libatomic isn't built for amdgcn but reduction-16.c adds it
via -foffload=-latomic when offloading for nvptx is enabled.
The following avoids linker errors when offloading to amdgcn is enabled
as well.

2021-04-21  Richard Biener  <rguenther@suse.de>

libgomp/
	* testsuite/libgomp.c-c++-common/reduction-16.c: Use -latomic
	only on nvptx-none.
2021-04-22 08:29:11 +02:00

55 lines
1.1 KiB
C

/* { dg-do run } */
/* { dg-additional-options "-foffload=nvptx-none=-latomic" { target offload_target_nvptx } } */
#include <stdlib.h>
#define N 512
#define GENERATE_TEST(T) \
int test_##T (void) \
{ \
T a[N], res = 0; \
\
for (int i = 0; i < N; ++i) \
a[i] = i & 1; \
\
_Pragma("omp target teams distribute reduction(||:res) defaultmap(tofrom:scalar)") \
for (int i = 0; i < N; ++i) \
res = res || a[i]; \
\
/* res should be non-zero. */\
if (!res) \
return 1; \
\
_Pragma("omp target teams distribute reduction(&&:res) defaultmap(tofrom:scalar)") \
for (int i = 0; i < N; ++i) \
res = res && a[i]; \
\
/* res should be zero. */ \
return res; \
}
GENERATE_TEST(char)
GENERATE_TEST(short)
GENERATE_TEST(int)
GENERATE_TEST(long)
#ifdef __SIZEOF_INT128__
GENERATE_TEST(__int128)
#endif
int main(void)
{
if (test_char ())
abort ();
if (test_short ())
abort ();
if (test_int ())
abort ();
if (test_long ())
abort ();
#ifdef __SIZEOF_INT128__
if (test___int128 ())
abort ();
#endif
}