Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ast-print %s | FileCheck %s
      2 // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -emit-pch -o %t %s
      3 // RUN: %clang_cc1 -fopenmp=libiomp5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
      4 // expected-no-diagnostics
      5 
      6 #ifndef HEADER
      7 #define HEADER
      8 
      9 void foo() {}
     10 
     11 template <class T>
     12 struct S {
     13   operator T() { return T(); }
     14   static T TS;
     15 #pragma omp threadprivate(TS)
     16 };
     17 
     18 // CHECK:      template <class T = int> struct S {
     19 // CHECK:        static int TS;
     20 // CHECK-NEXT:   #pragma omp threadprivate(S<int>::TS)
     21 // CHECK-NEXT: }
     22 // CHECK:      template <class T = long> struct S {
     23 // CHECK:        static long TS;
     24 // CHECK-NEXT:   #pragma omp threadprivate(S<long>::TS)
     25 // CHECK-NEXT: }
     26 // CHECK:      template <class T> struct S {
     27 // CHECK:        static T TS;
     28 // CHECK-NEXT:   #pragma omp threadprivate(S::TS)
     29 // CHECK:      };
     30 
     31 template <typename T, int C>
     32 T tmain(T argc, T *argv) {
     33   T b = argc, c, d, e, f, g;
     34   static T a;
     35   S<T> s;
     36 #pragma omp parallel sections
     37   {
     38     a = 2;
     39   }
     40 #pragma omp parallel sections default(none), private(argc, b) firstprivate(argv) shared(d) if (argc > 0) num_threads(C) copyin(S < T > ::TS) proc_bind(master) reduction(+ : c) reduction(max : e)
     41   {
     42     foo();
     43   }
     44 #pragma omp parallel sections if (C) num_threads(s) proc_bind(close) reduction(^ : e, f) reduction(&& : g) lastprivate(b, c)
     45   {
     46     foo();
     47 #pragma omp section
     48     foo();
     49   }
     50   return 0;
     51 }
     52 
     53 // CHECK: template <typename T = int, int C = 5> int tmain(int argc, int *argv) {
     54 // CHECK-NEXT: int b = argc, c, d, e, f, g;
     55 // CHECK-NEXT: static int a;
     56 // CHECK-NEXT: S<int> s;
     57 // CHECK-NEXT: #pragma omp parallel sections
     58 // CHECK-NEXT: {
     59 // CHECK-NEXT: a = 2;
     60 // CHECK-NEXT: }
     61 // CHECK-NEXT: #pragma omp parallel sections default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) num_threads(5) copyin(S<int>::TS) proc_bind(master) reduction(+: c) reduction(max: e)
     62 // CHECK-NEXT: {
     63 // CHECK-NEXT: foo();
     64 // CHECK-NEXT: }
     65 // CHECK-NEXT: #pragma omp parallel sections if(5) num_threads(s) proc_bind(close) reduction(^: e,f) reduction(&&: g) lastprivate(b,c)
     66 // CHECK-NEXT: {
     67 // CHECK-NEXT: foo();
     68 // CHECK-NEXT: #pragma omp section
     69 // CHECK-NEXT: foo();
     70 // CHECK-NEXT: }
     71 // CHECK: template <typename T = long, int C = 1> long tmain(long argc, long *argv) {
     72 // CHECK-NEXT: long b = argc, c, d, e, f, g;
     73 // CHECK-NEXT: static long a;
     74 // CHECK-NEXT: S<long> s;
     75 // CHECK-NEXT: #pragma omp parallel sections
     76 // CHECK-NEXT: {
     77 // CHECK-NEXT: a = 2;
     78 // CHECK-NEXT: }
     79 // CHECK-NEXT: #pragma omp parallel sections default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) num_threads(1) copyin(S<long>::TS) proc_bind(master) reduction(+: c) reduction(max: e)
     80 // CHECK-NEXT: {
     81 // CHECK-NEXT: foo();
     82 // CHECK-NEXT: }
     83 // CHECK-NEXT: #pragma omp parallel sections if(1) num_threads(s) proc_bind(close) reduction(^: e,f) reduction(&&: g) lastprivate(b,c)
     84 // CHECK-NEXT: {
     85 // CHECK-NEXT: foo();
     86 // CHECK-NEXT: #pragma omp section
     87 // CHECK-NEXT: foo();
     88 // CHECK-NEXT: }
     89 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
     90 // CHECK-NEXT: T b = argc, c, d, e, f, g;
     91 // CHECK-NEXT: static T a;
     92 // CHECK-NEXT: S<T> s;
     93 // CHECK-NEXT: #pragma omp parallel sections
     94 // CHECK-NEXT: {
     95 // CHECK-NEXT: a = 2;
     96 // CHECK-NEXT: }
     97 // CHECK-NEXT: #pragma omp parallel sections default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) num_threads(C) copyin(S<T>::TS) proc_bind(master) reduction(+: c) reduction(max: e)
     98 // CHECK-NEXT: {
     99 // CHECK-NEXT: foo();
    100 // CHECK-NEXT: }
    101 // CHECK-NEXT: #pragma omp parallel sections if(C) num_threads(s) proc_bind(close) reduction(^: e,f) reduction(&&: g) lastprivate(b,c)
    102 // CHECK-NEXT: {
    103 // CHECK-NEXT: foo();
    104 // CHECK-NEXT: #pragma omp section
    105 // CHECK-NEXT: foo();
    106 // CHECK-NEXT: }
    107 
    108 enum Enum {};
    109 
    110 int main(int argc, char **argv) {
    111   long x;
    112   int b = argc, c, d, e, f, g;
    113   static int a;
    114 #pragma omp threadprivate(a)
    115   Enum ee;
    116 // CHECK: Enum ee;
    117 #pragma omp parallel sections
    118   // CHECK-NEXT: #pragma omp parallel sections
    119   {
    120     a = 2;
    121   }
    122 // CHECK-NEXT: {
    123 // CHECK-NEXT: a = 2;
    124 // CHECK-NEXT: }
    125 #pragma omp parallel sections default(none), private(argc, b) firstprivate(argv) if (argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| : c, d) reduction(* : e) lastprivate(argv)
    126   // CHECK-NEXT: #pragma omp parallel sections default(none) private(argc,b) firstprivate(argv) if(argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(|: c,d) reduction(*: e) lastprivate(argv)
    127   {
    128     foo();
    129 #pragma omp section
    130     foo();
    131 #pragma omp section
    132     foo();
    133   }
    134   // CHECK-NEXT: {
    135   // CHECK-NEXT: foo();
    136   // CHECK-NEXT: #pragma omp section
    137   // CHECK-NEXT: foo();
    138   // CHECK-NEXT: #pragma omp section
    139   // CHECK-NEXT: foo();
    140   // CHECK-NEXT: }
    141   return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
    142 }
    143 
    144 #endif
    145