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