blob: 3e7135e284114a7500632aa9bc8f31474cc3c765 [file] [log] [blame]
Jonas Hahnfeldf7f86972018-09-04 15:13:23 +00001// RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu
2// RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu
3// RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu
4// RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu
5
6// Clang 6.0 doesn't use the new map interface, undefined behavior when
7// the compiler emits "old" interface code for structures.
8// UNSUPPORTED: clang-6
9
10#include <stdio.h>
11#include <stdlib.h>
12
13typedef struct {
14 int *ptr1;
15 int *ptr2;
16} StructWithPtrs;
17
18int main(int argc, char *argv[]) {
Alexey Bataev418af6f2018-09-28 17:13:11 +000019 StructWithPtrs s, s2;
Jonas Hahnfeldf7f86972018-09-04 15:13:23 +000020 s.ptr1 = malloc(sizeof(int));
21 s.ptr2 = malloc(2 * sizeof(int));
Alexey Bataev418af6f2018-09-28 17:13:11 +000022 s2.ptr1 = malloc(sizeof(int));
23 s2.ptr2 = malloc(2 * sizeof(int));
Jonas Hahnfeldf7f86972018-09-04 15:13:23 +000024
Alexey Bataev418af6f2018-09-28 17:13:11 +000025#pragma omp target enter data map(to: s2.ptr2[0:1])
Jonas Hahnfeldf7f86972018-09-04 15:13:23 +000026#pragma omp target map(s.ptr1[0:1], s.ptr2[0:2])
27 {
28 s.ptr1[0] = 1;
29 s.ptr2[0] = 2;
30 s.ptr2[1] = 3;
31 }
Alexey Bataev418af6f2018-09-28 17:13:11 +000032#pragma omp target exit data map(from: s2.ptr1[0:1], s2.ptr2[0:1])
Jonas Hahnfeldf7f86972018-09-04 15:13:23 +000033
34 // CHECK: s.ptr1[0] = 1
35 // CHECK: s.ptr2[0] = 2
36 // CHECK: s.ptr2[1] = 3
37 printf("s.ptr1[0] = %d\n", s.ptr1[0]);
38 printf("s.ptr2[0] = %d\n", s.ptr2[0]);
39 printf("s.ptr2[1] = %d\n", s.ptr2[1]);
40
41 free(s.ptr1);
42 free(s.ptr2);
Alexey Bataev418af6f2018-09-28 17:13:11 +000043 free(s2.ptr1);
44 free(s2.ptr2);
Jonas Hahnfeldf7f86972018-09-04 15:13:23 +000045
46 return 0;
47}