1  /* PR middle-end/102972 */
       2  
       3  #ifdef __cplusplus
       4  extern "C" {
       5  #endif
       6  
       7  /* From omp.h  */
       8  extern int omp_get_num_teams (void);
       9  extern void omp_set_num_teams (int);
      10  extern int omp_get_team_size (int);
      11  extern int omp_get_team_num (void);
      12  extern int omp_get_max_teams (void);
      13  extern void omp_set_teams_thread_limit (int);
      14  extern int omp_get_teams_thread_limit (void);
      15  extern int omp_is_initial_device (void);
      16  extern int omp_get_num_threads (void);
      17  
      18  
      19  #ifdef __cplusplus
      20  }
      21  #endif
      22  
      23  
      24  void valid ()
      25  {
      26    #pragma omp teams
      27    {
      28      #pragma omp distribute
      29      for (int i = 0; i < 64; i++)
      30        ;
      31  
      32      int n = omp_get_num_teams ();
      33      if (n >= omp_get_team_num ())
      34        __builtin_abort ();
      35  
      36      #pragma omp parallel for
      37      for (int i = 0; i < 64; i++)
      38        if (!omp_is_initial_device () || omp_get_num_threads () < 0)
      39  	__builtin_abort ();
      40  
      41      #pragma omp loop
      42      for (int i = 0; i < 64; i++)
      43        ;
      44    }
      45  }
      46  
      47  void invalid_nest ()
      48  {
      49    #pragma omp teams
      50    {
      51      #pragma distribute parallel for simd
      52      for (int i = 0; i < 64; i++)
      53        ;
      54  
      55      int n = 0;
      56      n += omp_get_team_size (0);  /* { dg-error "OpenMP runtime API call '\[^\n\r]*omp_get_team_size\[^\n\r]*' strictly nested in a 'teams' region" }  */
      57      n += omp_get_num_teams ();
      58      n += omp_get_team_num ();
      59      omp_set_num_teams (n);  /* { dg-error "OpenMP runtime API call '\[^\n\r]*omp_set_num_teams\[^\n\r]*' strictly nested in a 'teams' region" }  */
      60      n += omp_get_max_teams ();  /* { dg-error "OpenMP runtime API call '\[^\n\r]*omp_get_max_teams\[^\n\r]*' strictly nested in a 'teams' region" }  */
      61      n += omp_get_teams_thread_limit ();  /* { dg-error "OpenMP runtime API call '\[^\n\r]*omp_get_teams_thread_limit\[^\n\r]*' strictly nested in a 'teams' region" }  */
      62      omp_set_teams_thread_limit (n);  /* { dg-error "OpenMP runtime API call '\[^\n\r]*omp_set_teams_thread_limit\[^\n\r]*' strictly nested in a 'teams' region" }  */
      63    }
      64  }