clang 22.0.0git
DeclSpec.cpp
Go to the documentation of this file.
1//===--- DeclSpec.cpp - Declaration Specifier Semantic Analysis -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements semantic analysis for declaration specifiers.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Sema/DeclSpec.h"
15#include "clang/AST/DeclCXX.h"
16#include "clang/AST/Expr.h"
18#include "clang/AST/TypeLoc.h"
24#include "clang/Sema/Sema.h"
25#include <cstring>
26using namespace clang;
27
28
30 assert(TemplateId && "NULL template-id annotation?");
31 assert(!TemplateId->isInvalid() &&
32 "should not convert invalid template-ids to unqualified-ids");
33
35 this->TemplateId = TemplateId;
38}
39
41 assert(TemplateId && "NULL template-id annotation?");
42 assert(!TemplateId->isInvalid() &&
43 "should not convert invalid template-ids to unqualified-ids");
44
46 this->TemplateId = TemplateId;
49}
50
52 SourceLocation ColonColonLoc) {
53 Builder.Make(Context, TL, ColonColonLoc);
54 if (Range.getBegin().isInvalid())
55 Range.setBegin(TL.getBeginLoc());
56 Range.setEnd(ColonColonLoc);
57
58 assert(Range == Builder.getSourceRange() &&
59 "NestedNameSpecifierLoc range computation incorrect");
60}
61
63 SourceLocation NamespaceLoc,
64 SourceLocation ColonColonLoc) {
65 Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc);
66
67 if (Range.getBegin().isInvalid())
68 Range.setBegin(NamespaceLoc);
69 Range.setEnd(ColonColonLoc);
70
71 assert(Range == Builder.getSourceRange() &&
72 "NestedNameSpecifierLoc range computation incorrect");
73}
74
76 SourceLocation ColonColonLoc) {
77 Builder.MakeGlobal(Context, ColonColonLoc);
78
79 Range = SourceRange(ColonColonLoc);
80
81 assert(Range == Builder.getSourceRange() &&
82 "NestedNameSpecifierLoc range computation incorrect");
83}
84
86 SourceLocation SuperLoc,
87 SourceLocation ColonColonLoc) {
88 Builder.MakeMicrosoftSuper(Context, RD, SuperLoc, ColonColonLoc);
89
90 Range.setBegin(SuperLoc);
91 Range.setEnd(ColonColonLoc);
92
93 assert(Range == Builder.getSourceRange() &&
94 "NestedNameSpecifierLoc range computation incorrect");
95}
96
98 NestedNameSpecifier Qualifier, SourceRange R) {
99 Builder.MakeTrivial(Context, Qualifier, R);
100 Range = R;
101}
102
104 if (!Other) {
105 Range = SourceRange();
106 Builder.Clear();
107 return;
108 }
109
110 Range = Other.getSourceRange();
111 Builder.Adopt(Other);
112 assert(Range == Builder.getSourceRange() &&
113 "NestedNameSpecifierLoc range computation incorrect");
114}
115
117 if (!Builder.getRepresentation())
118 return SourceLocation();
119 return Builder.getTemporary().getLocalBeginLoc();
120}
121
124 if (!Builder.getRepresentation())
125 return NestedNameSpecifierLoc();
126
127 return Builder.getWithLocInContext(Context);
128}
129
130/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
131/// "TheDeclarator" is the declarator that this will be added to.
133 bool isAmbiguous,
134 SourceLocation LParenLoc,
135 ParamInfo *Params,
136 unsigned NumParams,
137 SourceLocation EllipsisLoc,
138 SourceLocation RParenLoc,
139 bool RefQualifierIsLvalueRef,
140 SourceLocation RefQualifierLoc,
141 SourceLocation MutableLoc,
143 ESpecType,
144 SourceRange ESpecRange,
145 ParsedType *Exceptions,
146 SourceRange *ExceptionRanges,
147 unsigned NumExceptions,
148 Expr *NoexceptExpr,
149 CachedTokens *ExceptionSpecTokens,
151 DeclsInPrototype,
152 SourceLocation LocalRangeBegin,
153 SourceLocation LocalRangeEnd,
154 Declarator &TheDeclarator,
155 TypeResult TrailingReturnType,
157 TrailingReturnTypeLoc,
158 DeclSpec *MethodQualifiers) {
159 assert(!(MethodQualifiers && MethodQualifiers->getTypeQualifiers() & DeclSpec::TQ_atomic) &&
160 "function cannot have _Atomic qualifier");
161
163 I.Kind = Function;
164 I.Loc = LocalRangeBegin;
165 I.EndLoc = LocalRangeEnd;
166 new (&I.Fun) FunctionTypeInfo;
167 I.Fun.hasPrototype = hasProto;
168 I.Fun.isVariadic = EllipsisLoc.isValid();
169 I.Fun.isAmbiguous = isAmbiguous;
170 I.Fun.LParenLoc = LParenLoc;
171 I.Fun.EllipsisLoc = EllipsisLoc;
172 I.Fun.RParenLoc = RParenLoc;
173 I.Fun.DeleteParams = false;
174 I.Fun.NumParams = NumParams;
175 I.Fun.Params = nullptr;
176 I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
177 I.Fun.RefQualifierLoc = RefQualifierLoc;
178 I.Fun.MutableLoc = MutableLoc;
179 I.Fun.ExceptionSpecType = ESpecType;
180 I.Fun.ExceptionSpecLocBeg = ESpecRange.getBegin();
181 I.Fun.ExceptionSpecLocEnd = ESpecRange.getEnd();
183 I.Fun.Exceptions = nullptr;
184 I.Fun.NoexceptExpr = nullptr;
185 I.Fun.HasTrailingReturnType = TrailingReturnType.isUsable() ||
186 TrailingReturnType.isInvalid();
187 I.Fun.TrailingReturnType = TrailingReturnType.get();
188 I.Fun.TrailingReturnTypeLoc = TrailingReturnTypeLoc;
189 I.Fun.MethodQualifiers = nullptr;
190 I.Fun.QualAttrFactory = nullptr;
191
192 if (MethodQualifiers && (MethodQualifiers->getTypeQualifiers() ||
193 MethodQualifiers->getAttributes().size())) {
194 auto &attrs = MethodQualifiers->getAttributes();
195 I.Fun.MethodQualifiers = new DeclSpec(attrs.getPool().getFactory());
196 MethodQualifiers->forEachCVRUQualifier(
197 [&](DeclSpec::TQ TypeQual, StringRef PrintName, SourceLocation SL) {
198 I.Fun.MethodQualifiers->SetTypeQual(TypeQual, SL);
199 });
201 I.Fun.MethodQualifiers->getAttributePool().takeAllFrom(attrs.getPool());
202 }
203
204 assert(I.Fun.ExceptionSpecType == ESpecType && "bitfield overflow");
205
206 // new[] a parameter array if needed.
207 if (NumParams) {
208 // If the 'InlineParams' in Declarator is unused and big enough, put our
209 // parameter list there (in an effort to avoid new/delete traffic). If it
210 // is already used (consider a function returning a function pointer) or too
211 // small (function with too many parameters), go to the heap.
212 if (!TheDeclarator.InlineStorageUsed &&
213 NumParams <= std::size(TheDeclarator.InlineParams)) {
214 I.Fun.Params = TheDeclarator.InlineParams;
215 new (I.Fun.Params) ParamInfo[NumParams];
216 I.Fun.DeleteParams = false;
217 TheDeclarator.InlineStorageUsed = true;
218 } else {
219 I.Fun.Params = new DeclaratorChunk::ParamInfo[NumParams];
220 I.Fun.DeleteParams = true;
221 }
222 for (unsigned i = 0; i < NumParams; i++)
223 I.Fun.Params[i] = std::move(Params[i]);
224 }
225
226 // Check what exception specification information we should actually store.
227 switch (ESpecType) {
228 default: break; // By default, save nothing.
229 case EST_Dynamic:
230 // new[] an exception array if needed
231 if (NumExceptions) {
232 I.Fun.NumExceptionsOrDecls = NumExceptions;
233 I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
234 for (unsigned i = 0; i != NumExceptions; ++i) {
235 I.Fun.Exceptions[i].Ty = Exceptions[i];
236 I.Fun.Exceptions[i].Range = ExceptionRanges[i];
237 }
238 }
239 break;
240
243 case EST_NoexceptTrue:
244 I.Fun.NoexceptExpr = NoexceptExpr;
245 break;
246
247 case EST_Unparsed:
248 I.Fun.ExceptionSpecTokens = ExceptionSpecTokens;
249 break;
250 }
251
252 if (!DeclsInPrototype.empty()) {
253 assert(ESpecType == EST_None && NumExceptions == 0 &&
254 "cannot have exception specifiers and decls in prototype");
255 I.Fun.NumExceptionsOrDecls = DeclsInPrototype.size();
256 // Copy the array of decls into stable heap storage.
257 I.Fun.DeclsInPrototype = new NamedDecl *[DeclsInPrototype.size()];
258 for (size_t J = 0; J < DeclsInPrototype.size(); ++J)
259 I.Fun.DeclsInPrototype[J] = DeclsInPrototype[J];
260 }
261
262 return I;
263}
264
266 SourceLocation LSquareLoc,
268 SourceLocation RSquareLoc) {
269 assert(!hasName() && "declarator given multiple names!");
270
271 BindingGroup.LSquareLoc = LSquareLoc;
272 BindingGroup.RSquareLoc = RSquareLoc;
273 BindingGroup.NumBindings = Bindings.size();
274 Range.setEnd(RSquareLoc);
275
276 // We're now past the identifier.
277 SetIdentifier(nullptr, LSquareLoc);
278 Name.EndLocation = RSquareLoc;
279
280 // Allocate storage for bindings and stash them away.
281 if (Bindings.size()) {
282 if (!InlineStorageUsed && Bindings.size() <= std::size(InlineBindings)) {
283 BindingGroup.Bindings = InlineBindings;
284 BindingGroup.DeleteBindings = false;
285 InlineStorageUsed = true;
286 } else {
287 BindingGroup.Bindings =
289 BindingGroup.DeleteBindings = true;
290 }
291 std::uninitialized_move(Bindings.begin(), Bindings.end(),
292 BindingGroup.Bindings);
293 }
294}
295
297 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
298 switch (DeclTypeInfo[i].Kind) {
300 return true;
302 continue;
309 return false;
310 }
311 llvm_unreachable("Invalid type chunk");
312 }
313
314 switch (DS.getTypeSpecType()) {
315 case TST_atomic:
316 case TST_auto:
317 case TST_auto_type:
318 case TST_bool:
319 case TST_char:
320 case TST_char8:
321 case TST_char16:
322 case TST_char32:
323 case TST_class:
324 case TST_decimal128:
325 case TST_decimal32:
326 case TST_decimal64:
327 case TST_double:
328 case TST_Accum:
329 case TST_Fract:
330 case TST_Float16:
331 case TST_float128:
332 case TST_ibm128:
333 case TST_enum:
334 case TST_error:
335 case TST_float:
336 case TST_half:
337 case TST_int:
338 case TST_int128:
339 case TST_bitint:
340 case TST_struct:
341 case TST_interface:
342 case TST_union:
344 case TST_unspecified:
345 case TST_void:
346 case TST_wchar:
347 case TST_BFloat16:
349#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
350#include "clang/Basic/OpenCLImageTypes.def"
351#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
352#include "clang/Basic/HLSLIntangibleTypes.def"
353 return false;
354
356 // This must have an initializer, so can't be a function declaration,
357 // even if the initializer has function type.
358 return false;
359
360 case TST_decltype:
362 case TST_typeofExpr:
363 if (Expr *E = DS.getRepAsExpr())
364 return E->getType()->isFunctionType();
365 return false;
366
367#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case TST_##Trait:
368#include "clang/Basic/TransformTypeTraits.def"
369 case TST_typename:
371 case TST_typeofType: {
372 QualType QT = DS.getRepAsType().get();
373 if (QT.isNull())
374 return false;
375
376 if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
377 QT = LIT->getType();
378
379 if (QT.isNull())
380 return false;
381
382 return QT->isFunctionType();
383 }
384 }
385
386 llvm_unreachable("Invalid TypeSpecType!");
387}
388
395 getName().OperatorFunctionId.Operator));
396}
397
400 return false;
402 if (Fun.NumParams) {
403 auto *P = dyn_cast_or_null<ParmVarDecl>(Fun.Params[0].Param);
404 if (P && P->isExplicitObjectParameter())
405 return true;
406 }
407 return false;
408}
409
413}
414
416 llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) {
417 if (TypeQualifiers & TQ_const)
418 Handle(TQ_const, "const", TQ_constLoc);
419 if (TypeQualifiers & TQ_volatile)
420 Handle(TQ_volatile, "volatile", TQ_volatileLoc);
421 if (TypeQualifiers & TQ_restrict)
422 Handle(TQ_restrict, "restrict", TQ_restrictLoc);
423 if (TypeQualifiers & TQ_unaligned)
424 Handle(TQ_unaligned, "unaligned", TQ_unalignedLoc);
425}
426
428 llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) {
429 forEachCVRUQualifier(Handle);
430 // FIXME: Add code below to iterate through the attributes and call Handle.
431}
432
434 if (!TypeSpecOwned)
435 return false;
436 return cast<TagDecl>(getRepAsDecl())->isCompleteDefinition();
437}
438
439/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
440/// declaration specifier includes.
441///
443 unsigned Res = 0;
444 if (StorageClassSpec != SCS_unspecified ||
445 ThreadStorageClassSpec != TSCS_unspecified)
447
448 if (TypeQualifiers != TQ_unspecified)
449 Res |= PQ_TypeQualifier;
450
451 if (hasTypeSpecifier())
452 Res |= PQ_TypeSpecifier;
453
454 if (FS_inline_specified || FS_virtual_specified || hasExplicitSpecifier() ||
455 FS_noreturn_specified || FS_forceinline_specified)
457 return Res;
458}
459
460template <class T> static bool BadSpecifier(T TNew, T TPrev,
461 const char *&PrevSpec,
462 unsigned &DiagID,
463 bool IsExtension = true) {
464 PrevSpec = DeclSpec::getSpecifierName(TPrev);
465 if (TNew != TPrev)
466 DiagID = diag::err_invalid_decl_spec_combination;
467 else
468 DiagID = IsExtension ? diag::ext_warn_duplicate_declspec :
469 diag::warn_duplicate_declspec;
470 return true;
471}
472
474 switch (S) {
475 case DeclSpec::SCS_unspecified: return "unspecified";
476 case DeclSpec::SCS_typedef: return "typedef";
477 case DeclSpec::SCS_extern: return "extern";
478 case DeclSpec::SCS_static: return "static";
479 case DeclSpec::SCS_auto: return "auto";
480 case DeclSpec::SCS_register: return "register";
481 case DeclSpec::SCS_private_extern: return "__private_extern__";
482 case DeclSpec::SCS_mutable: return "mutable";
483 }
484 llvm_unreachable("Unknown typespec!");
485}
486
488 switch (S) {
489 case DeclSpec::TSCS_unspecified: return "unspecified";
490 case DeclSpec::TSCS___thread: return "__thread";
491 case DeclSpec::TSCS_thread_local: return "thread_local";
492 case DeclSpec::TSCS__Thread_local: return "_Thread_local";
493 }
494 llvm_unreachable("Unknown typespec!");
495}
496
498 switch (W) {
500 return "unspecified";
502 return "short";
504 return "long";
506 return "long long";
507 }
508 llvm_unreachable("Unknown typespec!");
509}
510
512 switch (C) {
513 case TSC_unspecified: return "unspecified";
514 case TSC_imaginary: return "imaginary";
515 case TSC_complex: return "complex";
516 }
517 llvm_unreachable("Unknown typespec!");
518}
519
521 switch (S) {
523 return "unspecified";
525 return "signed";
527 return "unsigned";
528 }
529 llvm_unreachable("Unknown typespec!");
530}
531
533 const PrintingPolicy &Policy) {
534 switch (T) {
535 case DeclSpec::TST_unspecified: return "unspecified";
536 case DeclSpec::TST_void: return "void";
537 case DeclSpec::TST_char: return "char";
538 case DeclSpec::TST_wchar: return Policy.MSWChar ? "__wchar_t" : "wchar_t";
539 case DeclSpec::TST_char8: return "char8_t";
540 case DeclSpec::TST_char16: return "char16_t";
541 case DeclSpec::TST_char32: return "char32_t";
542 case DeclSpec::TST_int: return "int";
543 case DeclSpec::TST_int128: return "__int128";
544 case DeclSpec::TST_bitint: return "_BitInt";
545 case DeclSpec::TST_half: return "half";
546 case DeclSpec::TST_float: return "float";
547 case DeclSpec::TST_double: return "double";
548 case DeclSpec::TST_accum: return "_Accum";
549 case DeclSpec::TST_fract: return "_Fract";
550 case DeclSpec::TST_float16: return "_Float16";
551 case DeclSpec::TST_float128: return "__float128";
552 case DeclSpec::TST_ibm128: return "__ibm128";
553 case DeclSpec::TST_bool: return Policy.Bool ? "bool" : "_Bool";
554 case DeclSpec::TST_decimal32: return "_Decimal32";
555 case DeclSpec::TST_decimal64: return "_Decimal64";
556 case DeclSpec::TST_decimal128: return "_Decimal128";
557 case DeclSpec::TST_enum: return "enum";
558 case DeclSpec::TST_class: return "class";
559 case DeclSpec::TST_union: return "union";
560 case DeclSpec::TST_struct: return "struct";
561 case DeclSpec::TST_interface: return "__interface";
562 case DeclSpec::TST_typename: return "type-name";
564 return "type-name-pack-indexing";
566 case DeclSpec::TST_typeofExpr: return "typeof";
568 case DeclSpec::TST_typeof_unqualExpr: return "typeof_unqual";
569 case DeclSpec::TST_auto: return "auto";
570 case DeclSpec::TST_auto_type: return "__auto_type";
571 case DeclSpec::TST_decltype: return "(decltype)";
572 case DeclSpec::TST_decltype_auto: return "decltype(auto)";
573#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
574 case DeclSpec::TST_##Trait: \
575 return "__" #Trait;
576#include "clang/Basic/TransformTypeTraits.def"
577 case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
578 case DeclSpec::TST_atomic: return "_Atomic";
579 case DeclSpec::TST_BFloat16: return "__bf16";
580#define GENERIC_IMAGE_TYPE(ImgType, Id) \
581 case DeclSpec::TST_##ImgType##_t: \
582 return #ImgType "_t";
583#include "clang/Basic/OpenCLImageTypes.def"
584#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
585 case DeclSpec::TST_##Name: \
586 return #Name;
587#include "clang/Basic/HLSLIntangibleTypes.def"
588 case DeclSpec::TST_error: return "(error)";
589 }
590 llvm_unreachable("Unknown typespec!");
591}
592
594 switch (C) {
596 return "unspecified";
598 return "constexpr";
600 return "consteval";
602 return "constinit";
603 }
604 llvm_unreachable("Unknown ConstexprSpecKind");
605}
606
608 switch (T) {
609 case DeclSpec::TQ_unspecified: return "unspecified";
610 case DeclSpec::TQ_const: return "const";
611 case DeclSpec::TQ_restrict: return "restrict";
612 case DeclSpec::TQ_volatile: return "volatile";
613 case DeclSpec::TQ_atomic: return "_Atomic";
614 case DeclSpec::TQ_unaligned: return "__unaligned";
615 }
616 llvm_unreachable("Unknown typespec!");
617}
618
620 const char *&PrevSpec,
621 unsigned &DiagID,
622 const PrintingPolicy &Policy) {
623 // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class
624 // specifiers are not supported.
625 // It seems sensible to prohibit private_extern too
626 // The cl_clang_storage_class_specifiers extension enables support for
627 // these storage-class specifiers.
628 // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class
629 // specifiers are not supported."
630 if (S.getLangOpts().OpenCL &&
632 "cl_clang_storage_class_specifiers", S.getLangOpts())) {
633 switch (SC) {
634 case SCS_extern:
636 case SCS_static:
637 if (S.getLangOpts().getOpenCLCompatibleVersion() < 120) {
638 DiagID = diag::err_opencl_unknown_type_specifier;
639 PrevSpec = getSpecifierName(SC);
640 return true;
641 }
642 break;
643 case SCS_auto:
644 case SCS_register:
645 DiagID = diag::err_opencl_unknown_type_specifier;
646 PrevSpec = getSpecifierName(SC);
647 return true;
648 default:
649 break;
650 }
651 }
652
653 if (StorageClassSpec != SCS_unspecified) {
654 // Maybe this is an attempt to use C++11 'auto' outside of C++11 mode.
655 bool isInvalid = true;
656 if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) {
657 if (SC == SCS_auto)
658 return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID, Policy);
659 if (StorageClassSpec == SCS_auto) {
660 isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc,
661 PrevSpec, DiagID, Policy);
662 assert(!isInvalid && "auto SCS -> TST recovery failed");
663 }
664 }
665
666 // Changing storage class is allowed only if the previous one
667 // was the 'extern' that is part of a linkage specification and
668 // the new storage class is 'typedef'.
669 if (isInvalid &&
670 !(SCS_extern_in_linkage_spec &&
671 StorageClassSpec == SCS_extern &&
672 SC == SCS_typedef))
673 return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID);
674 }
675 StorageClassSpec = SC;
676 StorageClassSpecLoc = Loc;
677 assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
678 return false;
679}
680
682 const char *&PrevSpec,
683 unsigned &DiagID) {
684 if (ThreadStorageClassSpec != TSCS_unspecified)
685 return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID);
686
687 ThreadStorageClassSpec = TSC;
688 ThreadStorageClassSpecLoc = Loc;
689 return false;
690}
691
692/// These methods set the specified attribute of the DeclSpec, but return true
693/// and ignore the request if invalid (e.g. "extern" then "auto" is
694/// specified).
696 const char *&PrevSpec, unsigned &DiagID,
697 const PrintingPolicy &Policy) {
698 // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that
699 // for 'long long' we will keep the source location of the first 'long'.
701 TSWRange.setBegin(Loc);
702 // Allow turning long -> long long.
703 else if (W != TypeSpecifierWidth::LongLong ||
705 return BadSpecifier(W, getTypeSpecWidth(), PrevSpec, DiagID);
706 TypeSpecWidth = static_cast<unsigned>(W);
707 // Remember location of the last 'long'
708 TSWRange.setEnd(Loc);
709 return false;
710}
711
713 const char *&PrevSpec,
714 unsigned &DiagID) {
715 if (TypeSpecComplex != TSC_unspecified)
716 return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
717 TypeSpecComplex = C;
718 TSCLoc = Loc;
719 return false;
720}
721
723 const char *&PrevSpec, unsigned &DiagID) {
725 return BadSpecifier(S, getTypeSpecSign(), PrevSpec, DiagID);
726 TypeSpecSign = static_cast<unsigned>(S);
727 TSSLoc = Loc;
728 return false;
729}
730
732 const char *&PrevSpec,
733 unsigned &DiagID,
734 ParsedType Rep,
735 const PrintingPolicy &Policy) {
736 return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Policy);
737}
738
740 SourceLocation TagNameLoc,
741 const char *&PrevSpec,
742 unsigned &DiagID,
743 ParsedType Rep,
744 const PrintingPolicy &Policy) {
745 assert(isTypeRep(T) && "T does not store a type");
746 assert(Rep && "no type provided!");
747 if (TypeSpecType == TST_error)
748 return false;
749 if (TypeSpecType != TST_unspecified) {
750 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
751 DiagID = diag::err_invalid_decl_spec_combination;
752 return true;
753 }
754 TypeSpecType = T;
755 TypeRep = Rep;
756 TSTLoc = TagKwLoc;
757 TSTNameLoc = TagNameLoc;
758 TypeSpecOwned = false;
759
761 // we got there from a an annotation. Reconstruct the type
762 // Ugly...
763 QualType QT = Rep.get();
764 const PackIndexingType *LIT = cast<PackIndexingType>(QT);
767 }
768 return false;
769}
770
772 const char *&PrevSpec,
773 unsigned &DiagID,
774 Expr *Rep,
775 const PrintingPolicy &Policy) {
776 assert(isExprRep(T) && "T does not store an expr");
777 assert(Rep && "no expression provided!");
778 if (TypeSpecType == TST_error)
779 return false;
780 if (TypeSpecType != TST_unspecified) {
781 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
782 DiagID = diag::err_invalid_decl_spec_combination;
783 return true;
784 }
785 TypeSpecType = T;
786 ExprRep = Rep;
787 TSTLoc = Loc;
788 TSTNameLoc = Loc;
789 TypeSpecOwned = false;
790 return false;
791}
792
794 const char *&PrevSpec,
795 unsigned &DiagID,
796 Decl *Rep, bool Owned,
797 const PrintingPolicy &Policy) {
798 return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned, Policy);
799}
800
802 SourceLocation TagNameLoc,
803 const char *&PrevSpec,
804 unsigned &DiagID,
805 Decl *Rep, bool Owned,
806 const PrintingPolicy &Policy) {
807 assert(isDeclRep(T) && "T does not store a decl");
808 // Unlike the other cases, we don't assert that we actually get a decl.
809
810 if (TypeSpecType == TST_error)
811 return false;
812 if (TypeSpecType != TST_unspecified) {
813 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
814 DiagID = diag::err_invalid_decl_spec_combination;
815 return true;
816 }
817 TypeSpecType = T;
818 DeclRep = Rep;
819 TSTLoc = TagKwLoc;
820 TSTNameLoc = TagNameLoc;
821 TypeSpecOwned = Owned && Rep != nullptr;
822 return false;
823}
824
825bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
826 unsigned &DiagID, TemplateIdAnnotation *Rep,
827 const PrintingPolicy &Policy) {
828 assert(T == TST_auto || T == TST_decltype_auto);
829 ConstrainedAuto = true;
830 TemplateIdRep = Rep;
831 return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Policy);
832}
833
835 const char *&PrevSpec,
836 unsigned &DiagID,
837 const PrintingPolicy &Policy) {
838 assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) &&
839 "rep required for these type-spec kinds!");
840 if (TypeSpecType == TST_error)
841 return false;
842 if (TypeSpecType != TST_unspecified) {
843 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
844 DiagID = diag::err_invalid_decl_spec_combination;
845 return true;
846 }
847 TSTLoc = Loc;
848 TSTNameLoc = Loc;
849 if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) {
850 TypeAltiVecBool = true;
851 return false;
852 }
853 TypeSpecType = T;
854 TypeSpecOwned = false;
855 return false;
856}
857
858bool DeclSpec::SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
859 unsigned &DiagID) {
860 // Cannot set twice
861 if (TypeSpecSat) {
862 DiagID = diag::warn_duplicate_declspec;
863 PrevSpec = "_Sat";
864 return true;
865 }
866 TypeSpecSat = true;
867 TSSatLoc = Loc;
868 return false;
869}
870
872 const char *&PrevSpec, unsigned &DiagID,
873 const PrintingPolicy &Policy) {
874 if (TypeSpecType == TST_error)
875 return false;
876 if (TypeSpecType != TST_unspecified) {
877 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
878 DiagID = diag::err_invalid_vector_decl_spec_combination;
879 return true;
880 }
881 TypeAltiVecVector = isAltiVecVector;
882 AltiVecLoc = Loc;
883 return false;
884}
885
887 const char *&PrevSpec, unsigned &DiagID,
888 const PrintingPolicy &Policy) {
889 if (TypeSpecType == TST_error)
890 return false;
891 if (TypeSpecType != TST_unspecified) {
892 PrevSpec = DeclSpec::getSpecifierName((TST)TypeSpecType, Policy);
893 DiagID = diag::err_invalid_decl_spec_combination;
894 return true;
895 }
896
897 if (isPipe) {
898 TypeSpecPipe = static_cast<unsigned>(TypeSpecifiersPipe::Pipe);
899 }
900 return false;
901}
902
904 const char *&PrevSpec, unsigned &DiagID,
905 const PrintingPolicy &Policy) {
906 if (TypeSpecType == TST_error)
907 return false;
908 if (!TypeAltiVecVector || TypeAltiVecPixel ||
909 (TypeSpecType != TST_unspecified)) {
910 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
911 DiagID = diag::err_invalid_pixel_decl_spec_combination;
912 return true;
913 }
914 TypeAltiVecPixel = isAltiVecPixel;
915 TSTLoc = Loc;
916 TSTNameLoc = Loc;
917 return false;
918}
919
921 const char *&PrevSpec, unsigned &DiagID,
922 const PrintingPolicy &Policy) {
923 if (TypeSpecType == TST_error)
924 return false;
925 if (!TypeAltiVecVector || TypeAltiVecBool ||
926 (TypeSpecType != TST_unspecified)) {
927 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
928 DiagID = diag::err_invalid_vector_bool_decl_spec;
929 return true;
930 }
931 TypeAltiVecBool = isAltiVecBool;
932 TSTLoc = Loc;
933 TSTNameLoc = Loc;
934 return false;
935}
936
938 TypeSpecType = TST_error;
939 TypeSpecOwned = false;
940 TSTLoc = SourceLocation();
941 TSTNameLoc = SourceLocation();
942 return false;
943}
944
946 const char *&PrevSpec, unsigned &DiagID,
947 const PrintingPolicy &Policy) {
948 assert(BitsExpr && "no expression provided!");
949 if (TypeSpecType == TST_error)
950 return false;
951
952 if (TypeSpecType != TST_unspecified) {
953 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
954 DiagID = diag::err_invalid_decl_spec_combination;
955 return true;
956 }
957
958 TypeSpecType = TST_bitint;
959 ExprRep = BitsExpr;
960 TSTLoc = KWLoc;
961 TSTNameLoc = KWLoc;
962 TypeSpecOwned = false;
963 return false;
964}
965
967 Expr *IndexingExpr) {
968 assert(TypeSpecType == TST_typename &&
969 "pack indexing can only be applied to typename");
970 TypeSpecType = TST_typename_pack_indexing;
971 PackIndexingExpr = IndexingExpr;
972 this->EllipsisLoc = EllipsisLoc;
973}
974
975bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
976 unsigned &DiagID, const LangOptions &Lang) {
977 // Duplicates are permitted in C99 onwards, but are not permitted in C89 or
978 // C++. However, since this is likely not what the user intended, we will
979 // always warn. We do not need to set the qualifier's location since we
980 // already have it.
981 if (TypeQualifiers & T) {
982 bool IsExtension = true;
983 if (Lang.C99)
984 IsExtension = false;
985 return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension);
986 }
987
988 return SetTypeQual(T, Loc);
989}
990
992 TypeQualifiers |= T;
993
994 switch (T) {
995 case TQ_unspecified: break;
996 case TQ_const: TQ_constLoc = Loc; return false;
997 case TQ_restrict: TQ_restrictLoc = Loc; return false;
998 case TQ_volatile: TQ_volatileLoc = Loc; return false;
999 case TQ_unaligned: TQ_unalignedLoc = Loc; return false;
1000 case TQ_atomic: TQ_atomicLoc = Loc; return false;
1001 }
1002
1003 llvm_unreachable("Unknown type qualifier!");
1004}
1005
1007 unsigned &DiagID) {
1008 // 'inline inline' is ok. However, since this is likely not what the user
1009 // intended, we will always warn, similar to duplicates of type qualifiers.
1010 if (FS_inline_specified) {
1011 DiagID = diag::warn_duplicate_declspec;
1012 PrevSpec = "inline";
1013 return true;
1014 }
1015 FS_inline_specified = true;
1016 FS_inlineLoc = Loc;
1017 return false;
1018}
1019
1021 unsigned &DiagID) {
1022 if (FS_forceinline_specified) {
1023 DiagID = diag::warn_duplicate_declspec;
1024 PrevSpec = "__forceinline";
1025 return true;
1026 }
1027 FS_forceinline_specified = true;
1028 FS_forceinlineLoc = Loc;
1029 return false;
1030}
1031
1033 const char *&PrevSpec,
1034 unsigned &DiagID) {
1035 // 'virtual virtual' is ok, but warn as this is likely not what the user
1036 // intended.
1037 if (FS_virtual_specified) {
1038 DiagID = diag::warn_duplicate_declspec;
1039 PrevSpec = "virtual";
1040 return true;
1041 }
1042 FS_virtual_specified = true;
1043 FS_virtualLoc = Loc;
1044 return false;
1045}
1046
1048 const char *&PrevSpec, unsigned &DiagID,
1049 ExplicitSpecifier ExplicitSpec,
1050 SourceLocation CloseParenLoc) {
1051 // 'explicit explicit' is ok, but warn as this is likely not what the user
1052 // intended.
1053 if (hasExplicitSpecifier()) {
1054 DiagID = (ExplicitSpec.getExpr() || FS_explicit_specifier.getExpr())
1055 ? diag::err_duplicate_declspec
1056 : diag::ext_warn_duplicate_declspec;
1057 PrevSpec = "explicit";
1058 return true;
1059 }
1060 FS_explicit_specifier = ExplicitSpec;
1061 FS_explicitLoc = Loc;
1062 FS_explicitCloseParenLoc = CloseParenLoc;
1063 return false;
1064}
1065
1067 const char *&PrevSpec,
1068 unsigned &DiagID) {
1069 // '_Noreturn _Noreturn' is ok, but warn as this is likely not what the user
1070 // intended.
1071 if (FS_noreturn_specified) {
1072 DiagID = diag::warn_duplicate_declspec;
1073 PrevSpec = "_Noreturn";
1074 return true;
1075 }
1076 FS_noreturn_specified = true;
1077 FS_noreturnLoc = Loc;
1078 return false;
1079}
1080
1081bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
1082 unsigned &DiagID) {
1083 if (isFriendSpecified()) {
1084 PrevSpec = "friend";
1085 DiagID = diag::warn_duplicate_declspec;
1086 return true;
1087 }
1088
1089 FriendSpecifiedFirst = isEmpty();
1090 FriendLoc = Loc;
1091 return false;
1092}
1093
1095 unsigned &DiagID) {
1097 PrevSpec = "__module_private__";
1098 DiagID = diag::ext_warn_duplicate_declspec;
1099 return true;
1100 }
1101
1102 ModulePrivateLoc = Loc;
1103 return false;
1104}
1105
1107 SourceLocation Loc, const char *&PrevSpec,
1108 unsigned &DiagID) {
1110 return BadSpecifier(ConstexprKind, getConstexprSpecifier(), PrevSpec,
1111 DiagID);
1112 ConstexprSpecifier = static_cast<unsigned>(ConstexprKind);
1113 ConstexprLoc = Loc;
1114 return false;
1115}
1116
1117void DeclSpec::SaveWrittenBuiltinSpecs() {
1118 writtenBS.Sign = static_cast<int>(getTypeSpecSign());
1119 writtenBS.Width = static_cast<int>(getTypeSpecWidth());
1120 writtenBS.Type = getTypeSpecType();
1121 // Search the list of attributes for the presence of a mode attribute.
1122 writtenBS.ModeAttr = getAttributes().hasAttribute(ParsedAttr::AT_Mode);
1123}
1124
1125/// Finish - This does final analysis of the declspec, rejecting things like
1126/// "_Complex" (lacking an FP type). After calling this method, DeclSpec is
1127/// guaranteed to be self-consistent, even if an error occurred.
1128void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
1129 // Before possibly changing their values, save specs as written.
1130 SaveWrittenBuiltinSpecs();
1131
1132 // Check the type specifier components first. No checking for an invalid
1133 // type.
1134 if (TypeSpecType == TST_error)
1135 return;
1136
1137 // If decltype(auto) is used, no other type specifiers are permitted.
1138 if (TypeSpecType == TST_decltype_auto &&
1140 TypeSpecComplex != TSC_unspecified ||
1142 TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
1143 TypeQualifiers)) {
1144 const unsigned NumLocs = 9;
1145 SourceLocation ExtraLocs[NumLocs] = {
1146 TSWRange.getBegin(), TSCLoc, TSSLoc,
1147 AltiVecLoc, TQ_constLoc, TQ_restrictLoc,
1148 TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc};
1149 FixItHint Hints[NumLocs];
1150 SourceLocation FirstLoc;
1151 for (unsigned I = 0; I != NumLocs; ++I) {
1152 if (ExtraLocs[I].isValid()) {
1153 if (FirstLoc.isInvalid() ||
1155 FirstLoc))
1156 FirstLoc = ExtraLocs[I];
1157 Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]);
1158 }
1159 }
1160 TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Unspecified);
1161 TypeSpecComplex = TSC_unspecified;
1162 TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unspecified);
1163 TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false;
1164 TypeQualifiers = 0;
1165 S.Diag(TSTLoc, diag::err_decltype_auto_cannot_be_combined)
1166 << Hints[0] << Hints[1] << Hints[2] << Hints[3]
1167 << Hints[4] << Hints[5] << Hints[6] << Hints[7];
1168 }
1169
1170 // Validate and finalize AltiVec vector declspec.
1171 if (TypeAltiVecVector) {
1172 // No vector long long without VSX (or ZVector).
1174 !S.Context.getTargetInfo().hasFeature("vsx") &&
1175 !S.getLangOpts().ZVector)
1176 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_long_decl_spec);
1177
1178 // No vector __int128 prior to Power8 (or ZVector).
1179 if ((TypeSpecType == TST_int128) &&
1180 !S.Context.getTargetInfo().hasFeature("power8-vector") &&
1181 !S.getLangOpts().ZVector)
1182 S.Diag(TSTLoc, diag::err_invalid_vector_int128_decl_spec);
1183
1184 // Complex vector types are not supported.
1185 if (TypeSpecComplex != TSC_unspecified)
1186 S.Diag(TSCLoc, diag::err_invalid_vector_complex_decl_spec);
1187 else if (TypeAltiVecBool) {
1188 // Sign specifiers are not allowed with vector bool. (PIM 2.1)
1190 S.Diag(TSSLoc, diag::err_invalid_vector_bool_decl_spec)
1192 }
1193 // Only char/int are valid with vector bool prior to Power10.
1194 // Power10 adds instructions that produce vector bool data
1195 // for quadwords as well so allow vector bool __int128.
1196 if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) &&
1197 (TypeSpecType != TST_int) && (TypeSpecType != TST_int128)) ||
1198 TypeAltiVecPixel) {
1199 S.Diag(TSTLoc, diag::err_invalid_vector_bool_decl_spec)
1200 << (TypeAltiVecPixel ? "__pixel" :
1201 getSpecifierName((TST)TypeSpecType, Policy));
1202 }
1203 // vector bool __int128 requires Power10 (or ZVector).
1204 if ((TypeSpecType == TST_int128) &&
1205 (!S.Context.getTargetInfo().hasFeature("power10-vector") &&
1206 !S.getLangOpts().ZVector))
1207 S.Diag(TSTLoc, diag::err_invalid_vector_bool_int128_decl_spec);
1208
1209 // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
1213 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec)
1215
1216 // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
1217 if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) ||
1218 (TypeSpecType == TST_int128) ||
1220 TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unsigned);
1221 } else if (TypeSpecType == TST_double) {
1222 // vector long double and vector long long double are never allowed.
1223 // vector double is OK for Power7 and later, and ZVector.
1226 S.Diag(TSWRange.getBegin(),
1227 diag::err_invalid_vector_long_double_decl_spec);
1228 else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
1229 !S.getLangOpts().ZVector)
1230 S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec);
1231 } else if (TypeSpecType == TST_float) {
1232 // vector float is unsupported for ZVector unless we have the
1233 // vector-enhancements facility 1 (ISA revision 12).
1234 if (S.getLangOpts().ZVector &&
1235 !S.Context.getTargetInfo().hasFeature("arch12"))
1236 S.Diag(TSTLoc, diag::err_invalid_vector_float_decl_spec);
1238 // Vector long is unsupported for ZVector, or without VSX, and deprecated
1239 // for AltiVec.
1240 // It has also been historically deprecated on AIX (as an alias for
1241 // "vector int" in both 32-bit and 64-bit modes). It was then made
1242 // unsupported in the Clang-based XL compiler since the deprecated type
1243 // has a number of conflicting semantics and continuing to support it
1244 // is a disservice to users.
1245 if (S.getLangOpts().ZVector ||
1246 !S.Context.getTargetInfo().hasFeature("vsx") ||
1247 S.Context.getTargetInfo().getTriple().isOSAIX())
1248 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec);
1249 else
1250 S.Diag(TSWRange.getBegin(),
1251 diag::warn_vector_long_decl_spec_combination)
1252 << getSpecifierName((TST)TypeSpecType, Policy);
1253 }
1254
1255 if (TypeAltiVecPixel) {
1256 //TODO: perform validation
1257 TypeSpecType = TST_int;
1258 TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unsigned);
1259 TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Short);
1260 TypeSpecOwned = false;
1261 }
1262 }
1263
1264 bool IsFixedPointType =
1265 TypeSpecType == TST_accum || TypeSpecType == TST_fract;
1266
1267 // signed/unsigned are only valid with int/char/wchar_t/_Accum.
1269 if (TypeSpecType == TST_unspecified)
1270 TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
1271 else if (TypeSpecType != TST_int && TypeSpecType != TST_int128 &&
1272 TypeSpecType != TST_char && TypeSpecType != TST_wchar &&
1273 !IsFixedPointType && TypeSpecType != TST_bitint) {
1274 S.Diag(TSSLoc, diag::err_invalid_sign_spec)
1275 << getSpecifierName((TST)TypeSpecType, Policy);
1276 // signed double -> double.
1277 TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unspecified);
1278 }
1279 }
1280
1281 // Validate the width of the type.
1282 switch (getTypeSpecWidth()) {
1284 break;
1285 case TypeSpecifierWidth::Short: // short int
1286 case TypeSpecifierWidth::LongLong: // long long int
1287 if (TypeSpecType == TST_unspecified)
1288 TypeSpecType = TST_int; // short -> short int, long long -> long long int.
1289 else if (!(TypeSpecType == TST_int ||
1290 (IsFixedPointType &&
1292 S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
1293 << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
1294 TypeSpecType = TST_int;
1295 TypeSpecSat = false;
1296 TypeSpecOwned = false;
1297 }
1298 break;
1299 case TypeSpecifierWidth::Long: // long double, long int
1300 if (TypeSpecType == TST_unspecified)
1301 TypeSpecType = TST_int; // long -> long int.
1302 else if (TypeSpecType != TST_int && TypeSpecType != TST_double &&
1303 !IsFixedPointType) {
1304 S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
1305 << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
1306 TypeSpecType = TST_int;
1307 TypeSpecSat = false;
1308 TypeSpecOwned = false;
1309 }
1310 break;
1311 }
1312
1313 // TODO: if the implementation does not implement _Complex, disallow their
1314 // use. Need information about the backend.
1315 if (TypeSpecComplex != TSC_unspecified) {
1316 if (TypeSpecType == TST_unspecified) {
1317 S.Diag(TSCLoc, diag::ext_plain_complex)
1320 " double");
1321 TypeSpecType = TST_double; // _Complex -> _Complex double.
1322 } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
1323 // Note that this intentionally doesn't include _Complex _Bool.
1324 if (!S.getLangOpts().CPlusPlus)
1325 S.Diag(TSTLoc, diag::ext_integer_complex);
1326 } else if (TypeSpecType != TST_float && TypeSpecType != TST_double &&
1327 TypeSpecType != TST_float128 && TypeSpecType != TST_float16 &&
1328 TypeSpecType != TST_ibm128) {
1329 // FIXME: __fp16?
1330 S.Diag(TSCLoc, diag::err_invalid_complex_spec)
1331 << getSpecifierName((TST)TypeSpecType, Policy);
1332 TypeSpecComplex = TSC_unspecified;
1333 }
1334 }
1335
1336 // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and
1337 // _Thread_local can only appear with the 'static' and 'extern' storage class
1338 // specifiers. We also allow __private_extern__ as an extension.
1339 if (ThreadStorageClassSpec != TSCS_unspecified) {
1340 switch (StorageClassSpec) {
1341 case SCS_unspecified:
1342 case SCS_extern:
1343 case SCS_private_extern:
1344 case SCS_static:
1345 break;
1346 default:
1350 diag::err_invalid_decl_spec_combination)
1353 else
1355 diag::err_invalid_decl_spec_combination)
1358 // Discard the thread storage class specifier to recover.
1359 ThreadStorageClassSpec = TSCS_unspecified;
1360 ThreadStorageClassSpecLoc = SourceLocation();
1361 }
1362 if (S.getLangOpts().C23 &&
1364 S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
1367 }
1368 }
1369
1370 if (S.getLangOpts().C23 &&
1372 StorageClassSpec == SCS_extern) {
1373 S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
1376 }
1377
1378 // If no type specifier was provided and we're parsing a language where
1379 // the type specifier is not optional, but we got 'auto' as a storage
1380 // class specifier, then assume this is an attempt to use C++0x's 'auto'
1381 // type specifier.
1382 if (S.getLangOpts().CPlusPlus &&
1383 TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) {
1384 TypeSpecType = TST_auto;
1385 StorageClassSpec = SCS_unspecified;
1386 TSTLoc = TSTNameLoc = StorageClassSpecLoc;
1387 StorageClassSpecLoc = SourceLocation();
1388 }
1389 // Diagnose if we've recovered from an ill-formed 'auto' storage class
1390 // specifier in a pre-C++11 dialect of C++ or in a pre-C23 dialect of C.
1391 if (!S.getLangOpts().CPlusPlus11 && !S.getLangOpts().C23 &&
1392 TypeSpecType == TST_auto)
1393 S.Diag(TSTLoc, diag::ext_auto_type_specifier) << /*C++*/ 0;
1394 if (S.getLangOpts().HLSL &&
1395 S.getLangOpts().getHLSLVersion() < LangOptions::HLSL_202y &&
1396 TypeSpecType == TST_auto)
1397 S.Diag(TSTLoc, diag::ext_hlsl_auto_type_specifier) << /*HLSL*/ 1;
1398 if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11 &&
1399 StorageClassSpec == SCS_auto)
1400 S.Diag(StorageClassSpecLoc, diag::warn_auto_storage_class)
1401 << FixItHint::CreateRemoval(StorageClassSpecLoc);
1402 if (TypeSpecType == TST_char8)
1403 S.Diag(TSTLoc, diag::warn_cxx17_compat_unicode_type);
1404 else if (TypeSpecType == TST_char16 || TypeSpecType == TST_char32)
1405 S.Diag(TSTLoc, diag::warn_cxx98_compat_unicode_type)
1406 << (TypeSpecType == TST_char16 ? "char16_t" : "char32_t");
1408 S.Diag(ConstexprLoc, diag::warn_cxx98_compat_constexpr);
1410 S.Diag(ConstexprLoc, diag::warn_cxx20_compat_consteval);
1412 S.Diag(ConstexprLoc, diag::warn_cxx20_compat_constinit);
1413 // C++ [class.friend]p6:
1414 // No storage-class-specifier shall appear in the decl-specifier-seq
1415 // of a friend declaration.
1416 if (isFriendSpecified() &&
1418 SmallString<32> SpecName;
1419 SourceLocation SCLoc;
1420 FixItHint StorageHint, ThreadHint;
1421
1423 SpecName = getSpecifierName(SC);
1424 SCLoc = getStorageClassSpecLoc();
1425 StorageHint = FixItHint::CreateRemoval(SCLoc);
1426 }
1427
1429 if (!SpecName.empty()) SpecName += " ";
1430 SpecName += getSpecifierName(TSC);
1432 ThreadHint = FixItHint::CreateRemoval(SCLoc);
1433 }
1434
1435 S.Diag(SCLoc, diag::err_friend_decl_spec)
1436 << SpecName << StorageHint << ThreadHint;
1437
1439 }
1440
1441 // C++11 [dcl.fct.spec]p5:
1442 // The virtual specifier shall be used only in the initial
1443 // declaration of a non-static class member function;
1444 // C++11 [dcl.fct.spec]p6:
1445 // The explicit specifier shall be used only in the declaration of
1446 // a constructor or conversion function within its class
1447 // definition;
1449 StringRef Keyword;
1450 FixItHint Hint;
1451 SourceLocation SCLoc;
1452
1453 if (isVirtualSpecified()) {
1454 Keyword = "virtual";
1455 SCLoc = getVirtualSpecLoc();
1456 Hint = FixItHint::CreateRemoval(SCLoc);
1457 } else {
1458 Keyword = "explicit";
1459 SCLoc = getExplicitSpecLoc();
1461 }
1462
1463 S.Diag(SCLoc, diag::err_friend_decl_spec)
1464 << Keyword << Hint;
1465
1466 FS_virtual_specified = false;
1467 FS_explicit_specifier = ExplicitSpecifier();
1468 FS_virtualLoc = FS_explicitLoc = SourceLocation();
1469 }
1470
1471 assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
1472
1473 // Okay, now we can infer the real type.
1474
1475 // TODO: return "auto function" and other bad things based on the real type.
1476
1477 // 'data definition has no type or storage class'?
1478}
1479
1481 TST tst = getTypeSpecType();
1482 return isDeclRep(tst) && getRepAsDecl() != nullptr &&
1483 StorageClassSpec != DeclSpec::SCS_typedef;
1484}
1485
1488 SourceLocation SymbolLocations[3]) {
1490 StartLocation = OperatorLoc;
1491 EndLocation = OperatorLoc;
1492 new (&OperatorFunctionId) struct OFI;
1494 for (unsigned I = 0; I != 3; ++I) {
1495 OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I];
1496
1497 if (SymbolLocations[I].isValid())
1498 EndLocation = SymbolLocations[I];
1499 }
1500}
1501
1503 const char *&PrevSpec) {
1504 if (!FirstLocation.isValid())
1505 FirstLocation = Loc;
1506 LastLocation = Loc;
1507 LastSpecifier = VS;
1508
1509 if (Specifiers & VS) {
1510 PrevSpec = getSpecifierName(VS);
1511 return true;
1512 }
1513
1514 Specifiers |= VS;
1515
1516 switch (VS) {
1517 default: llvm_unreachable("Unknown specifier!");
1518 case VS_Override: VS_overrideLoc = Loc; break;
1519 case VS_GNU_Final:
1520 case VS_Sealed:
1521 case VS_Final: VS_finalLoc = Loc; break;
1522 case VS_Abstract: VS_abstractLoc = Loc; break;
1523 }
1524
1525 return false;
1526}
1527
1529 switch (VS) {
1530 default: llvm_unreachable("Unknown specifier");
1531 case VS_Override: return "override";
1532 case VS_Final: return "final";
1533 case VS_GNU_Final: return "__final";
1534 case VS_Sealed: return "sealed";
1535 case VS_Abstract: return "abstract";
1536 }
1537}
Defines the clang::ASTContext interface.
StringRef P
Expr * E
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1192
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static bool BadSpecifier(T TNew, T TPrev, const char *&PrevSpec, unsigned &DiagID, bool IsExtension=true)
Definition: DeclSpec.cpp:460
Defines the clang::LangOptions interface.
SourceLocation Loc
Definition: SemaObjC.cpp:754
static bool isInvalid(LocType Loc, bool *Invalid)
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TypeLoc interface and its subclasses.
__device__ int
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:859
The result of parsing/analyzing an expression, statement etc.
Definition: Ownership.h:154
PtrTy get() const
Definition: Ownership.h:171
bool isInvalid() const
Definition: Ownership.h:167
bool isUsable() const
Definition: Ownership.h:169
void takeAllFrom(AttributePool &pool)
Take the given pool's allocations and add them to this pool.
Definition: ParsedAttr.h:726
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK)
Returns true if the given operator is implicitly static in a record context.
Definition: DeclCXX.h:2171
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)
Make a nested-name-specifier of the form 'type::'.
Definition: DeclSpec.cpp:51
SourceLocation getLastQualifierNameLoc() const
Retrieve the location of the name in the last qualifier in this nested name specifier.
Definition: DeclSpec.cpp:116
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Definition: DeclSpec.cpp:97
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:75
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition: DeclSpec.cpp:123
void Extend(ASTContext &Context, NamespaceBaseDecl *Namespace, SourceLocation NamespaceLoc, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'name...
Definition: DeclSpec.cpp:62
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:85
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:103
Captures information about "declaration specifiers".
Definition: DeclSpec.h:217
bool isVirtualSpecified() const
Definition: DeclSpec.h:618
bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, ExplicitSpecifier ExplicitSpec, SourceLocation CloseParenLoc)
Definition: DeclSpec.cpp:1047
bool isModulePrivateSpecified() const
Definition: DeclSpec.h:799
static const TSCS TSCS___thread
Definition: DeclSpec.h:236
static const TST TST_typeof_unqualType
Definition: DeclSpec.h:279
bool SetTypePipe(bool isPipe, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:886
static const TST TST_typename
Definition: DeclSpec.h:276
bool hasTypeSpecifier() const
Return true if any type-specifier has been found.
Definition: DeclSpec.h:661
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
Definition: DeclSpec.cpp:619
bool isTypeRep() const
Definition: DeclSpec.h:512
static const TST TST_char8
Definition: DeclSpec.h:252
static const TST TST_BFloat16
Definition: DeclSpec.h:259
void ClearStorageClassSpecs()
Definition: DeclSpec.h:485
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1106
static const TSCS TSCS__Thread_local
Definition: DeclSpec.h:238
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
Definition: DeclSpec.cpp:695
TST getTypeSpecType() const
Definition: DeclSpec.h:507
Decl * DeclRep
Definition: DeclSpec.h:382
SourceLocation getStorageClassSpecLoc() const
Definition: DeclSpec.h:480
SCS getStorageClassSpec() const
Definition: DeclSpec.h:471
bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1094
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:834
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:858
void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack)
Definition: DeclSpec.cpp:966
bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:681
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:945
static const TST TST_auto_type
Definition: DeclSpec.h:289
static const TST TST_interface
Definition: DeclSpec.h:274
static const TST TST_double
Definition: DeclSpec.h:261
static const TST TST_typeofExpr
Definition: DeclSpec.h:278
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
Definition: DeclSpec.h:586
bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:903
bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1081
Expr * ExprRep
Definition: DeclSpec.h:383
static const TST TST_union
Definition: DeclSpec.h:272
static const TST TST_typename_pack_indexing
Definition: DeclSpec.h:283
static const TST TST_char
Definition: DeclSpec.h:250
static const TST TST_bool
Definition: DeclSpec.h:267
static const TST TST_char16
Definition: DeclSpec.h:253
SCS
storage-class-specifier
Definition: DeclSpec.h:221
SourceLocation getExplicitSpecLoc() const
Definition: DeclSpec.h:624
static const TST TST_unknown_anytype
Definition: DeclSpec.h:290
static const TST TST_int
Definition: DeclSpec.h:255
void forEachCVRUQualifier(llvm::function_ref< void(TQ, StringRef, SourceLocation)> Handle)
This method calls the passed in handler on each CVRU qual being set.
Definition: DeclSpec.cpp:415
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:712
bool isMissingDeclaratorOk()
Checks if this DeclSpec can stand alone, without a Declarator.
Definition: DeclSpec.cpp:1480
ParsedType getRepAsType() const
Definition: DeclSpec.h:517
TSCS getThreadStorageClassSpec() const
Definition: DeclSpec.h:472
bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1066
static const TST TST_accum
Definition: DeclSpec.h:263
static const TST TST_half
Definition: DeclSpec.h:258
ParsedAttributes & getAttributes()
Definition: DeclSpec.h:843
UnionParsedType TypeRep
Definition: DeclSpec.h:381
SourceRange getExplicitSpecRange() const
Definition: DeclSpec.h:625
static const TST TST_ibm128
Definition: DeclSpec.h:266
Expr * getRepAsExpr() const
Definition: DeclSpec.h:525
static const TST TST_enum
Definition: DeclSpec.h:271
bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:920
AttributePool & getAttributePool() const
Definition: DeclSpec.h:816
static const TST TST_float128
Definition: DeclSpec.h:265
static const TST TST_decltype
Definition: DeclSpec.h:281
static bool isDeclRep(TST T)
Definition: DeclSpec.h:439
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Complex" (la...
Definition: DeclSpec.cpp:1128
static const TST TST_typeof_unqualExpr
Definition: DeclSpec.h:280
static const TST TST_class
Definition: DeclSpec.h:275
bool hasTagDefinition() const
Definition: DeclSpec.cpp:433
static const TST TST_decimal64
Definition: DeclSpec.h:269
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
Definition: DeclSpec.cpp:442
bool SetTypeQual(TQ T, SourceLocation Loc)
Definition: DeclSpec.cpp:991
static const TST TST_wchar
Definition: DeclSpec.h:251
SourceLocation getTypeSpecComplexLoc() const
Definition: DeclSpec.h:550
static const TST TST_void
Definition: DeclSpec.h:249
static const TSCS TSCS_unspecified
Definition: DeclSpec.h:235
static const TST TST_bitint
Definition: DeclSpec.h:257
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
Definition: DeclSpec.cpp:532
static const TST TST_float
Definition: DeclSpec.h:260
static const TST TST_atomic
Definition: DeclSpec.h:291
static const TST TST_fract
Definition: DeclSpec.h:264
bool SetTypeSpecError()
Definition: DeclSpec.cpp:937
SourceLocation getThreadStorageClassSpecLoc() const
Definition: DeclSpec.h:481
Decl * getRepAsDecl() const
Definition: DeclSpec.h:521
static const TST TST_float16
Definition: DeclSpec.h:262
static const TST TST_unspecified
Definition: DeclSpec.h:248
SourceLocation getVirtualSpecLoc() const
Definition: DeclSpec.h:619
TypeSpecifierSign getTypeSpecSign() const
Definition: DeclSpec.h:504
bool isEmpty() const
isEmpty - Return true if this declaration specifier is completely empty: no tokens were parsed in the...
Definition: DeclSpec.h:674
static const TST TST_decltype_auto
Definition: DeclSpec.h:282
static const TSCS TSCS_thread_local
Definition: DeclSpec.h:237
static const TST TST_error
Definition: DeclSpec.h:298
void forEachQualifier(llvm::function_ref< void(TQ, StringRef, SourceLocation)> Handle)
This method calls the passed in handler on each qual being set.
Definition: DeclSpec.cpp:427
bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1032
static const TST TST_decimal32
Definition: DeclSpec.h:268
bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:871
TypeSpecifierWidth getTypeSpecWidth() const
Definition: DeclSpec.h:500
static const TST TST_char32
Definition: DeclSpec.h:254
bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1006
static const TST TST_decimal128
Definition: DeclSpec.h:270
static const TST TST_int128
Definition: DeclSpec.h:256
FriendSpecified isFriendSpecified() const
Definition: DeclSpec.h:791
bool hasExplicitSpecifier() const
Definition: DeclSpec.h:621
bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1020
static const TST TST_typeofType
Definition: DeclSpec.h:277
TemplateIdAnnotation * TemplateIdRep
Definition: DeclSpec.h:384
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:722
static const TST TST_auto
Definition: DeclSpec.h:288
@ PQ_FunctionSpecifier
Definition: DeclSpec.h:319
@ PQ_StorageClassSpecifier
Definition: DeclSpec.h:316
ConstexprSpecKind getConstexprSpecifier() const
Definition: DeclSpec.h:802
static const TST TST_struct
Definition: DeclSpec.h:273
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1874
bool isDeclarationOfFunction() const
Determine whether the declaration that will be produced from this declaration will be a function.
Definition: DeclSpec.cpp:296
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:2021
void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
Definition: DeclSpec.h:2313
bool isFunctionDeclarator() const
isFunctionDeclarator - Once this declarator is fully parsed and formed, this method returns true if t...
Definition: DeclSpec.h:2454
void setDecompositionBindings(SourceLocation LSquareLoc, MutableArrayRef< DecompositionDeclarator::Binding > Bindings, SourceLocation RSquareLoc)
Set the decomposition bindings for this declarator.
Definition: DeclSpec.cpp:265
DeclaratorChunk::ParamInfo InlineParams[16]
InlineParams - This is a local array used for the first function decl chunk to avoid going to the hea...
Definition: DeclSpec.h:1961
DeclaratorContext getContext() const
Definition: DeclSpec.h:2046
bool isCtorOrDtor()
Returns true if this declares a constructor or a destructor.
Definition: DeclSpec.cpp:410
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
Definition: DeclSpec.h:2040
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
Definition: DeclSpec.h:2294
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
The template parameter lists that preceded the declarator.
Definition: DeclSpec.h:2623
bool isExplicitObjectMemberFunction()
Definition: DeclSpec.cpp:398
bool isStaticMember()
Returns true if this declares a static member.
Definition: DeclSpec.cpp:389
DecompositionDeclarator::Binding InlineBindings[16]
Definition: DeclSpec.h:1962
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
Definition: DeclSpec.h:2461
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1924
const Expr * getExpr() const
Definition: DeclCXX.h:1933
This represents one expression.
Definition: Expr.h:112
QualType getType() const
Definition: Expr.h:144
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:78
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:128
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:102
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
Definition: LangOptions.cpp:65
Holds a QualType and a TypeSourceInfo* that came out of a declarator parsing.
Definition: LocInfoType.h:28
This represents a decl that may have a name.
Definition: Decl.h:273
Represents C++ namespaces and their aliases.
Definition: Decl.h:572
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)
Make a nested-name-specifier of the form 'type::'.
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
void Clear()
Clear out this builder, and prepare it to build another nested-name-specifier with source-location in...
NestedNameSpecifierLoc getTemporary() const
Retrieve a nested-name-specifier with location information based on the information in this builder.
void Extend(ASTContext &Context, const NamespaceBaseDecl *Namespace, SourceLocation NamespaceLoc, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'name...
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covered by this nested-name-specifier.
NestedNameSpecifier getRepresentation() const
Retrieve the representation of the nested-name-specifier.
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
PtrTy get() const
Definition: Ownership.h:81
static OpaquePtr make(QualType P)
Definition: Ownership.h:61
bool isAvailableOption(llvm::StringRef Ext, const LangOptions &LO) const
QualType getPattern() const
Definition: TypeBase.h:6331
Expr * getIndexExpr() const
Definition: TypeBase.h:6330
bool hasAttribute(ParsedAttr::Kind K) const
Definition: ParsedAttr.h:897
SizeType size() const
Definition: ParsedAttr.h:823
void takeAllFrom(ParsedAttributes &Other)
Definition: ParsedAttr.h:946
A (possibly-)qualified type.
Definition: TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: TypeBase.h:1004
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:61
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:850
ASTContext & Context
Definition: Sema.h:1276
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:83
const LangOptions & getLangOpts() const
Definition: Sema.h:911
SourceManager & getSourceManager() const
Definition: Sema.h:916
OpenCLOptions & getOpenCLOptions()
Definition: Sema.h:912
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
void setEnd(SourceLocation e)
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1288
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
Definition: TargetInfo.h:1526
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:193
bool isFunctionType() const
Definition: TypeBase.h:8576
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
Definition: DeclSpec.h:1030
SourceLocation EndLocation
The location of the last token that describes this unqualified-id.
Definition: DeclSpec.h:1059
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
Definition: DeclSpec.cpp:1486
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
Definition: DeclSpec.h:1074
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
Definition: DeclSpec.cpp:29
void setConstructorTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id that names a constructor.
Definition: DeclSpec.cpp:40
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
Definition: DeclSpec.h:1056
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
Definition: DeclSpec.h:1080
TemplateIdAnnotation * TemplateId
When Kind == IK_TemplateId or IK_ConstructorTemplateId, the template-id annotation that contains the ...
Definition: DeclSpec.h:1050
static const char * getSpecifierName(Specifier VS)
Definition: DeclSpec.cpp:1528
bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec)
Definition: DeclSpec.cpp:1502
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
TypeSpecifierType
Specifies the kind of type.
Definition: Specifiers.h:55
@ TST_typeof_unqualType
Definition: Specifiers.h:87
@ TST_ibm128
Definition: Specifiers.h:74
@ TST_decimal64
Definition: Specifiers.h:77
@ TST_float
Definition: Specifiers.h:71
@ TST_auto_type
Definition: Specifiers.h:94
@ TST_auto
Definition: Specifiers.h:92
@ TST_typeof_unqualExpr
Definition: Specifiers.h:88
@ TST_decimal32
Definition: Specifiers.h:76
@ TST_int128
Definition: Specifiers.h:64
@ TST_atomic
Definition: Specifiers.h:96
@ TST_half
Definition: Specifiers.h:66
@ TST_decltype
Definition: Specifiers.h:89
@ TST_typename_pack_indexing
Definition: Specifiers.h:97
@ TST_char32
Definition: Specifiers.h:62
@ TST_struct
Definition: Specifiers.h:81
@ TST_typeofType
Definition: Specifiers.h:85
@ TST_bitint
Definition: Specifiers.h:65
@ TST_wchar
Definition: Specifiers.h:59
@ TST_BFloat16
Definition: Specifiers.h:70
@ TST_char16
Definition: Specifiers.h:61
@ TST_char
Definition: Specifiers.h:58
@ TST_unspecified
Definition: Specifiers.h:56
@ TST_class
Definition: Specifiers.h:82
@ TST_union
Definition: Specifiers.h:80
@ TST_Fract
Definition: Specifiers.h:69
@ TST_float128
Definition: Specifiers.h:73
@ TST_double
Definition: Specifiers.h:72
@ TST_Accum
Definition: Specifiers.h:68
@ TST_int
Definition: Specifiers.h:63
@ TST_bool
Definition: Specifiers.h:75
@ TST_typeofExpr
Definition: Specifiers.h:86
@ TST_typename
Definition: Specifiers.h:84
@ TST_void
Definition: Specifiers.h:57
@ TST_unknown_anytype
Definition: Specifiers.h:95
@ TST_enum
Definition: Specifiers.h:79
@ TST_error
Definition: Specifiers.h:104
@ TST_decltype_auto
Definition: Specifiers.h:93
@ TST_interface
Definition: Specifiers.h:83
@ TST_Float16
Definition: Specifiers.h:67
@ TST_char8
Definition: Specifiers.h:60
@ TST_decimal128
Definition: Specifiers.h:78
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition: Specifiers.h:35
@ IK_TemplateId
A template-id, e.g., f<int>.
@ IK_ConstructorTemplateId
A constructor named via a template-id.
@ IK_ConstructorName
A constructor name.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition: Specifiers.h:235
@ Keyword
The name has been typo-corrected to a keyword.
TypeSpecifierWidth
Specifies the width of a type, e.g., short, long, or long long.
Definition: Specifiers.h:47
TypeSpecifierSign
Specifies the signedness of a type, e.g., signed or unsigned.
Definition: Specifiers.h:50
const FunctionProtoType * T
@ Other
Other implicit parameter.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_Unparsed
not parsed yet
@ EST_None
no exception specification
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
unsigned isVariadic
isVariadic - If this function has a prototype, and if that proto ends with ',...)',...
Definition: DeclSpec.h:1338
CachedTokens * ExceptionSpecTokens
Pointer to the cached tokens for an exception-specification that has not yet been parsed.
Definition: DeclSpec.h:1418
SourceLocation MutableLoc
The location of the 'mutable' qualifer in a lambda-declarator, if any.
Definition: DeclSpec.h:1387
UnionParsedType TrailingReturnType
If HasTrailingReturnType is true, this is the trailing return type specified.
Definition: DeclSpec.h:1428
TypeAndRange * Exceptions
Pointer to a new[]'d array of TypeAndRange objects that contain the types in the function's dynamic e...
Definition: DeclSpec.h:1410
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
Definition: DeclSpec.h:1398
unsigned RefQualifierIsLValueRef
Whether the ref-qualifier (if any) is an lvalue reference.
Definition: DeclSpec.h:1347
NamedDecl ** DeclsInPrototype
Pointer to a new[]'d array of declarations that need to be available for lookup inside the function b...
Definition: DeclSpec.h:1423
AttributeFactory * QualAttrFactory
AttributeFactory for the MethodQualifiers.
Definition: DeclSpec.h:1404
SourceLocation ExceptionSpecLocEnd
The end location of the exception specification, if any.
Definition: DeclSpec.h:1393
SourceLocation EllipsisLoc
When isVariadic is true, the location of the ellipsis in the source.
Definition: DeclSpec.h:1366
unsigned DeleteParams
DeleteParams - If this is true, we need to delete[] Params.
Definition: DeclSpec.h:1355
DeclSpec * MethodQualifiers
DeclSpec for the function with the qualifier related info.
Definition: DeclSpec.h:1401
unsigned NumExceptionsOrDecls
NumExceptionsOrDecls - This is the number of types in the dynamic-exception-decl, if the function has...
Definition: DeclSpec.h:1378
SourceLocation RefQualifierLoc
The location of the ref-qualifier, if any.
Definition: DeclSpec.h:1383
SourceLocation RParenLoc
The location of the right parenthesis in the source.
Definition: DeclSpec.h:1369
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1373
unsigned HasTrailingReturnType
HasTrailingReturnType - If this is true, a trailing return type was specified.
Definition: DeclSpec.h:1360
unsigned isAmbiguous
Can this declaration be a constructor-style initializer?
Definition: DeclSpec.h:1342
unsigned hasPrototype
hasPrototype - This is true if the function had at least one typed parameter.
Definition: DeclSpec.h:1332
SourceLocation LParenLoc
The location of the left parenthesis in the source.
Definition: DeclSpec.h:1363
unsigned ExceptionSpecType
ExceptionSpecType - An ExceptionSpecificationType value.
Definition: DeclSpec.h:1351
SourceLocation ExceptionSpecLocBeg
The beginning location of the exception specification, if any.
Definition: DeclSpec.h:1390
SourceLocation TrailingReturnTypeLoc
If HasTrailingReturnType is true, this is the location of the trailing return type.
Definition: DeclSpec.h:1432
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
Definition: DeclSpec.h:1414
ParamInfo - An array of paraminfo objects is allocated whenever a function declarator is parsed.
Definition: DeclSpec.h:1303
One instance of this struct is used for each type in a declarator that is parsed.
Definition: DeclSpec.h:1221
SourceLocation EndLoc
EndLoc - If valid, the place where this chunck ends.
Definition: DeclSpec.h:1231
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
Definition: DeclSpec.cpp:132
SourceLocation Loc
Loc - The place where this type was defined.
Definition: DeclSpec.h:1229
FunctionTypeInfo Fun
Definition: DeclSpec.h:1612
enum clang::DeclaratorChunk::@211 Kind
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
unsigned Bool
Whether we can use 'bool' rather than '_Bool' (even if the language doesn't actually have 'bool',...
unsigned MSWChar
When true, print the built-in wchar_t type as __wchar_t.
Information about a template-id annotation token.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
SourceLocation SymbolLocations[3]
The source locations of the individual tokens that name the operator, e.g., the "new",...
Definition: DeclSpec.h:1018
OverloadedOperatorKind Operator
The kind of overloaded operator.
Definition: DeclSpec.h:1009