150
|
1 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -DGNU
|
|
2 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DGNU -std=c++98
|
|
3 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -std=c11 -DC11 -D__thread=_Thread_local
|
|
4 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++98
|
|
5 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DCXX11 -D__thread=thread_local -std=c++11 -Wno-deprecated
|
|
6 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++11 -Wno-deprecated
|
|
7 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic %s -std=c99 -D__thread=_Thread_local -DC99
|
|
8
|
|
9 __thread int t1; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
10 __thread extern int t2; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
11 __thread static int t3; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
12 #ifdef GNU
|
|
13 // expected-warning@-3 {{'__thread' before 'extern'}}
|
|
14 // expected-warning@-3 {{'__thread' before 'static'}}
|
|
15 #endif
|
|
16
|
252
|
17 __private_extern__ __thread int t4; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
150
|
18 struct t5 { __thread int x; }; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
19 #ifdef __cplusplus
|
|
20 // expected-error-re@-2 {{'{{__thread|_Thread_local|thread_local}}' is only allowed on variable declarations}}
|
|
21 #else
|
|
22 // FIXME: The 'is only allowed on variable declarations' diagnostic is better here.
|
|
23 // expected-error@-5 {{type name does not allow storage class to be specified}}
|
|
24 #endif
|
|
25
|
236
|
26 __thread int t6(void); // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
150
|
27 #if defined(GNU)
|
|
28 // expected-error@-2 {{'__thread' is only allowed on variable declarations}}
|
|
29 #elif defined(C11) || defined(C99)
|
|
30 // expected-error@-4 {{'_Thread_local' is only allowed on variable declarations}}
|
|
31 #else
|
|
32 // expected-error@-6 {{'thread_local' is only allowed on variable declarations}}
|
|
33 #endif
|
|
34
|
|
35 int f(__thread int t7) { // expected-error {{' is only allowed on variable declarations}} \
|
|
36 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
37 __thread int t8; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
38 #if defined(GNU)
|
|
39 // expected-error@-2 {{'__thread' variables must have global storage}}
|
|
40 #elif defined(C11) || defined(C99)
|
|
41 // expected-error@-4 {{'_Thread_local' variables must have global storage}}
|
|
42 #endif
|
|
43 extern __thread int t9; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
44 static __thread int t10; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
252
|
45 __private_extern__ __thread int t11; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
150
|
46 #if __cplusplus < 201103L
|
|
47 __thread auto int t12a; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local}}' declaration specifier}} \
|
|
48 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
49 auto __thread int t12b; // expected-error {{cannot combine with previous 'auto' declaration specifier}} \
|
|
50 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
51 #elif !defined(CXX11)
|
|
52 __thread auto t12a = 0; // expected-error {{'_Thread_local' variables must have global storage}} \
|
|
53 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
54 auto __thread t12b = 0; // expected-error {{'_Thread_local' variables must have global storage}} \
|
|
55 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
56 #endif
|
|
57 __thread register int t13a; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \
|
|
58 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
59 register __thread int t13b; // expected-error {{cannot combine with previous 'register' declaration specifier}} \
|
|
60 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
61 }
|
|
62
|
|
63 __thread typedef int t14; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \
|
|
64 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
65 __thread int t15; // expected-note {{previous definition is here}} \
|
|
66 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
67 extern int t15; // expected-error {{non-thread-local declaration of 't15' follows thread-local declaration}}
|
|
68 extern int t16; // expected-note {{previous declaration is here}}
|
|
69 __thread int t16; // expected-error {{thread-local declaration of 't16' follows non-thread-local declaration}} \
|
|
70 // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
71
|
|
72 #ifdef CXX11
|
|
73 extern thread_local int t17; // expected-note {{previous declaration is here}}
|
|
74 _Thread_local int t17; // expected-error {{thread-local declaration of 't17' with static initialization follows declaration with dynamic initialization}} \
|
|
75 // expected-warning {{'_Thread_local' is a C11 extension}}
|
|
76 extern _Thread_local int t18; // expected-note {{previous declaration is here}} \
|
|
77 // expected-warning {{'_Thread_local' is a C11 extension}}
|
|
78 thread_local int t18; // expected-error {{thread-local declaration of 't18' with dynamic initialization follows declaration with static initialization}}
|
|
79 #endif
|
|
80
|
|
81 // PR13720
|
|
82 __thread int thread_int; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
83 int *thread_int_ptr = &thread_int;
|
|
84 #ifndef __cplusplus
|
|
85 // expected-error@-2 {{initializer element is not a compile-time constant}}
|
|
86 #endif
|
236
|
87 void g(void) {
|
150
|
88 int *p = &thread_int; // This is perfectly fine, though.
|
|
89 }
|
|
90 #if __cplusplus >= 201103L
|
|
91 constexpr int *thread_int_ptr_2 = &thread_int; // expected-error {{must be initialized by a constant expression}}
|
|
92 #endif
|
|
93
|
236
|
94 int non_const(void);
|
150
|
95 __thread int non_const_init = non_const(); // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
96 #if !defined(__cplusplus)
|
|
97 // expected-error@-2 {{initializer element is not a compile-time constant}}
|
|
98 #elif !defined(CXX11)
|
|
99 // expected-error@-4 {{initializer for thread-local variable must be a constant expression}}
|
|
100 #if __cplusplus >= 201103L
|
|
101 // expected-note@-6 {{use 'thread_local' to allow this}}
|
|
102 #endif
|
|
103 #endif
|
|
104
|
|
105 #ifdef __cplusplus
|
|
106 struct S {
|
|
107 ~S();
|
|
108 };
|
|
109 __thread S s; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
110 #if !defined(CXX11)
|
|
111 // expected-error@-2 {{type of thread-local variable has non-trivial destruction}}
|
|
112 #if __cplusplus >= 201103L
|
|
113 // expected-note@-4 {{use 'thread_local' to allow this}}
|
|
114 #endif
|
|
115 #endif
|
|
116 #endif
|
|
117
|
|
118 #ifdef __cplusplus
|
|
119 struct HasCtor {
|
|
120 HasCtor();
|
|
121 };
|
|
122 __thread HasCtor var_with_ctor; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|
|
123 #if !defined(CXX11)
|
|
124 // expected-error@-2 {{initializer for thread-local variable must be a constant expression}}
|
|
125 #if __cplusplus >= 201103L
|
|
126 // expected-note@-4 {{use 'thread_local' to allow this}}
|
|
127 #endif
|
|
128 #endif
|
|
129 #endif
|
|
130
|
|
131 __thread int aggregate[10] = {0}; // thread-local-warning {{'_Thread_local' is a C11 extension}}
|