1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -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
foo()9 void foo() {}
10
11 struct S1 {
S1S112 S1(): a(0) {}
S1S113 S1(int v) : a(v) {}
14 int a;
15 typedef int type;
16 };
17
18 template <typename T>
19 class S7 : public T {
20 protected:
21 T a;
S7()22 S7() : a(0) {}
23
24 public:
S7(typename T::type v)25 S7(typename T::type v) : a(v) {
26 #pragma omp task private(a) private(this->a) private(T::a)
27 for (int k = 0; k < a.a; ++k)
28 ++this->a.a;
29 }
operator =(S7 & s)30 S7 &operator=(S7 &s) {
31 #pragma omp task private(a) private(this->a)
32 for (int k = 0; k < s.a.a; ++k)
33 ++s.a.a;
34 return *this;
35 }
36 };
37
38 // CHECK: #pragma omp task private(this->a) private(this->a) private(this->S1::a)
39 // CHECK: #pragma omp task private(this->a) private(this->a) private(T::a)
40 // CHECK: #pragma omp task private(this->a) private(this->a)
41
42 class S8 : public S7<S1> {
S8()43 S8() {}
44
45 public:
S8(int v)46 S8(int v) : S7<S1>(v){
47 #pragma omp task private(a) private(this->a) private(S7<S1>::a)
48 for (int k = 0; k < a.a; ++k)
49 ++this->a.a;
50 }
operator =(S8 & s)51 S8 &operator=(S8 &s) {
52 #pragma omp task private(a) private(this->a)
53 for (int k = 0; k < s.a.a; ++k)
54 ++s.a.a;
55 return *this;
56 }
57 };
58
59 // CHECK: #pragma omp task private(this->a) private(this->a) private(this->S7<S1>::a)
60 // CHECK: #pragma omp task private(this->a) private(this->a)
61
62 template <class T>
63 struct S {
operator TS64 operator T() { return T(); }
65 static T TS;
66 #pragma omp threadprivate(TS)
67 };
68
69 // CHECK: template <class T = int> struct S {
70 // CHECK: static int TS;
71 // CHECK-NEXT: #pragma omp threadprivate(S<int>::TS)
72 // CHECK-NEXT: }
73 // CHECK: template <class T = long> struct S {
74 // CHECK: static long TS;
75 // CHECK-NEXT: #pragma omp threadprivate(S<long>::TS)
76 // CHECK-NEXT: }
77 // CHECK: template <class T> struct S {
78 // CHECK: static T TS;
79 // CHECK-NEXT: #pragma omp threadprivate(S::TS)
80 // CHECK: };
81
82 template <typename T, int C>
tmain(T argc,T * argv)83 T tmain(T argc, T *argv) {
84 T b = argc, c, d, e, f, g;
85 static T a;
86 S<T> s;
87 T arr[argc];
88 #pragma omp task untied depend(in : argc, argv[b:argc], arr[:]) if (task : argc > 0)
89 a = 2;
90 #pragma omp task default(none), private(argc, b) firstprivate(argv) shared(d) if (argc > 0) final(S<T>::TS > 0) priority(argc)
91 foo();
92 #pragma omp task if (C) mergeable priority(C)
93 foo();
94 return 0;
95 }
96
97 // CHECK: template <typename T = int, int C = 5> int tmain(int argc, int *argv) {
98 // CHECK-NEXT: int b = argc, c, d, e, f, g;
99 // CHECK-NEXT: static int a;
100 // CHECK-NEXT: S<int> s;
101 // CHECK-NEXT: int arr[argc];
102 // CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:]) if(task: argc > 0)
103 // CHECK-NEXT: a = 2;
104 // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<int>::TS > 0) priority(argc)
105 // CHECK-NEXT: foo()
106 // CHECK-NEXT: #pragma omp task if(5) mergeable priority(5)
107 // CHECK-NEXT: foo()
108 // CHECK: template <typename T = long, int C = 1> long tmain(long argc, long *argv) {
109 // CHECK-NEXT: long b = argc, c, d, e, f, g;
110 // CHECK-NEXT: static long a;
111 // CHECK-NEXT: S<long> s;
112 // CHECK-NEXT: long arr[argc];
113 // CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:]) if(task: argc > 0)
114 // CHECK-NEXT: a = 2;
115 // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<long>::TS > 0) priority(argc)
116 // CHECK-NEXT: foo()
117 // CHECK-NEXT: #pragma omp task if(1) mergeable priority(1)
118 // CHECK-NEXT: foo()
119 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
120 // CHECK-NEXT: T b = argc, c, d, e, f, g;
121 // CHECK-NEXT: static T a;
122 // CHECK-NEXT: S<T> s;
123 // CHECK-NEXT: T arr[argc];
124 // CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:]) if(task: argc > 0)
125 // CHECK-NEXT: a = 2;
126 // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<T>::TS > 0) priority(argc)
127 // CHECK-NEXT: foo()
128 // CHECK-NEXT: #pragma omp task if(C) mergeable priority(C)
129 // CHECK-NEXT: foo()
130
131 enum Enum {};
132
main(int argc,char ** argv)133 int main(int argc, char **argv) {
134 long x;
135 int b = argc, c, d, e, f, g;
136 static int a;
137 int arr[10];
138 #pragma omp threadprivate(a)
139 Enum ee;
140 // CHECK: Enum ee;
141 #pragma omp task untied mergeable depend(out:argv[:a][1], (arr)[0:]) if(task: argc > 0) priority(f)
142 // CHECK-NEXT: #pragma omp task untied mergeable depend(out : argv[:a][1],(arr)[0:]) if(task: argc > 0) priority(f)
143 a = 2;
144 // CHECK-NEXT: a = 2;
145 #pragma omp task default(none), private(argc, b) firstprivate(argv) if (argc > 0) final(a > 0) depend(inout : a, argv[:argc],arr[:a]) priority(23)
146 // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) if(argc > 0) final(a > 0) depend(inout : a,argv[:argc],arr[:a]) priority(23)
147 foo();
148 // CHECK-NEXT: foo();
149 return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
150 }
151
152 extern template int S<int>::TS;
153 extern template long S<long>::TS;
154
155 #endif
156