Lower zeroing array assignment to memset for allocatable arrays.
[official-gcc.git] / gcc / testsuite / c-c++-common / gomp / reverse-offload-1.c
blobddc3c2c6be1e7af64b327ca8c647d1ec9f6c7290
1 /* { dg-additional-options "-fdump-tree-omplower" } */
3 /* { dg-final { scan-tree-dump-times "omp declare target\[^ \]" 3 "omplower" } } */
5 /* { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare target\\)\\)\[\n\r\]*int called_in_target1" 1 "omplower" } } */
6 /* { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare target\\)\\)\[\n\r\]*int called_in_target2" 1 "omplower" } } */
7 /* { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare target, omp declare target block\\)\\)\[\n\r\]*void tg_fn" 1 "omplower" } } */
9 #pragma omp requires reverse_offload
11 extern int add_3 (int);
13 static int global_var = 5;
15 void
16 check_offload (int *x, int *y)
18 *x = add_3 (*x);
19 *y = add_3 (*y);
22 int
23 called_in_target1 ()
25 return 42;
28 int
29 called_in_target2 ()
31 return -6;
34 #pragma omp declare target
35 void
36 tg_fn (int *x, int *y)
38 int x2 = *x, y2 = *y;
39 if (x2 != 2 || y2 != 3)
40 __builtin_abort ();
41 x2 = x2 + 2 + called_in_target1 ();
42 y2 = y2 + 7;
44 #pragma omp target device(ancestor : 1) map(tofrom: x2)
45 check_offload(&x2, &y2);
47 if (x2 != 2+2+3+42 || y2 != 3 + 7)
48 __builtin_abort ();
49 *x = x2, *y = y2;
51 #pragma omp end declare target
53 void
54 my_func (int *x, int *y)
56 if (global_var != 5)
57 __builtin_abort ();
58 global_var = 242;
59 *x = 2*add_3(*x);
60 *y = 3*add_3(*y);
63 int
64 main ()
66 #pragma omp target
68 int x = 2, y = 3;
69 tg_fn (&x, &y);
72 #pragma omp target
74 int x = -2, y = -1;
75 x += called_in_target2 ();
76 #pragma omp target device ( ancestor:1 ) firstprivate(y) map(tofrom:x)
78 if (x != -2-6 || y != -1)
79 __builtin_abort ();
80 my_func (&x, &y);
81 if (x != 2*(3-2) || y != 3*(3-1))
82 __builtin_abort ();
84 if (x != 2*(3-2) || y != -1)
85 __builtin_abort ();
88 if (global_var != 242)
89 __builtin_abort ();
90 return 0;