blob: 4adee55e341c440c3622979f5a957c4f4709ff9b [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00003// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s
4
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00005void foo() {
6}
7
8bool foobool(int argc) {
9 return argc;
10}
11
12struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
13extern S1 a;
14class S2 {
15 mutable int a;
16public:
17 S2():a(0) { }
Alexey Bataevdffa93a2015-12-10 08:20:58 +000018 static float S2s; // expected-note {{static data member is predetermined as shared}}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000019};
20const S2 b;
21const S2 ba[5];
22class S3 {
23 int a;
24public:
25 S3():a(0) { }
26};
Alexey Bataev7ff55242014-06-19 09:13:45 +000027const S3 c; // expected-note {{global variable is predetermined as shared}}
28const S3 ca[5]; // expected-note {{global variable is predetermined as shared}}
29extern const int f; // expected-note {{global variable is predetermined as shared}}
Alexey Bataev03b340a2014-10-21 03:16:40 +000030class S4 {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000031 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000032 S4(); // expected-note {{implicitly declared private here}}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000033public:
34 S4(int v):a(v) { }
35};
Alexey Bataev03b340a2014-10-21 03:16:40 +000036class S5 {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000037 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000038 S5():a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000039public:
40 S5(int v):a(v) { }
41};
42
Alexey Bataev758e55e2013-09-06 18:03:48 +000043int threadvar;
44#pragma omp threadprivate(threadvar) // expected-note {{defined as threadprivate or thread local}}
45
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +000046namespace A {
47double x;
48#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
49}
50namespace B {
51using A::x;
52}
53
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000054int main(int argc, char **argv) {
Alexey Bataev7ff55242014-06-19 09:13:45 +000055 const int d = 5; // expected-note {{constant variable is predetermined as shared}}
56 const int da[5] = { 0 }; // expected-note {{constant variable is predetermined as shared}}
Alexey Bataev03b340a2014-10-21 03:16:40 +000057 S4 e(4);
58 S5 g[] = {5, 6};
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000059 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000060 int &j = i;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000061 #pragma omp parallel private // expected-error {{expected '(' after 'private'}}
62 #pragma omp parallel private ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
63 #pragma omp parallel private () // expected-error {{expected expression}}
64 #pragma omp parallel private (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevc5970622016-04-01 08:43:42 +000065 #pragma omp parallel private (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000066 #pragma omp parallel private (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
67 #pragma omp parallel private (argc argv) // expected-error {{expected ',' or ')' in 'private' clause}}
68 #pragma omp parallel private (S1) // expected-error {{'S1' does not refer to a value}}
Alexey Bataev758e55e2013-09-06 18:03:48 +000069 #pragma omp parallel private (a, b, c, d, f) // expected-error {{a private variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be private}}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000070 #pragma omp parallel private (argv[1]) // expected-error {{expected variable name}}
71 #pragma omp parallel private(ba)
Alexey Bataev758e55e2013-09-06 18:03:48 +000072 #pragma omp parallel private(ca) // expected-error {{shared variable cannot be private}}
73 #pragma omp parallel private(da) // expected-error {{shared variable cannot be private}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +000074 #pragma omp parallel private(S2::S2s) // expected-error {{shared variable cannot be private}}
Alexey Bataev03b340a2014-10-21 03:16:40 +000075 #pragma omp parallel private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +000076 #pragma omp parallel private(threadvar, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
Alexey Bataevd5af8e42013-10-01 05:32:34 +000077 #pragma omp parallel shared(i), private(i) // expected-error {{shared variable cannot be private}} expected-note {{defined as shared}}
78 foo();
79 #pragma omp parallel firstprivate(i) private(i) // expected-error {{firstprivate variable cannot be private}} expected-note {{defined as firstprivate}}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000080 foo();
81 #pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +000082 #pragma omp parallel private(j)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000083 foo();
Alexey Bataevd5af8e42013-10-01 05:32:34 +000084 #pragma omp parallel firstprivate(i)
85 for (int k = 0; k < 10; ++k) {
86 #pragma omp parallel private(i)
87 foo();
88 }
Kelvin Li4eea8c62015-09-15 18:56:58 +000089 static int m;
90 #pragma omp parallel private(m) // OK
91 foo();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000092
93 return 0;
94}