1651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp=libiomp5 -ferror-limit 100 %s
2c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
34fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev#pragma omp threadprivate // expected-error {{expected '(' after 'threadprivate'}}
46af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate( // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
56af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate() // expected-error {{expected identifier}}
6c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(1) // expected-error {{expected unqualified-id}}
7c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevstruct CompleteSt{
8c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev int a;
9c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev};
10c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
11c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevstruct CompleteSt1{
12c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(1) // expected-error {{expected unqualified-id}}
13c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev int a;
146af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev} d; // expected-note {{'d' defined here}}
15c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
166af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataevint a; // expected-note {{'a' defined here}}
17c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
18c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(a)
19c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(u) // expected-error {{use of undeclared identifier 'u'}}
20c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(d, a) // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'a'}}
21c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevint foo() { // expected-note {{declared here}}
22c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  static int l;
236af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate(l)) // expected-warning {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
24c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  return (a);
25c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev}
26c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
27651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate (a) (
28651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// expected-error@-1 {{'#pragma omp threadprivate' must precede all references to variable 'a'}} expected-warning@-1 {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
29651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate (a) [ // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'a'}} expected-warning {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
30651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate (a) { // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'a'}} expected-warning {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
31651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate (a) ) // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'a'}} expected-warning {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
32651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate (a) ] // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'a'}} expected-warning {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
33651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate (a) } // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'a'}} expected-warning {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
344fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev#pragma omp threadprivate a // expected-error {{expected '(' after 'threadprivate'}}
35c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(d // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{'#pragma omp threadprivate' must precede all references to variable 'd'}}
366af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate(d)) // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'd'}} expected-warning {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
37c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevint x, y;
386af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate(x)) // expected-warning {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
39651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate(y)),
40651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// expected-warning@-1 {{extra tokens at the end of '#pragma omp threadprivate' are ignored}}
41651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate(a,d)
42651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// expected-error@-1 {{'#pragma omp threadprivate' must precede all references to variable 'a'}} expected-error@-1 {{'#pragma omp threadprivate' must precede all references to variable 'd'}}
436af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate(d.a) // expected-error {{expected identifier}}
44c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate((float)a) // expected-error {{expected unqualified-id}}
452d67097ad41f4c2fe82ebce3f587e06498f1bd71Richard Smithint foa; // expected-note {{'foa' declared here}}
46c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(faa) // expected-error {{use of undeclared identifier 'faa'; did you mean 'foa'?}}
47c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(foo) // expected-error {{'foo' is not a global variable, static local variable or static data member}}
48c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (int a=2) // expected-error {{expected unqualified-id}}
49c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
50c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevstruct IncompleteSt; // expected-note {{forward declaration of 'IncompleteSt'}}
51c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
52c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevextern IncompleteSt e;
536af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate (e) // expected-error {{threadprivate variable with incomplete type 'IncompleteSt'}}
54c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
556af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataevint &f = a; // expected-note {{'f' defined here}}
564fa7eab771ab8212e1058bd1a91061ff120c8fbbAlexey Bataev#pragma omp threadprivate (f) // expected-error {{arguments of '#pragma omp threadprivate' cannot be of reference type 'int &'}}
57c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
58ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesclass TestClass {
59c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  private:
60c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev    int a; // expected-note {{declared here}}
616af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev    static int b; // expected-note {{'b' declared here}}
62ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    TestClass() : a(0){}
63c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  public:
64ef8225444452a1486bd721f3285301fe84643b00Stephen Hines    TestClass (int aaa) : a(aaa) {}
65c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (b, a) // expected-error {{'a' is not a global variable, static local variable or static data member}}
66c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev} g(10);
67c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (b) // expected-error {{use of undeclared identifier 'b'}}
68ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#pragma omp threadprivate (TestClass::b) // expected-error {{'#pragma omp threadprivate' must appear in the scope of the 'TestClass::b' variable declaration}}
69c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (g)
70c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
71c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevnamespace ns {
72d0dbb7e6d4f05f5d0a5978822476897fe3427787Alexey Bataev  int m;
73c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (m)
74c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev}
75c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (m) // expected-error {{use of undeclared identifier 'm'}}
76d0dbb7e6d4f05f5d0a5978822476897fe3427787Alexey Bataev#pragma omp threadprivate (ns::m) // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'ns::m'}}
77d0dbb7e6d4f05f5d0a5978822476897fe3427787Alexey Bataev#pragma omp threadprivate (ns:m) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}} expected-error {{'#pragma omp threadprivate' must precede all references to variable 'ns::m'}}
78c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
79c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevconst int h = 12;
80c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevconst volatile int i = 10;
81c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (h, i)
82c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
83c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
84c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevtemplate <class T>
85c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevclass TempClass {
86c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  private:
87c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev    T a;
88c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev    TempClass() : a(){}
89c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  public:
90c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev    TempClass (T aaa) : a(aaa) {}
91c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev    static T s;
92c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (s)
93c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev};
94c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (s) // expected-error {{use of undeclared identifier 's'}}
95c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
966af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataevstatic __thread int t; // expected-note {{'t' defined here}}
97c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (t) // expected-error {{variable 't' cannot be threadprivate because it is thread-local}}
98c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
99c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevint o; // expected-note {{candidate found by name lookup is 'o'}}
1006af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate (o)
101c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataevnamespace {
102651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesint o; // expected-note {{candidate found by name lookup is '(anonymous namespace)::o'}}
1036af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate (o)
104651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#pragma omp threadprivate (o) // expected-error {{'#pragma omp threadprivate' must precede all references to variable '(anonymous namespace)::o'}}
105c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev}
106c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate (o) // expected-error {{reference to 'o' is ambiguous}}
1076af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate (::o) // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'o'}}
108c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
1096af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataevint main(int argc, char **argv) { // expected-note {{'argc' defined here}}
110c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
111ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  int x, y = argc; // expected-note 2 {{'y' defined here}}
112c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  static double d1;
113c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  static double d2;
1146af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev  static double d3; // expected-note {{'d3' defined here}}
115ef8225444452a1486bd721f3285301fe84643b00Stephen Hines  static TestClass LocalClass(y); // expected-error {{variable with local storage in initial value of threadprivate variable}}
116ef8225444452a1486bd721f3285301fe84643b00Stephen Hines#pragma omp threadprivate(LocalClass)
117c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
118c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  d.a = a;
119c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  d2++;
120c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  ;
1216af701f29be43e49a25ab098c79940ae4cbb69c7Alexey Bataev#pragma omp threadprivate(argc+y) // expected-error {{expected identifier}}
122c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(argc,y) // expected-error 2 {{arguments of '#pragma omp threadprivate' must have static storage duration}}
123c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(d2) // expected-error {{'#pragma omp threadprivate' must precede all references to variable 'd2'}}
124c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(d1)
125c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  {
126c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  ++a;d2=0;
127c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(d3) // expected-error {{'#pragma omp threadprivate' must appear in the scope of the 'd3' variable declaration}}
128c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  }
129c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(d3)
130c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev
131c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(a) // expected-error {{'#pragma omp threadprivate' must appear in the scope of the 'a' variable declaration}}
132c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev  return (y);
133c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev#pragma omp threadprivate(d) // expected-error {{'#pragma omp threadprivate' must appear in the scope of the 'd' variable declaration}}
134c640058aa7f224a71ce3b1d2601d84e1b57f82d3Alexey Bataev}
135