annotate clang/test/Sema/thread-specifier.c @ 207:2e18cbf3894f

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