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