1  /* { dg-additional-options "-fdump-tree-omplower" } */
       2  
       3  /* { dg-final { scan-tree-dump-times "omp declare target\[^ \]" 3 "omplower" } }  */
       4  
       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" } }  */
       8  
       9  /* { dg-prune-output "'reverse_offload' clause on 'requires' directive not supported yet" } */
      10  
      11  #pragma omp requires reverse_offload
      12  
      13  extern int add_3 (int);
      14  
      15  static int global_var = 5;
      16  
      17  void
      18  check_offload (int *x, int *y)
      19  {
      20    *x = add_3 (*x);
      21    *y = add_3 (*y);
      22  }
      23  
      24  int
      25  called_in_target1 ()
      26  {
      27    return 42;
      28  }
      29  
      30  int
      31  called_in_target2 ()
      32  {
      33    return -6;
      34  }
      35  
      36  #pragma omp declare target
      37  void
      38  tg_fn (int *x, int *y)
      39  {
      40    int x2 = *x, y2 = *y;
      41    if (x2 != 2 || y2 != 3)
      42      __builtin_abort ();
      43    x2 = x2 + 2 + called_in_target1 ();
      44    y2 = y2 + 7;
      45  
      46    #pragma omp target device(ancestor : 1) map(tofrom: x2)
      47      check_offload(&x2, &y2);
      48  
      49    if (x2 != 2+2+3+42 || y2 != 3 + 7)
      50      __builtin_abort ();
      51    *x = x2, *y = y2;
      52  }
      53  #pragma omp end declare target
      54  
      55  void
      56  my_func (int *x, int *y)
      57  {
      58    if (global_var != 5)
      59      __builtin_abort ();
      60    global_var = 242;
      61    *x = 2*add_3(*x);
      62    *y = 3*add_3(*y);
      63  }
      64  
      65  int
      66  main ()
      67  {
      68    #pragma omp target
      69    {
      70       int x = 2, y = 3;
      71       tg_fn (&x, &y);
      72    }
      73  
      74    #pragma omp target
      75    {
      76       int x = -2, y = -1;
      77       x += called_in_target2 ();
      78       #pragma omp target device ( ancestor:1 ) firstprivate(y) map(tofrom:x)
      79       {
      80         if (x != -2-6 || y != -1)
      81           __builtin_abort ();
      82         my_func (&x, &y);
      83         if (x != 2*(3-2) || y != 3*(3-1))
      84           __builtin_abort ();
      85       }
      86       if (x != 2*(3-2) || y != -1)
      87         __builtin_abort ();
      88    }
      89  
      90    if (global_var != 242)
      91      __builtin_abort ();
      92    return 0;
      93  }