llvm-c166/offload/test/mapping/declare_mapper_target_data.cpp
Abhinav Gaba 1a2691c3d3
[NFC][OpenMP] Add mapper-specific tests exercising pointee section mapping. (#204269)
* Add a few tests for when a mapper does something like `map(s.p[0:10])`
where `p` is a pointer.
* Add a few tests that require propagation of bits like `present/always`
into a mapper.
* Fix a few tests that were expecting `p` to be mapped when the mapper
only said `map(s.p[0:10])`.

The output of a few tests is different from what we expect. They have
been annotated with FIXMEs, and the expected output for when the
follow-up changes in this stack to propagate the map-type-modifier bits
and using attach-style mapping for mappers get merged.

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-28 11:27:03 -07:00

37 lines
661 B
C++

// RUN: %libomptarget-compile-run-and-check-generic
// UNSUPPORTED: intelgpu
#include <cstdio>
#include <cstdlib>
#define NUM 1024
class C {
public:
int *a;
};
#pragma omp declare mapper(id : C s) map(alloc : s.a) map(s.a[0 : NUM])
int main() {
C c;
c.a = (int *)malloc(sizeof(int) * NUM);
for (int i = 0; i < NUM; i++) {
c.a[i] = 1;
}
#pragma omp target data map(mapper(id), tofrom : c)
{
#pragma omp target teams distribute parallel for
for (int i = 0; i < NUM; i++) {
++c.a[i];
}
}
int sum = 0;
for (int i = 0; i < NUM; i++) {
sum += c.a[i];
}
// CHECK: Sum = 2048
printf("Sum = %d\n", sum);
return 0;
}