Jonas Hahnfeld | f7f8697 | 2018-09-04 15:13:23 +0000 | [diff] [blame] | 1 | // 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 | |
| 13 | typedef struct { |
| 14 | int *ptr1; |
| 15 | int *ptr2; |
| 16 | } StructWithPtrs; |
| 17 | |
| 18 | int main(int argc, char *argv[]) { |
Alexey Bataev | 418af6f | 2018-09-28 17:13:11 +0000 | [diff] [blame] | 19 | StructWithPtrs s, s2; |
Jonas Hahnfeld | f7f8697 | 2018-09-04 15:13:23 +0000 | [diff] [blame] | 20 | s.ptr1 = malloc(sizeof(int)); |
| 21 | s.ptr2 = malloc(2 * sizeof(int)); |
Alexey Bataev | 418af6f | 2018-09-28 17:13:11 +0000 | [diff] [blame] | 22 | s2.ptr1 = malloc(sizeof(int)); |
| 23 | s2.ptr2 = malloc(2 * sizeof(int)); |
Jonas Hahnfeld | f7f8697 | 2018-09-04 15:13:23 +0000 | [diff] [blame] | 24 | |
Alexey Bataev | 418af6f | 2018-09-28 17:13:11 +0000 | [diff] [blame] | 25 | #pragma omp target enter data map(to: s2.ptr2[0:1]) |
Jonas Hahnfeld | f7f8697 | 2018-09-04 15:13:23 +0000 | [diff] [blame] | 26 | #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 Bataev | 418af6f | 2018-09-28 17:13:11 +0000 | [diff] [blame] | 32 | #pragma omp target exit data map(from: s2.ptr1[0:1], s2.ptr2[0:1]) |
Jonas Hahnfeld | f7f8697 | 2018-09-04 15:13:23 +0000 | [diff] [blame] | 33 | |
| 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 Bataev | 418af6f | 2018-09-28 17:13:11 +0000 | [diff] [blame] | 43 | free(s2.ptr1); |
| 44 | free(s2.ptr2); |
Jonas Hahnfeld | f7f8697 | 2018-09-04 15:13:23 +0000 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |