Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s |
| 2 | |
| 3 | void foo() { |
| 4 | } |
| 5 | |
| 6 | struct S1; // expected-note 2 {{declared here}} |
| 7 | class S2 { |
| 8 | mutable int a; |
| 9 | |
| 10 | public: |
| 11 | S2() : a(0) {} |
| 12 | S2 &operator=(S2 &s2) { return *this; } |
| 13 | }; |
| 14 | class S3 { |
| 15 | int a; |
| 16 | |
| 17 | public: |
| 18 | S3() : a(0) {} |
| 19 | S3 &operator=(S3 &s3) { return *this; } |
| 20 | }; |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 21 | class S4 { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 22 | int a; |
| 23 | S4(); |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 24 | S4 &operator=(const S4 &s4); // expected-note 3 {{implicitly declared private here}} |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 25 | |
| 26 | public: |
| 27 | S4(int v) : a(v) {} |
| 28 | }; |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 29 | class S5 { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 30 | int a; |
| 31 | S5() : a(0) {} |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 32 | S5 &operator=(const S5 &s5) { return *this; } // expected-note 3 {{implicitly declared private here}} |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 33 | |
| 34 | public: |
| 35 | S5(int v) : a(v) {} |
| 36 | }; |
| 37 | |
| 38 | S2 k; |
| 39 | S3 h; |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 40 | S4 l(3); |
| 41 | S5 m(4); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 42 | #pragma omp threadprivate(h, k, l, m) |
| 43 | |
| 44 | template <class T, class C> |
| 45 | T tmain(T argc, C **argv) { |
| 46 | T i; |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 47 | static T TA; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 48 | #pragma omp parallel |
| 49 | #pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}} |
| 50 | #pragma omp parallel |
| 51 | #pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 52 | #pragma omp parallel |
| 53 | #pragma omp single copyprivate() // expected-error {{expected expression}} |
| 54 | #pragma omp parallel |
| 55 | #pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 56 | #pragma omp parallel |
| 57 | #pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 58 | #pragma omp parallel |
| 59 | #pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 60 | #pragma omp parallel |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 61 | #pragma omp single copyprivate(l) // expected-error 2 {{'operator=' is a private member of 'S4'}} |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 62 | #pragma omp parallel |
| 63 | #pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}} |
| 64 | #pragma omp parallel |
| 65 | #pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}} |
| 66 | #pragma omp parallel // expected-note {{implicitly determined as shared}} |
| 67 | #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} |
| 68 | #pragma omp parallel |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 69 | #pragma omp single copyprivate(m) // expected-error 2 {{'operator=' is a private member of 'S5'}} |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 70 | foo(); |
| 71 | #pragma omp parallel private(i) |
| 72 | { |
| 73 | #pragma omp single copyprivate(i) |
| 74 | foo(); |
| 75 | } |
| 76 | #pragma omp parallel shared(i) // expected-note {{defined as shared}} |
| 77 | { |
| 78 | #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} |
| 79 | foo(); |
| 80 | } |
| 81 | #pragma omp parallel private(i) |
| 82 | #pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}} |
| 83 | { |
| 84 | #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} |
| 85 | foo(); |
| 86 | } |
| 87 | #pragma omp parallel private(i) |
| 88 | #pragma omp parallel // expected-note {{implicitly determined as shared}} |
| 89 | { |
| 90 | #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} |
| 91 | foo(); |
| 92 | } |
| 93 | #pragma omp parallel |
| 94 | #pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}} |
| 95 | foo(); |
| 96 | #pragma omp parallel |
| 97 | #pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}} |
| 98 | foo(); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 99 | #pragma omp parallel private(TA) |
| 100 | { |
| 101 | #pragma omp single copyprivate(TA) |
| 102 | TA = 99; |
| 103 | } |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 104 | |
| 105 | return T(); |
| 106 | } |
| 107 | |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame] | 108 | namespace A { |
| 109 | double x; |
| 110 | #pragma omp threadprivate(x) |
| 111 | } |
| 112 | namespace B { |
| 113 | using A::x; |
| 114 | } |
| 115 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 116 | int main(int argc, char **argv) { |
| 117 | int i; |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 118 | static int intA; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 119 | #pragma omp parallel |
| 120 | #pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}} |
| 121 | #pragma omp parallel |
| 122 | #pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 123 | #pragma omp parallel |
| 124 | #pragma omp single copyprivate() // expected-error {{expected expression}} |
| 125 | #pragma omp parallel |
| 126 | #pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 127 | #pragma omp parallel |
| 128 | #pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 129 | #pragma omp parallel |
| 130 | #pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 131 | #pragma omp parallel |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame] | 132 | #pragma omp single copyprivate(l, B::x) // expected-error {{'operator=' is a private member of 'S4'}} |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 133 | #pragma omp parallel |
| 134 | #pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}} |
| 135 | #pragma omp parallel |
| 136 | #pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}} |
| 137 | #pragma omp parallel // expected-note {{implicitly determined as shared}} |
| 138 | #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} |
| 139 | #pragma omp parallel |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 140 | #pragma omp single copyprivate(m) // expected-error {{'operator=' is a private member of 'S5'}} |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 141 | foo(); |
| 142 | #pragma omp parallel private(i) |
| 143 | { |
| 144 | #pragma omp single copyprivate(i) |
| 145 | foo(); |
| 146 | } |
| 147 | #pragma omp parallel shared(i) // expected-note {{defined as shared}} |
| 148 | { |
| 149 | #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} |
| 150 | foo(); |
| 151 | } |
| 152 | #pragma omp parallel private(i) |
| 153 | #pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}} |
| 154 | { |
| 155 | #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} |
| 156 | foo(); |
| 157 | } |
| 158 | #pragma omp parallel private(i) |
| 159 | #pragma omp parallel // expected-note {{implicitly determined as shared}} |
| 160 | { |
| 161 | #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} |
| 162 | foo(); |
| 163 | } |
| 164 | #pragma omp parallel |
| 165 | #pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}} |
| 166 | foo(); |
| 167 | #pragma omp parallel |
| 168 | #pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}} |
| 169 | foo(); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 170 | #pragma omp single copyprivate(i) nowait // expected-error {{the 'copyprivate' clause must not be used with the 'nowait' clause}} expected-note {{'nowait' clause is here}} |
| 171 | foo(); |
| 172 | #pragma omp parallel private(intA) |
| 173 | { |
| 174 | #pragma omp single copyprivate(intA) |
| 175 | intA = 99; |
| 176 | } |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 177 | |
| 178 | return tmain(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<int, char>' requested here}} |
| 179 | } |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 180 | |
| 181 | extern void abort(void); |
| 182 | |
| 183 | void |
| 184 | single(int a, int b) { |
| 185 | #pragma omp single copyprivate(a) copyprivate(b) |
| 186 | { |
| 187 | a = b = 5; |
| 188 | } |
| 189 | |
| 190 | if (a != b) |
| 191 | abort(); |
| 192 | } |
| 193 | |
| 194 | int parallel() { |
| 195 | #pragma omp parallel |
| 196 | single(1, 2); |
| 197 | |
| 198 | return 0; |
| 199 | } |