1  /* { dg-do compile } */
       2  /* { dg-additional-options "-fdump-tree-gimple" } */
       3  
       4  int v = 6;
       5  void bar (int);
       6  void bar2 (int, long *, long *);
       7  int baz (void);
       8  #pragma omp declare target to (bar, baz, v)
       9  
      10  void
      11  foo (int a, int b, long c, long d)
      12  {
      13    /* The OpenMP 4.5 spec says that these expressions are evaluated before
      14       target region on combined target teams, so those cases are always
      15       fine.  */
      16    #pragma omp target
      17    bar (0);
      18    #pragma omp target
      19    #pragma omp teams
      20    bar (1);
      21    #pragma omp target teams
      22    bar (2);
      23    #pragma omp target
      24    #pragma omp teams num_teams (4)
      25    bar (3);
      26    #pragma omp target teams num_teams (4)
      27    bar (4);
      28    #pragma omp target
      29    #pragma omp teams thread_limit (7)
      30    bar (5);
      31    #pragma omp target teams thread_limit (7)
      32    bar (6);
      33    #pragma omp target
      34    #pragma omp teams num_teams (4) thread_limit (8)
      35    {
      36      {
      37        bar (7);
      38      }
      39    }
      40    #pragma omp target teams num_teams (4) thread_limit (8)
      41    bar (8);
      42    #pragma omp target
      43    #pragma omp teams num_teams (a) thread_limit (b)
      44    bar (9);
      45    #pragma omp target teams num_teams (a) thread_limit (b)
      46    bar (10);
      47    #pragma omp target
      48    #pragma omp teams num_teams (c + 1) thread_limit (d - 1)
      49    bar (11);
      50    #pragma omp target teams num_teams (c + 1) thread_limit (d - 1)
      51    bar (12);
      52    #pragma omp target map (always, to: c, d)
      53    #pragma omp teams num_teams (c + 1) thread_limit (d - 1)
      54    bar (13);
      55    #pragma omp target data map (to: c, d)
      56    {
      57      #pragma omp target defaultmap (tofrom: scalar)
      58      bar2 (14, &c, &d);
      59      /* This is one of the cases which can't be generally optimized,
      60         the c and d are (or could be) already mapped and whether
      61         their device and original values match is unclear.  */
      62      #pragma omp target map (to: c, d)
      63      #pragma omp teams num_teams (c + 1) thread_limit (d - 1)
      64      bar (15);
      65    }
      66    /* This can't be optimized, there are function calls inside of
      67       target involved.  */
      68    #pragma omp target
      69    #pragma omp teams num_teams (baz () + 1) thread_limit (baz () - 1)
      70    bar (16);
      71    #pragma omp target teams num_teams (baz () + 1) thread_limit (baz () - 1)
      72    bar (17);
      73    /* This one can't be optimized, as v might have different value between
      74       host and target.  */
      75    #pragma omp target
      76    #pragma omp teams num_teams (v + 1) thread_limit (v - 1)
      77    bar (18);
      78  }
      79  
      80  /* { dg-final { scan-tree-dump-times "num_teams\\(-1\\)" 3 "gimple" } } */
      81  /* { dg-final { scan-tree-dump-times "thread_limit\\(-1\\)" 3 "gimple" } } */
      82  /* { dg-final { scan-tree-dump-times "num_teams\\(0\\)" 4 "gimple" } } */
      83  /* { dg-final { scan-tree-dump-times "thread_limit\\(0\\)" 6 "gimple" } } */
      84  /* { dg-final { scan-tree-dump-times "num_teams\\(-2\\)" 2 "gimple" } } */
      85  /* { dg-final { scan-tree-dump-times "thread_limit\\(1\\)" 0 "gimple" } } */