xref: /llvm-project/offload/test/offloading/indirect_fp_mapping.c (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compile-generic -fopenmp-version=51
2 // RUN: %libomptarget-run-generic | %fcheck-generic
3 // RUN: %libomptarget-compileopt-generic -fopenmp-version=51
4 // RUN: %libomptarget-run-generic | %fcheck-generic
5 
6 #include <stdio.h>
7 
square(int x)8 int square(int x) { return x * x; }
9 #pragma omp declare target indirect to(square)
10 
11 typedef int (*fp_t)(int);
12 
main()13 int main() {
14   int i = 17, r;
15 
16   fp_t fp = &square;
17   // CHECK: host: &square =
18   printf("host: &square = %p\n", fp);
19 
20 #pragma omp target map(from : fp)
21   fp = &square;
22   // CHECK: device: &square = [[DEV_FP:.*]]
23   printf("device: &square = %p\n", fp);
24 
25   fp_t fp1 = square;
26   fp_t fp2 = 0;
27 #pragma omp target map(from : fp2)
28   fp2 = fp1;
29   // CHECK: device: fp2 = [[DEV_FP]]
30   printf("device: fp2 = %p\n", fp2);
31 
32 #pragma omp target map(from : r)
33   { r = fp1(i); }
34 
35   // CHECK: 17*17 = 289
36   printf("%i*%i = %i\n", i, i, r);
37 }
38