1// RUN: %libomptarget-compile-run-and-check-generic
2
3// Clang 6.0 doesn't use the new map interface, undefined behavior when
4// the compiler emits "old" interface code for structures.
5// UNSUPPORTED: clang-6
6
7#include <stdio.h>
8#include <stdlib.h>
9
10typedef struct {
11 int *ptr1;
12 int *ptr2;
13} StructWithPtrs;
14
15int main(int argc, char *argv[]) {
16 StructWithPtrs s, s2;
17 s.ptr1 = malloc(size: sizeof(int));
18 s.ptr2 = malloc(size: 2 * sizeof(int));
19 s2.ptr1 = malloc(size: sizeof(int));
20 s2.ptr2 = malloc(size: 2 * sizeof(int));
21
22#pragma omp target enter data map(to : s2.ptr2[0 : 1])
23#pragma omp target map(s.ptr1[0 : 1], s.ptr2[0 : 2])
24 {
25 s.ptr1[0] = 1;
26 s.ptr2[0] = 2;
27 s.ptr2[1] = 3;
28 }
29#pragma omp target exit data map(from : s2.ptr1[0 : 1], s2.ptr2[0 : 1])
30
31 // CHECK: s.ptr1[0] = 1
32 // CHECK: s.ptr2[0] = 2
33 // CHECK: s.ptr2[1] = 3
34 printf(format: "s.ptr1[0] = %d\n", s.ptr1[0]);
35 printf(format: "s.ptr2[0] = %d\n", s.ptr2[0]);
36 printf(format: "s.ptr2[1] = %d\n", s.ptr2[1]);
37
38 free(ptr: s.ptr1);
39 free(ptr: s.ptr2);
40 free(ptr: s2.ptr1);
41 free(ptr: s2.ptr2);
42
43 return 0;
44}
45

source code of offload/test/mapping/pr38704.c