aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/target-flex-80.C
blob: f41a1bbed366a08356d4886daf1683a62d728251 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// { dg-additional-options "-std=c++20" }

/* std::span  */

#include <span>

#include "target-flex-common.h"

template<typename It0, typename It1>
bool simple_equal(It0 it0, const It0 end0,
		  It1 it1, const It1 end1) noexcept
{
  for (; it0 != end0; ++it0, ++it1)
    if (it1 == end1 || *it0 != *it1)
      return false;
  return true;
}

template<typename T, std::size_t Size>
bool test(const T (&arr)[Size])
{
  bool ok;
  T out_arr[Size];
  #pragma omp target map(from: ok) map(to: arr[:Size])
    {
      std::span span = {arr, Size};
      bool inner_ok = true;
      {
	VERIFY (!span.empty());
	VERIFY (span.size() == Size);
	auto out_it = out_arr;
	for (auto elem : span)
	  *(out_it++) = elem;
      }
      end:
      ok = inner_ok;
    }
  if (!ok)
    return false;
  VERIFY_NON_TARGET (simple_equal(arr, arr + Size,
				  out_arr, out_arr + Size));
  return true;
}

int main()
{
  int arr[8] = {0, 1, 2, 3, 4, 5, 6, 7};
  return test(arr) ? 0 : 1;
}