blob: 28c81496390bc2af542b9f2c93b0e3a5dcf11de0 [file] [log] [blame]
Chris Lattner289ab7b2006-11-08 06:54:53 +00001//===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===//
Chris Lattnerb9093cd2006-08-04 04:39:53 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerb9093cd2006-08-04 04:39:53 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner289ab7b2006-11-08 06:54:53 +000010// This file implements semantic analysis for declaration specifiers.
Chris Lattnerb9093cd2006-08-04 04:39:53 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner288e86ff12006-11-11 23:03:42 +000014#include "clang/Parse/DeclSpec.h"
Chris Lattner60f36222009-01-29 05:15:15 +000015#include "clang/Parse/ParseDiagnostic.h"
Chris Lattnerda48a8e2006-08-04 05:25:55 +000016#include "clang/Basic/LangOptions.h"
Chris Lattner1ce41ed2009-01-20 19:11:22 +000017#include "llvm/ADT/STLExtras.h"
Chris Lattnerb9093cd2006-08-04 04:39:53 +000018using namespace clang;
19
Chris Lattner3b0f3ef2008-11-22 08:32:36 +000020
21static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc,
22 SourceManager &SrcMgr, unsigned DiagID) {
23 return D.Report(FullSourceLoc(Loc, SrcMgr), DiagID);
24}
25
26
Chris Lattner1ce41ed2009-01-20 19:11:22 +000027/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
28/// "TheDeclarator" is the declarator that this will be added to.
29DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic,
Douglas Gregor94349fd2009-02-18 07:07:28 +000030 SourceLocation EllipsisLoc,
Chris Lattner1ce41ed2009-01-20 19:11:22 +000031 ParamInfo *ArgInfo,
32 unsigned NumArgs,
33 unsigned TypeQuals,
34 SourceLocation Loc,
35 Declarator &TheDeclarator) {
36 DeclaratorChunk I;
37 I.Kind = Function;
38 I.Loc = Loc;
39 I.Fun.hasPrototype = hasProto;
40 I.Fun.isVariadic = isVariadic;
Douglas Gregor94349fd2009-02-18 07:07:28 +000041 I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding();
Chris Lattner1ce41ed2009-01-20 19:11:22 +000042 I.Fun.DeleteArgInfo = false;
43 I.Fun.TypeQuals = TypeQuals;
44 I.Fun.NumArgs = NumArgs;
45 I.Fun.ArgInfo = 0;
46
47 // new[] an argument array if needed.
48 if (NumArgs) {
49 // If the 'InlineParams' in Declarator is unused and big enough, put our
50 // parameter list there (in an effort to avoid new/delete traffic). If it
51 // is already used (consider a function returning a function pointer) or too
52 // small (function taking too many arguments), go to the heap.
53 if (!TheDeclarator.InlineParamsUsed &&
54 NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
55 I.Fun.ArgInfo = TheDeclarator.InlineParams;
56 I.Fun.DeleteArgInfo = false;
57 TheDeclarator.InlineParamsUsed = true;
58 } else {
59 I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs];
60 I.Fun.DeleteArgInfo = true;
61 }
62 memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
63 }
64 return I;
65}
Chris Lattner3b0f3ef2008-11-22 08:32:36 +000066
Chris Lattnerb9093cd2006-08-04 04:39:53 +000067/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
68///
69unsigned DeclSpec::getParsedSpecifiers() const {
70 unsigned Res = 0;
Chris Lattnerf63f89a2006-08-05 03:28:50 +000071 if (StorageClassSpec != SCS_unspecified ||
72 SCS_thread_specified)
Chris Lattnerb9093cd2006-08-04 04:39:53 +000073 Res |= PQ_StorageClassSpecifier;
Mike Stump65643c62008-06-19 19:52:46 +000074
Chris Lattner4d8f8732006-11-28 05:05:08 +000075 if (TypeQualifiers != TQ_unspecified)
Chris Lattnerb9093cd2006-08-04 04:39:53 +000076 Res |= PQ_TypeQualifier;
77
Chris Lattnerf055d432006-11-28 04:28:12 +000078 if (hasTypeSpecifier())
Chris Lattnerb9093cd2006-08-04 04:39:53 +000079 Res |= PQ_TypeSpecifier;
80
Douglas Gregor61956c42008-10-31 09:07:45 +000081 if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified)
Chris Lattnerb9093cd2006-08-04 04:39:53 +000082 Res |= PQ_FunctionSpecifier;
83 return Res;
84}
85
Chris Lattner7bd11fe2007-01-23 04:35:33 +000086const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) {
Chris Lattnerf63f89a2006-08-05 03:28:50 +000087 switch (S) {
88 default: assert(0 && "Unknown typespec!");
89 case DeclSpec::SCS_unspecified: return "unspecified";
90 case DeclSpec::SCS_typedef: return "typedef";
91 case DeclSpec::SCS_extern: return "extern";
92 case DeclSpec::SCS_static: return "static";
93 case DeclSpec::SCS_auto: return "auto";
94 case DeclSpec::SCS_register: return "register";
Sebastian Redlccdfaba2008-11-14 23:42:31 +000095 case DeclSpec::SCS_mutable: return "mutable";
Chris Lattnerf63f89a2006-08-05 03:28:50 +000096 }
97}
98
Steve Naroffab468cb2008-02-12 04:08:59 +000099bool DeclSpec::BadSpecifier(SCS S, const char *&PrevSpec) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000100 PrevSpec = getSpecifierName(S);
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000101 return true;
102}
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000103
Steve Naroffab468cb2008-02-12 04:08:59 +0000104bool DeclSpec::BadSpecifier(TSW W, const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000105 switch (W) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000106 case TSW_unspecified: PrevSpec = "unspecified"; break;
107 case TSW_short: PrevSpec = "short"; break;
108 case TSW_long: PrevSpec = "long"; break;
109 case TSW_longlong: PrevSpec = "long long"; break;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000110 }
111 return true;
112}
113
Steve Naroffab468cb2008-02-12 04:08:59 +0000114bool DeclSpec::BadSpecifier(TSC C, const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000115 switch (C) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000116 case TSC_unspecified: PrevSpec = "unspecified"; break;
117 case TSC_imaginary: PrevSpec = "imaginary"; break;
118 case TSC_complex: PrevSpec = "complex"; break;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000119 }
120 return true;
121}
122
123
Steve Naroffab468cb2008-02-12 04:08:59 +0000124bool DeclSpec::BadSpecifier(TSS S, const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000125 switch (S) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000126 case TSS_unspecified: PrevSpec = "unspecified"; break;
127 case TSS_signed: PrevSpec = "signed"; break;
128 case TSS_unsigned: PrevSpec = "unsigned"; break;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000129 }
130 return true;
131}
132
Chris Lattner69680ea2007-01-23 04:34:43 +0000133const char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000134 switch (T) {
Chris Lattner839713c2006-08-04 06:15:52 +0000135 default: assert(0 && "Unknown typespec!");
136 case DeclSpec::TST_unspecified: return "unspecified";
137 case DeclSpec::TST_void: return "void";
138 case DeclSpec::TST_char: return "char";
Argyrios Kyrtzidis40e9e482008-08-09 16:51:54 +0000139 case DeclSpec::TST_wchar: return "wchar_t";
Chris Lattner839713c2006-08-04 06:15:52 +0000140 case DeclSpec::TST_int: return "int";
141 case DeclSpec::TST_float: return "float";
142 case DeclSpec::TST_double: return "double";
143 case DeclSpec::TST_bool: return "_Bool";
144 case DeclSpec::TST_decimal32: return "_Decimal32";
145 case DeclSpec::TST_decimal64: return "_Decimal64";
146 case DeclSpec::TST_decimal128: return "_Decimal128";
Chris Lattnerda72c822006-08-13 22:16:42 +0000147 case DeclSpec::TST_enum: return "enum";
Chris Lattner861a2262008-04-13 18:59:07 +0000148 case DeclSpec::TST_class: return "class";
Chris Lattnerda72c822006-08-13 22:16:42 +0000149 case DeclSpec::TST_union: return "union";
150 case DeclSpec::TST_struct: return "struct";
Douglas Gregor9817f4a2009-02-09 15:09:02 +0000151 case DeclSpec::TST_typename: return "type-name";
Steve Naroffad373bd2007-07-31 12:34:36 +0000152 case DeclSpec::TST_typeofType:
153 case DeclSpec::TST_typeofExpr: return "typeof";
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000154 }
Chris Lattner839713c2006-08-04 06:15:52 +0000155}
156
Steve Naroffab468cb2008-02-12 04:08:59 +0000157bool DeclSpec::BadSpecifier(TST T, const char *&PrevSpec) {
Steve Naroffab468cb2008-02-12 04:08:59 +0000158 PrevSpec = getSpecifierName(T);
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000159 return true;
160}
161
Steve Naroffab468cb2008-02-12 04:08:59 +0000162bool DeclSpec::BadSpecifier(TQ T, const char *&PrevSpec) {
Chris Lattnerda48a8e2006-08-04 05:25:55 +0000163 switch (T) {
164 case DeclSpec::TQ_unspecified: PrevSpec = "unspecified"; break;
165 case DeclSpec::TQ_const: PrevSpec = "const"; break;
166 case DeclSpec::TQ_restrict: PrevSpec = "restrict"; break;
167 case DeclSpec::TQ_volatile: PrevSpec = "volatile"; break;
168 }
169 return true;
170}
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000171
Chris Lattner4d8f8732006-11-28 05:05:08 +0000172bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc,
173 const char *&PrevSpec) {
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000174 if (StorageClassSpec != SCS_unspecified)
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000175 return BadSpecifier((SCS)StorageClassSpec, PrevSpec);
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000176 StorageClassSpec = S;
Chris Lattner4d8f8732006-11-28 05:05:08 +0000177 StorageClassSpecLoc = Loc;
Sebastian Redlccdfaba2008-11-14 23:42:31 +0000178 assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield");
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000179 return false;
180}
181
Chris Lattner4d8f8732006-11-28 05:05:08 +0000182bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc,
183 const char *&PrevSpec) {
Chris Lattner353f5742006-11-28 04:50:12 +0000184 if (SCS_thread_specified) {
185 PrevSpec = "__thread";
186 return true;
187 }
188 SCS_thread_specified = true;
Chris Lattner4d8f8732006-11-28 05:05:08 +0000189 SCS_threadLoc = Loc;
Chris Lattner353f5742006-11-28 04:50:12 +0000190 return false;
191}
192
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000193
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000194/// These methods set the specified attribute of the DeclSpec, but return true
195/// and ignore the request if invalid (e.g. "extern" then "auto" is
196/// specified).
Chris Lattnerb20e8942006-11-28 05:30:29 +0000197bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc,
198 const char *&PrevSpec) {
Chris Lattner353f5742006-11-28 04:50:12 +0000199 if (TypeSpecWidth != TSW_unspecified &&
200 // Allow turning long -> long long.
201 (W != TSW_longlong || TypeSpecWidth != TSW_long))
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000202 return BadSpecifier((TSW)TypeSpecWidth, PrevSpec);
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000203 TypeSpecWidth = W;
Chris Lattnerb20e8942006-11-28 05:30:29 +0000204 TSWLoc = Loc;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000205 return false;
206}
207
Chris Lattnerb20e8942006-11-28 05:30:29 +0000208bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc,
209 const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000210 if (TypeSpecComplex != TSC_unspecified)
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000211 return BadSpecifier((TSC)TypeSpecComplex, PrevSpec);
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000212 TypeSpecComplex = C;
Chris Lattnerb20e8942006-11-28 05:30:29 +0000213 TSCLoc = Loc;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000214 return false;
215}
216
Chris Lattnerb20e8942006-11-28 05:30:29 +0000217bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc,
218 const char *&PrevSpec) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000219 if (TypeSpecSign != TSS_unspecified)
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000220 return BadSpecifier((TSS)TypeSpecSign, PrevSpec);
Chris Lattnerdeb42f52006-08-04 05:26:52 +0000221 TypeSpecSign = S;
Chris Lattnerb20e8942006-11-28 05:30:29 +0000222 TSSLoc = Loc;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000223 return false;
224}
225
Chris Lattnerb20e8942006-11-28 05:30:29 +0000226bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
Argyrios Kyrtzidis25d05e82008-08-01 10:35:27 +0000227 const char *&PrevSpec, Action::TypeTy *Rep) {
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000228 if (TypeSpecType != TST_unspecified)
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000229 return BadSpecifier((TST)TypeSpecType, PrevSpec);
Chris Lattnerdeb42f52006-08-04 05:26:52 +0000230 TypeSpecType = T;
Chris Lattnerb9d572a2007-01-23 04:58:34 +0000231 TypeRep = Rep;
Chris Lattnerb20e8942006-11-28 05:30:29 +0000232 TSTLoc = Loc;
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000233 return false;
234}
235
Douglas Gregorcd72ba92009-02-06 22:42:48 +0000236bool DeclSpec::SetTypeSpecError() {
237 TypeSpecType = TST_error;
238 TypeRep = 0;
239 TSTLoc = SourceLocation();
240 return false;
241}
242
Chris Lattner60809f52006-11-28 05:18:46 +0000243bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
Chris Lattnerda48a8e2006-08-04 05:25:55 +0000244 const LangOptions &Lang) {
245 // Duplicates turn into warnings pre-C99.
246 if ((TypeQualifiers & T) && !Lang.C99)
247 return BadSpecifier(T, PrevSpec);
248 TypeQualifiers |= T;
Chris Lattner60809f52006-11-28 05:18:46 +0000249
250 switch (T) {
251 default: assert(0 && "Unknown type qualifier!");
252 case TQ_const: TQ_constLoc = Loc; break;
253 case TQ_restrict: TQ_restrictLoc = Loc; break;
254 case TQ_volatile: TQ_volatileLoc = Loc; break;
255 }
Chris Lattnerda48a8e2006-08-04 05:25:55 +0000256 return false;
257}
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000258
Chris Lattner1b22eed2006-11-28 05:12:07 +0000259bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec){
Chris Lattnera925dc62006-11-28 04:33:46 +0000260 // 'inline inline' is ok.
261 FS_inline_specified = true;
Chris Lattner1b22eed2006-11-28 05:12:07 +0000262 FS_inlineLoc = Loc;
Chris Lattnera925dc62006-11-28 04:33:46 +0000263 return false;
264}
265
Douglas Gregor61956c42008-10-31 09:07:45 +0000266bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec){
267 // 'virtual virtual' is ok.
268 FS_virtual_specified = true;
269 FS_virtualLoc = Loc;
270 return false;
271}
272
273bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec){
274 // 'explicit explicit' is ok.
275 FS_explicit_specified = true;
276 FS_explicitLoc = Loc;
277 return false;
278}
279
Chris Lattnera925dc62006-11-28 04:33:46 +0000280
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000281/// Finish - This does final analysis of the declspec, rejecting things like
282/// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
283/// diag::NUM_DIAGNOSTICS if there is no error. After calling this method,
284/// DeclSpec is guaranteed self-consistent, even if an error occurred.
Ted Kremenekd4e5fba2007-12-11 21:27:55 +0000285void DeclSpec::Finish(Diagnostic &D, SourceManager& SrcMgr,
286 const LangOptions &Lang) {
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000287 // Check the type specifier components first.
288
Argyrios Kyrtzidis40e9e482008-08-09 16:51:54 +0000289 // signed/unsigned are only valid with int/char/wchar_t.
Chris Lattner839713c2006-08-04 06:15:52 +0000290 if (TypeSpecSign != TSS_unspecified) {
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000291 if (TypeSpecType == TST_unspecified)
292 TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
Argyrios Kyrtzidis40e9e482008-08-09 16:51:54 +0000293 else if (TypeSpecType != TST_int &&
294 TypeSpecType != TST_char && TypeSpecType != TST_wchar) {
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000295 Diag(D, TSSLoc, SrcMgr, diag::err_invalid_sign_spec)
296 << getSpecifierName((TST)TypeSpecType);
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000297 // signed double -> double.
Chris Lattner839713c2006-08-04 06:15:52 +0000298 TypeSpecSign = TSS_unspecified;
299 }
300 }
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000301
Chris Lattner839713c2006-08-04 06:15:52 +0000302 // Validate the width of the type.
303 switch (TypeSpecWidth) {
304 case TSW_unspecified: break;
305 case TSW_short: // short int
306 case TSW_longlong: // long long int
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000307 if (TypeSpecType == TST_unspecified)
308 TypeSpecType = TST_int; // short -> short int, long long -> long long int.
309 else if (TypeSpecType != TST_int) {
Ted Kremenekd4e5fba2007-12-11 21:27:55 +0000310 Diag(D, TSWLoc, SrcMgr,
Chris Lattner36982e42007-05-16 17:49:37 +0000311 TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000312 : diag::err_invalid_longlong_spec)
313 << getSpecifierName((TST)TypeSpecType);
Chris Lattner839713c2006-08-04 06:15:52 +0000314 TypeSpecType = TST_int;
315 }
316 break;
317 case TSW_long: // long double, long int
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000318 if (TypeSpecType == TST_unspecified)
319 TypeSpecType = TST_int; // long -> long int.
320 else if (TypeSpecType != TST_int && TypeSpecType != TST_double) {
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000321 Diag(D, TSWLoc, SrcMgr, diag::err_invalid_long_spec)
322 << getSpecifierName((TST)TypeSpecType);
Chris Lattner839713c2006-08-04 06:15:52 +0000323 TypeSpecType = TST_int;
324 }
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000325 break;
Chris Lattner839713c2006-08-04 06:15:52 +0000326 }
327
Chris Lattner0e894622006-08-13 19:58:17 +0000328 // TODO: if the implementation does not implement _Complex or _Imaginary,
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000329 // disallow their use. Need information about the backend.
330 if (TypeSpecComplex != TSC_unspecified) {
331 if (TypeSpecType == TST_unspecified) {
Ted Kremenekd4e5fba2007-12-11 21:27:55 +0000332 Diag(D, TSCLoc, SrcMgr, diag::ext_plain_complex);
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000333 TypeSpecType = TST_double; // _Complex -> _Complex double.
334 } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000335 // Note that this intentionally doesn't include _Complex _Bool.
Ted Kremenekd4e5fba2007-12-11 21:27:55 +0000336 Diag(D, TSTLoc, SrcMgr, diag::ext_integer_complex);
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000337 } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000338 Diag(D, TSCLoc, SrcMgr, diag::err_invalid_complex_spec)
339 << getSpecifierName((TST)TypeSpecType);
Chris Lattnerfef9d2b2006-08-04 06:36:52 +0000340 TypeSpecComplex = TSC_unspecified;
341 }
342 }
Chris Lattner1ae23292006-08-04 06:42:31 +0000343
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000344 // Verify __thread.
345 if (SCS_thread_specified) {
346 if (StorageClassSpec == SCS_unspecified) {
347 StorageClassSpec = SCS_extern; // '__thread int' -> 'extern __thread int'
348 } else if (StorageClassSpec != SCS_extern &&
349 StorageClassSpec != SCS_static) {
Chris Lattner3b0f3ef2008-11-22 08:32:36 +0000350 Diag(D, getStorageClassSpecLoc(), SrcMgr, diag::err_invalid_thread_spec)
351 << getSpecifierName((SCS)StorageClassSpec);
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000352 SCS_thread_specified = false;
353 }
354 }
Chris Lattner8e90ef62006-08-05 03:30:45 +0000355
356 // Okay, now we can infer the real type.
Chris Lattner8e90ef62006-08-05 03:30:45 +0000357
Chris Lattner0e894622006-08-13 19:58:17 +0000358 // TODO: return "auto function" and other bad things based on the real type.
Chris Lattnerf63f89a2006-08-05 03:28:50 +0000359
Chris Lattner1ae23292006-08-04 06:42:31 +0000360 // 'data definition has no type or storage class'?
Chris Lattnerb9093cd2006-08-04 04:39:53 +0000361}
Daniel Dunbarc74b5cc2008-08-11 03:45:03 +0000362
Sebastian Redla2b5e312008-12-28 15:28:59 +0000363bool DeclSpec::isMissingDeclaratorOk() {
364 TST tst = getTypeSpecType();
365 return (tst == TST_union
366 || tst == TST_struct
367 || tst == TST_class
368 || tst == TST_enum
Douglas Gregorc6f58fe2009-01-12 22:49:06 +0000369 ) && getTypeRep() != 0 && StorageClassSpec != DeclSpec::SCS_typedef;
Sebastian Redla2b5e312008-12-28 15:28:59 +0000370}