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"
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_move(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:
378#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
379#include "clang/Basic/OpenCLImageTypes.def"
380#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
381#include "clang/Basic/HLSLIntangibleTypes.def"
382 return false;
383
385 // This must have an initializer, so can't be a function declaration,
386 // even if the initializer has function type.
387 return false;
388
389 case TST_decltype:
391 case TST_typeofExpr:
392 if (Expr *E = DS.getRepAsExpr())
393 return E->getType()->isFunctionType();
394 return false;
395
396#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case TST_##Trait:
397#include "clang/Basic/TransformTypeTraits.def"
398 case TST_typename:
400 case TST_typeofType: {
401 QualType QT = DS.getRepAsType().get();
402 if (QT.isNull())
403 return false;
404
405 if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
406 QT = LIT->getType();
407
408 if (QT.isNull())
409 return false;
410
411 return QT->isFunctionType();
412 }
413 }
414
415 llvm_unreachable("Invalid TypeSpecType!");
416}
417
424 getName().OperatorFunctionId.Operator));
425}
426
429 return false;
431 if (Fun.NumParams) {
432 auto *P = dyn_cast_or_null<ParmVarDecl>(Fun.Params[0].Param);
433 if (P && P->isExplicitObjectParameter())
434 return true;
435 }
436 return false;
437}
438
442}
443
445 llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) {
446 if (TypeQualifiers & TQ_const)
447 Handle(TQ_const, "const", TQ_constLoc);
448 if (TypeQualifiers & TQ_volatile)
449 Handle(TQ_volatile, "volatile", TQ_volatileLoc);
450 if (TypeQualifiers & TQ_restrict)
451 Handle(TQ_restrict, "restrict", TQ_restrictLoc);
452 if (TypeQualifiers & TQ_unaligned)
453 Handle(TQ_unaligned, "unaligned", TQ_unalignedLoc);
454}
455
457 llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) {
458 forEachCVRUQualifier(Handle);
459 // FIXME: Add code below to iterate through the attributes and call Handle.
460}
461
463 if (!TypeSpecOwned)
464 return false;
465 return cast<TagDecl>(getRepAsDecl())->isCompleteDefinition();
466}
467
468/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
469/// declaration specifier includes.
470///
472 unsigned Res = 0;
473 if (StorageClassSpec != SCS_unspecified ||
474 ThreadStorageClassSpec != TSCS_unspecified)
476
477 if (TypeQualifiers != TQ_unspecified)
478 Res |= PQ_TypeQualifier;
479
480 if (hasTypeSpecifier())
481 Res |= PQ_TypeSpecifier;
482
483 if (FS_inline_specified || FS_virtual_specified || hasExplicitSpecifier() ||
484 FS_noreturn_specified || FS_forceinline_specified)
486 return Res;
487}
488
489template <class T> static bool BadSpecifier(T TNew, T TPrev,
490 const char *&PrevSpec,
491 unsigned &DiagID,
492 bool IsExtension = true) {
493 PrevSpec = DeclSpec::getSpecifierName(TPrev);
494 if (TNew != TPrev)
495 DiagID = diag::err_invalid_decl_spec_combination;
496 else
497 DiagID = IsExtension ? diag::ext_warn_duplicate_declspec :
498 diag::warn_duplicate_declspec;
499 return true;
500}
501
503 switch (S) {
504 case DeclSpec::SCS_unspecified: return "unspecified";
505 case DeclSpec::SCS_typedef: return "typedef";
506 case DeclSpec::SCS_extern: return "extern";
507 case DeclSpec::SCS_static: return "static";
508 case DeclSpec::SCS_auto: return "auto";
509 case DeclSpec::SCS_register: return "register";
510 case DeclSpec::SCS_private_extern: return "__private_extern__";
511 case DeclSpec::SCS_mutable: return "mutable";
512 }
513 llvm_unreachable("Unknown typespec!");
514}
515
517 switch (S) {
518 case DeclSpec::TSCS_unspecified: return "unspecified";
519 case DeclSpec::TSCS___thread: return "__thread";
520 case DeclSpec::TSCS_thread_local: return "thread_local";
521 case DeclSpec::TSCS__Thread_local: return "_Thread_local";
522 }
523 llvm_unreachable("Unknown typespec!");
524}
525
527 switch (W) {
529 return "unspecified";
531 return "short";
533 return "long";
535 return "long long";
536 }
537 llvm_unreachable("Unknown typespec!");
538}
539
541 switch (C) {
542 case TSC_unspecified: return "unspecified";
543 case TSC_imaginary: return "imaginary";
544 case TSC_complex: return "complex";
545 }
546 llvm_unreachable("Unknown typespec!");
547}
548
550 switch (S) {
552 return "unspecified";
554 return "signed";
556 return "unsigned";
557 }
558 llvm_unreachable("Unknown typespec!");
559}
560
562 const PrintingPolicy &Policy) {
563 switch (T) {
564 case DeclSpec::TST_unspecified: return "unspecified";
565 case DeclSpec::TST_void: return "void";
566 case DeclSpec::TST_char: return "char";
567 case DeclSpec::TST_wchar: return Policy.MSWChar ? "__wchar_t" : "wchar_t";
568 case DeclSpec::TST_char8: return "char8_t";
569 case DeclSpec::TST_char16: return "char16_t";
570 case DeclSpec::TST_char32: return "char32_t";
571 case DeclSpec::TST_int: return "int";
572 case DeclSpec::TST_int128: return "__int128";
573 case DeclSpec::TST_bitint: return "_BitInt";
574 case DeclSpec::TST_half: return "half";
575 case DeclSpec::TST_float: return "float";
576 case DeclSpec::TST_double: return "double";
577 case DeclSpec::TST_accum: return "_Accum";
578 case DeclSpec::TST_fract: return "_Fract";
579 case DeclSpec::TST_float16: return "_Float16";
580 case DeclSpec::TST_float128: return "__float128";
581 case DeclSpec::TST_ibm128: return "__ibm128";
582 case DeclSpec::TST_bool: return Policy.Bool ? "bool" : "_Bool";
583 case DeclSpec::TST_decimal32: return "_Decimal32";
584 case DeclSpec::TST_decimal64: return "_Decimal64";
585 case DeclSpec::TST_decimal128: return "_Decimal128";
586 case DeclSpec::TST_enum: return "enum";
587 case DeclSpec::TST_class: return "class";
588 case DeclSpec::TST_union: return "union";
589 case DeclSpec::TST_struct: return "struct";
590 case DeclSpec::TST_interface: return "__interface";
591 case DeclSpec::TST_typename: return "type-name";
593 return "type-name-pack-indexing";
595 case DeclSpec::TST_typeofExpr: return "typeof";
597 case DeclSpec::TST_typeof_unqualExpr: return "typeof_unqual";
598 case DeclSpec::TST_auto: return "auto";
599 case DeclSpec::TST_auto_type: return "__auto_type";
600 case DeclSpec::TST_decltype: return "(decltype)";
601 case DeclSpec::TST_decltype_auto: return "decltype(auto)";
602#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
603 case DeclSpec::TST_##Trait: \
604 return "__" #Trait;
605#include "clang/Basic/TransformTypeTraits.def"
606 case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
607 case DeclSpec::TST_atomic: return "_Atomic";
608 case DeclSpec::TST_BFloat16: return "__bf16";
609#define GENERIC_IMAGE_TYPE(ImgType, Id) \
610 case DeclSpec::TST_##ImgType##_t: \
611 return #ImgType "_t";
612#include "clang/Basic/OpenCLImageTypes.def"
613#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
614 case DeclSpec::TST_##Name: \
615 return #Name;
616#include "clang/Basic/HLSLIntangibleTypes.def"
617 case DeclSpec::TST_error: return "(error)";
618 }
619 llvm_unreachable("Unknown typespec!");
620}
621
623 switch (C) {
625 return "unspecified";
627 return "constexpr";
629 return "consteval";
631 return "constinit";
632 }
633 llvm_unreachable("Unknown ConstexprSpecKind");
634}
635
637 switch (T) {
638 case DeclSpec::TQ_unspecified: return "unspecified";
639 case DeclSpec::TQ_const: return "const";
640 case DeclSpec::TQ_restrict: return "restrict";
641 case DeclSpec::TQ_volatile: return "volatile";
642 case DeclSpec::TQ_atomic: return "_Atomic";
643 case DeclSpec::TQ_unaligned: return "__unaligned";
644 }
645 llvm_unreachable("Unknown typespec!");
646}
647
649 const char *&PrevSpec,
650 unsigned &DiagID,
651 const PrintingPolicy &Policy) {
652 // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class
653 // specifiers are not supported.
654 // It seems sensible to prohibit private_extern too
655 // The cl_clang_storage_class_specifiers extension enables support for
656 // these storage-class specifiers.
657 // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class
658 // specifiers are not supported."
659 if (S.getLangOpts().OpenCL &&
661 "cl_clang_storage_class_specifiers", S.getLangOpts())) {
662 switch (SC) {
663 case SCS_extern:
665 case SCS_static:
666 if (S.getLangOpts().getOpenCLCompatibleVersion() < 120) {
667 DiagID = diag::err_opencl_unknown_type_specifier;
668 PrevSpec = getSpecifierName(SC);
669 return true;
670 }
671 break;
672 case SCS_auto:
673 case SCS_register:
674 DiagID = diag::err_opencl_unknown_type_specifier;
675 PrevSpec = getSpecifierName(SC);
676 return true;
677 default:
678 break;
679 }
680 }
681
682 if (StorageClassSpec != SCS_unspecified) {
683 // Maybe this is an attempt to use C++11 'auto' outside of C++11 mode.
684 bool isInvalid = true;
685 if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) {
686 if (SC == SCS_auto)
687 return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID, Policy);
688 if (StorageClassSpec == SCS_auto) {
689 isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc,
690 PrevSpec, DiagID, Policy);
691 assert(!isInvalid && "auto SCS -> TST recovery failed");
692 }
693 }
694
695 // Changing storage class is allowed only if the previous one
696 // was the 'extern' that is part of a linkage specification and
697 // the new storage class is 'typedef'.
698 if (isInvalid &&
699 !(SCS_extern_in_linkage_spec &&
700 StorageClassSpec == SCS_extern &&
701 SC == SCS_typedef))
702 return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID);
703 }
704 StorageClassSpec = SC;
705 StorageClassSpecLoc = Loc;
706 assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
707 return false;
708}
709
711 const char *&PrevSpec,
712 unsigned &DiagID) {
713 if (ThreadStorageClassSpec != TSCS_unspecified)
714 return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID);
715
716 ThreadStorageClassSpec = TSC;
717 ThreadStorageClassSpecLoc = Loc;
718 return false;
719}
720
721/// These methods set the specified attribute of the DeclSpec, but return true
722/// and ignore the request if invalid (e.g. "extern" then "auto" is
723/// specified).
725 const char *&PrevSpec, unsigned &DiagID,
726 const PrintingPolicy &Policy) {
727 // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that
728 // for 'long long' we will keep the source location of the first 'long'.
730 TSWRange.setBegin(Loc);
731 // Allow turning long -> long long.
732 else if (W != TypeSpecifierWidth::LongLong ||
734 return BadSpecifier(W, getTypeSpecWidth(), PrevSpec, DiagID);
735 TypeSpecWidth = static_cast<unsigned>(W);
736 // Remember location of the last 'long'
737 TSWRange.setEnd(Loc);
738 return false;
739}
740
742 const char *&PrevSpec,
743 unsigned &DiagID) {
744 if (TypeSpecComplex != TSC_unspecified)
745 return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
746 TypeSpecComplex = C;
747 TSCLoc = Loc;
748 return false;
749}
750
752 const char *&PrevSpec, unsigned &DiagID) {
754 return BadSpecifier(S, getTypeSpecSign(), PrevSpec, DiagID);
755 TypeSpecSign = static_cast<unsigned>(S);
756 TSSLoc = Loc;
757 return false;
758}
759
761 const char *&PrevSpec,
762 unsigned &DiagID,
763 ParsedType Rep,
764 const PrintingPolicy &Policy) {
765 return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Policy);
766}
767
769 SourceLocation TagNameLoc,
770 const char *&PrevSpec,
771 unsigned &DiagID,
772 ParsedType Rep,
773 const PrintingPolicy &Policy) {
774 assert(isTypeRep(T) && "T does not store a type");
775 assert(Rep && "no type 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 TypeRep = Rep;
785 TSTLoc = TagKwLoc;
786 TSTNameLoc = TagNameLoc;
787 TypeSpecOwned = false;
788
790 // we got there from a an annotation. Reconstruct the type
791 // Ugly...
792 QualType QT = Rep.get();
793 const PackIndexingType *LIT = cast<PackIndexingType>(QT);
796 }
797 return false;
798}
799
801 const char *&PrevSpec,
802 unsigned &DiagID,
803 Expr *Rep,
804 const PrintingPolicy &Policy) {
805 assert(isExprRep(T) && "T does not store an expr");
806 assert(Rep && "no expression provided!");
807 if (TypeSpecType == TST_error)
808 return false;
809 if (TypeSpecType != TST_unspecified) {
810 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
811 DiagID = diag::err_invalid_decl_spec_combination;
812 return true;
813 }
814 TypeSpecType = T;
815 ExprRep = Rep;
816 TSTLoc = Loc;
817 TSTNameLoc = Loc;
818 TypeSpecOwned = false;
819 return false;
820}
821
823 const char *&PrevSpec,
824 unsigned &DiagID,
825 Decl *Rep, bool Owned,
826 const PrintingPolicy &Policy) {
827 return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned, Policy);
828}
829
831 SourceLocation TagNameLoc,
832 const char *&PrevSpec,
833 unsigned &DiagID,
834 Decl *Rep, bool Owned,
835 const PrintingPolicy &Policy) {
836 assert(isDeclRep(T) && "T does not store a decl");
837 // Unlike the other cases, we don't assert that we actually get a decl.
838
839 if (TypeSpecType == TST_error)
840 return false;
841 if (TypeSpecType != TST_unspecified) {
842 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
843 DiagID = diag::err_invalid_decl_spec_combination;
844 return true;
845 }
846 TypeSpecType = T;
847 DeclRep = Rep;
848 TSTLoc = TagKwLoc;
849 TSTNameLoc = TagNameLoc;
850 TypeSpecOwned = Owned && Rep != nullptr;
851 return false;
852}
853
854bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
855 unsigned &DiagID, TemplateIdAnnotation *Rep,
856 const PrintingPolicy &Policy) {
857 assert(T == TST_auto || T == TST_decltype_auto);
858 ConstrainedAuto = true;
859 TemplateIdRep = Rep;
860 return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Policy);
861}
862
864 const char *&PrevSpec,
865 unsigned &DiagID,
866 const PrintingPolicy &Policy) {
867 assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) &&
868 "rep required for these type-spec kinds!");
869 if (TypeSpecType == TST_error)
870 return false;
871 if (TypeSpecType != TST_unspecified) {
872 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
873 DiagID = diag::err_invalid_decl_spec_combination;
874 return true;
875 }
876 TSTLoc = Loc;
877 TSTNameLoc = Loc;
878 if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) {
879 TypeAltiVecBool = true;
880 return false;
881 }
882 TypeSpecType = T;
883 TypeSpecOwned = false;
884 return false;
885}
886
887bool DeclSpec::SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
888 unsigned &DiagID) {
889 // Cannot set twice
890 if (TypeSpecSat) {
891 DiagID = diag::warn_duplicate_declspec;
892 PrevSpec = "_Sat";
893 return true;
894 }
895 TypeSpecSat = true;
896 TSSatLoc = Loc;
897 return false;
898}
899
901 const char *&PrevSpec, unsigned &DiagID,
902 const PrintingPolicy &Policy) {
903 if (TypeSpecType == TST_error)
904 return false;
905 if (TypeSpecType != TST_unspecified) {
906 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
907 DiagID = diag::err_invalid_vector_decl_spec_combination;
908 return true;
909 }
910 TypeAltiVecVector = isAltiVecVector;
911 AltiVecLoc = Loc;
912 return false;
913}
914
916 const char *&PrevSpec, unsigned &DiagID,
917 const PrintingPolicy &Policy) {
918 if (TypeSpecType == TST_error)
919 return false;
920 if (TypeSpecType != TST_unspecified) {
921 PrevSpec = DeclSpec::getSpecifierName((TST)TypeSpecType, Policy);
922 DiagID = diag::err_invalid_decl_spec_combination;
923 return true;
924 }
925
926 if (isPipe) {
927 TypeSpecPipe = static_cast<unsigned>(TypeSpecifiersPipe::Pipe);
928 }
929 return false;
930}
931
933 const char *&PrevSpec, unsigned &DiagID,
934 const PrintingPolicy &Policy) {
935 if (TypeSpecType == TST_error)
936 return false;
937 if (!TypeAltiVecVector || TypeAltiVecPixel ||
938 (TypeSpecType != TST_unspecified)) {
939 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
940 DiagID = diag::err_invalid_pixel_decl_spec_combination;
941 return true;
942 }
943 TypeAltiVecPixel = isAltiVecPixel;
944 TSTLoc = Loc;
945 TSTNameLoc = Loc;
946 return false;
947}
948
950 const char *&PrevSpec, unsigned &DiagID,
951 const PrintingPolicy &Policy) {
952 if (TypeSpecType == TST_error)
953 return false;
954 if (!TypeAltiVecVector || TypeAltiVecBool ||
955 (TypeSpecType != TST_unspecified)) {
956 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
957 DiagID = diag::err_invalid_vector_bool_decl_spec;
958 return true;
959 }
960 TypeAltiVecBool = isAltiVecBool;
961 TSTLoc = Loc;
962 TSTNameLoc = Loc;
963 return false;
964}
965
967 TypeSpecType = TST_error;
968 TypeSpecOwned = false;
969 TSTLoc = SourceLocation();
970 TSTNameLoc = SourceLocation();
971 return false;
972}
973
975 const char *&PrevSpec, unsigned &DiagID,
976 const PrintingPolicy &Policy) {
977 assert(BitsExpr && "no expression provided!");
978 if (TypeSpecType == TST_error)
979 return false;
980
981 if (TypeSpecType != TST_unspecified) {
982 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
983 DiagID = diag::err_invalid_decl_spec_combination;
984 return true;
985 }
986
987 TypeSpecType = TST_bitint;
988 ExprRep = BitsExpr;
989 TSTLoc = KWLoc;
990 TSTNameLoc = KWLoc;
991 TypeSpecOwned = false;
992 return false;
993}
994
996 Expr *IndexingExpr) {
997 assert(TypeSpecType == TST_typename &&
998 "pack indexing can only be applied to typename");
999 TypeSpecType = TST_typename_pack_indexing;
1000 PackIndexingExpr = IndexingExpr;
1001 this->EllipsisLoc = EllipsisLoc;
1002}
1003
1004bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
1005 unsigned &DiagID, const LangOptions &Lang) {
1006 // Duplicates are permitted in C99 onwards, but are not permitted in C89 or
1007 // C++. However, since this is likely not what the user intended, we will
1008 // always warn. We do not need to set the qualifier's location since we
1009 // already have it.
1010 if (TypeQualifiers & T) {
1011 bool IsExtension = true;
1012 if (Lang.C99)
1013 IsExtension = false;
1014 return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension);
1015 }
1016
1017 return SetTypeQual(T, Loc);
1018}
1019
1021 TypeQualifiers |= T;
1022
1023 switch (T) {
1024 case TQ_unspecified: break;
1025 case TQ_const: TQ_constLoc = Loc; return false;
1026 case TQ_restrict: TQ_restrictLoc = Loc; return false;
1027 case TQ_volatile: TQ_volatileLoc = Loc; return false;
1028 case TQ_unaligned: TQ_unalignedLoc = Loc; return false;
1029 case TQ_atomic: TQ_atomicLoc = Loc; return false;
1030 }
1031
1032 llvm_unreachable("Unknown type qualifier!");
1033}
1034
1036 unsigned &DiagID) {
1037 // 'inline inline' is ok. However, since this is likely not what the user
1038 // intended, we will always warn, similar to duplicates of type qualifiers.
1039 if (FS_inline_specified) {
1040 DiagID = diag::warn_duplicate_declspec;
1041 PrevSpec = "inline";
1042 return true;
1043 }
1044 FS_inline_specified = true;
1045 FS_inlineLoc = Loc;
1046 return false;
1047}
1048
1050 unsigned &DiagID) {
1051 if (FS_forceinline_specified) {
1052 DiagID = diag::warn_duplicate_declspec;
1053 PrevSpec = "__forceinline";
1054 return true;
1055 }
1056 FS_forceinline_specified = true;
1057 FS_forceinlineLoc = Loc;
1058 return false;
1059}
1060
1062 const char *&PrevSpec,
1063 unsigned &DiagID) {
1064 // 'virtual virtual' is ok, but warn as this is likely not what the user
1065 // intended.
1066 if (FS_virtual_specified) {
1067 DiagID = diag::warn_duplicate_declspec;
1068 PrevSpec = "virtual";
1069 return true;
1070 }
1071 FS_virtual_specified = true;
1072 FS_virtualLoc = Loc;
1073 return false;
1074}
1075
1077 const char *&PrevSpec, unsigned &DiagID,
1078 ExplicitSpecifier ExplicitSpec,
1079 SourceLocation CloseParenLoc) {
1080 // 'explicit explicit' is ok, but warn as this is likely not what the user
1081 // intended.
1082 if (hasExplicitSpecifier()) {
1083 DiagID = (ExplicitSpec.getExpr() || FS_explicit_specifier.getExpr())
1084 ? diag::err_duplicate_declspec
1085 : diag::ext_warn_duplicate_declspec;
1086 PrevSpec = "explicit";
1087 return true;
1088 }
1089 FS_explicit_specifier = ExplicitSpec;
1090 FS_explicitLoc = Loc;
1091 FS_explicitCloseParenLoc = CloseParenLoc;
1092 return false;
1093}
1094
1096 const char *&PrevSpec,
1097 unsigned &DiagID) {
1098 // '_Noreturn _Noreturn' is ok, but warn as this is likely not what the user
1099 // intended.
1100 if (FS_noreturn_specified) {
1101 DiagID = diag::warn_duplicate_declspec;
1102 PrevSpec = "_Noreturn";
1103 return true;
1104 }
1105 FS_noreturn_specified = true;
1106 FS_noreturnLoc = Loc;
1107 return false;
1108}
1109
1110bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
1111 unsigned &DiagID) {
1112 if (isFriendSpecified()) {
1113 PrevSpec = "friend";
1114 DiagID = diag::warn_duplicate_declspec;
1115 return true;
1116 }
1117
1118 FriendSpecifiedFirst = isEmpty();
1119 FriendLoc = Loc;
1120 return false;
1121}
1122
1124 unsigned &DiagID) {
1126 PrevSpec = "__module_private__";
1127 DiagID = diag::ext_warn_duplicate_declspec;
1128 return true;
1129 }
1130
1131 ModulePrivateLoc = Loc;
1132 return false;
1133}
1134
1136 SourceLocation Loc, const char *&PrevSpec,
1137 unsigned &DiagID) {
1139 return BadSpecifier(ConstexprKind, getConstexprSpecifier(), PrevSpec,
1140 DiagID);
1141 ConstexprSpecifier = static_cast<unsigned>(ConstexprKind);
1142 ConstexprLoc = Loc;
1143 return false;
1144}
1145
1146void DeclSpec::SaveWrittenBuiltinSpecs() {
1147 writtenBS.Sign = static_cast<int>(getTypeSpecSign());
1148 writtenBS.Width = static_cast<int>(getTypeSpecWidth());
1149 writtenBS.Type = getTypeSpecType();
1150 // Search the list of attributes for the presence of a mode attribute.
1151 writtenBS.ModeAttr = getAttributes().hasAttribute(ParsedAttr::AT_Mode);
1152}
1153
1154/// Finish - This does final analysis of the declspec, rejecting things like
1155/// "_Complex" (lacking an FP type). After calling this method, DeclSpec is
1156/// guaranteed to be self-consistent, even if an error occurred.
1157void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
1158 // Before possibly changing their values, save specs as written.
1159 SaveWrittenBuiltinSpecs();
1160
1161 // Check the type specifier components first. No checking for an invalid
1162 // type.
1163 if (TypeSpecType == TST_error)
1164 return;
1165
1166 // If decltype(auto) is used, no other type specifiers are permitted.
1167 if (TypeSpecType == TST_decltype_auto &&
1169 TypeSpecComplex != TSC_unspecified ||
1171 TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
1172 TypeQualifiers)) {
1173 const unsigned NumLocs = 9;
1174 SourceLocation ExtraLocs[NumLocs] = {
1175 TSWRange.getBegin(), TSCLoc, TSSLoc,
1176 AltiVecLoc, TQ_constLoc, TQ_restrictLoc,
1177 TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc};
1178 FixItHint Hints[NumLocs];
1179 SourceLocation FirstLoc;
1180 for (unsigned I = 0; I != NumLocs; ++I) {
1181 if (ExtraLocs[I].isValid()) {
1182 if (FirstLoc.isInvalid() ||
1184 FirstLoc))
1185 FirstLoc = ExtraLocs[I];
1186 Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]);
1187 }
1188 }
1189 TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Unspecified);
1190 TypeSpecComplex = TSC_unspecified;
1191 TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unspecified);
1192 TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false;
1193 TypeQualifiers = 0;
1194 S.Diag(TSTLoc, diag::err_decltype_auto_cannot_be_combined)
1195 << Hints[0] << Hints[1] << Hints[2] << Hints[3]
1196 << Hints[4] << Hints[5] << Hints[6] << Hints[7];
1197 }
1198
1199 // Validate and finalize AltiVec vector declspec.
1200 if (TypeAltiVecVector) {
1201 // No vector long long without VSX (or ZVector).
1203 !S.Context.getTargetInfo().hasFeature("vsx") &&
1204 !S.getLangOpts().ZVector)
1205 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_long_decl_spec);
1206
1207 // No vector __int128 prior to Power8.
1208 if ((TypeSpecType == TST_int128) &&
1209 !S.Context.getTargetInfo().hasFeature("power8-vector"))
1210 S.Diag(TSTLoc, diag::err_invalid_vector_int128_decl_spec);
1211
1212 // Complex vector types are not supported.
1213 if (TypeSpecComplex != TSC_unspecified)
1214 S.Diag(TSCLoc, diag::err_invalid_vector_complex_decl_spec);
1215 else if (TypeAltiVecBool) {
1216 // Sign specifiers are not allowed with vector bool. (PIM 2.1)
1218 S.Diag(TSSLoc, diag::err_invalid_vector_bool_decl_spec)
1220 }
1221 // Only char/int are valid with vector bool prior to Power10.
1222 // Power10 adds instructions that produce vector bool data
1223 // for quadwords as well so allow vector bool __int128.
1224 if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) &&
1225 (TypeSpecType != TST_int) && (TypeSpecType != TST_int128)) ||
1226 TypeAltiVecPixel) {
1227 S.Diag(TSTLoc, diag::err_invalid_vector_bool_decl_spec)
1228 << (TypeAltiVecPixel ? "__pixel" :
1229 getSpecifierName((TST)TypeSpecType, Policy));
1230 }
1231 // vector bool __int128 requires Power10.
1232 if ((TypeSpecType == TST_int128) &&
1233 (!S.Context.getTargetInfo().hasFeature("power10-vector")))
1234 S.Diag(TSTLoc, diag::err_invalid_vector_bool_int128_decl_spec);
1235
1236 // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
1240 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec)
1242
1243 // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
1244 if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) ||
1245 (TypeSpecType == TST_int128) ||
1247 TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unsigned);
1248 } else if (TypeSpecType == TST_double) {
1249 // vector long double and vector long long double are never allowed.
1250 // vector double is OK for Power7 and later, and ZVector.
1253 S.Diag(TSWRange.getBegin(),
1254 diag::err_invalid_vector_long_double_decl_spec);
1255 else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
1256 !S.getLangOpts().ZVector)
1257 S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec);
1258 } else if (TypeSpecType == TST_float) {
1259 // vector float is unsupported for ZVector unless we have the
1260 // vector-enhancements facility 1 (ISA revision 12).
1261 if (S.getLangOpts().ZVector &&
1262 !S.Context.getTargetInfo().hasFeature("arch12"))
1263 S.Diag(TSTLoc, diag::err_invalid_vector_float_decl_spec);
1265 // Vector long is unsupported for ZVector, or without VSX, and deprecated
1266 // for AltiVec.
1267 // It has also been historically deprecated on AIX (as an alias for
1268 // "vector int" in both 32-bit and 64-bit modes). It was then made
1269 // unsupported in the Clang-based XL compiler since the deprecated type
1270 // has a number of conflicting semantics and continuing to support it
1271 // is a disservice to users.
1272 if (S.getLangOpts().ZVector ||
1273 !S.Context.getTargetInfo().hasFeature("vsx") ||
1274 S.Context.getTargetInfo().getTriple().isOSAIX())
1275 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec);
1276 else
1277 S.Diag(TSWRange.getBegin(),
1278 diag::warn_vector_long_decl_spec_combination)
1279 << getSpecifierName((TST)TypeSpecType, Policy);
1280 }
1281
1282 if (TypeAltiVecPixel) {
1283 //TODO: perform validation
1284 TypeSpecType = TST_int;
1285 TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unsigned);
1286 TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Short);
1287 TypeSpecOwned = false;
1288 }
1289 }
1290
1291 bool IsFixedPointType =
1292 TypeSpecType == TST_accum || TypeSpecType == TST_fract;
1293
1294 // signed/unsigned are only valid with int/char/wchar_t/_Accum.
1296 if (TypeSpecType == TST_unspecified)
1297 TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
1298 else if (TypeSpecType != TST_int && TypeSpecType != TST_int128 &&
1299 TypeSpecType != TST_char && TypeSpecType != TST_wchar &&
1300 !IsFixedPointType && TypeSpecType != TST_bitint) {
1301 S.Diag(TSSLoc, diag::err_invalid_sign_spec)
1302 << getSpecifierName((TST)TypeSpecType, Policy);
1303 // signed double -> double.
1304 TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unspecified);
1305 }
1306 }
1307
1308 // Validate the width of the type.
1309 switch (getTypeSpecWidth()) {
1311 break;
1312 case TypeSpecifierWidth::Short: // short int
1313 case TypeSpecifierWidth::LongLong: // long long int
1314 if (TypeSpecType == TST_unspecified)
1315 TypeSpecType = TST_int; // short -> short int, long long -> long long int.
1316 else if (!(TypeSpecType == TST_int ||
1317 (IsFixedPointType &&
1319 S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
1320 << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
1321 TypeSpecType = TST_int;
1322 TypeSpecSat = false;
1323 TypeSpecOwned = false;
1324 }
1325 break;
1326 case TypeSpecifierWidth::Long: // long double, long int
1327 if (TypeSpecType == TST_unspecified)
1328 TypeSpecType = TST_int; // long -> long int.
1329 else if (TypeSpecType != TST_int && TypeSpecType != TST_double &&
1330 !IsFixedPointType) {
1331 S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
1332 << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
1333 TypeSpecType = TST_int;
1334 TypeSpecSat = false;
1335 TypeSpecOwned = false;
1336 }
1337 break;
1338 }
1339
1340 // TODO: if the implementation does not implement _Complex, disallow their
1341 // use. Need information about the backend.
1342 if (TypeSpecComplex != TSC_unspecified) {
1343 if (TypeSpecType == TST_unspecified) {
1344 S.Diag(TSCLoc, diag::ext_plain_complex)
1347 " double");
1348 TypeSpecType = TST_double; // _Complex -> _Complex double.
1349 } else if (TypeSpecType == TST_int || TypeSpecType == TST_char ||
1350 TypeSpecType == TST_bitint) {
1351 // Note that this intentionally doesn't include _Complex _Bool.
1352 if (!S.getLangOpts().CPlusPlus)
1353 S.Diag(TSTLoc, diag::ext_integer_complex);
1354 } else if (TypeSpecType != TST_float && TypeSpecType != TST_double &&
1355 TypeSpecType != TST_float128 && TypeSpecType != TST_float16 &&
1356 TypeSpecType != TST_ibm128) {
1357 // FIXME: __fp16?
1358 S.Diag(TSCLoc, diag::err_invalid_complex_spec)
1359 << getSpecifierName((TST)TypeSpecType, Policy);
1360 TypeSpecComplex = TSC_unspecified;
1361 }
1362 }
1363
1364 // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and
1365 // _Thread_local can only appear with the 'static' and 'extern' storage class
1366 // specifiers. We also allow __private_extern__ as an extension.
1367 if (ThreadStorageClassSpec != TSCS_unspecified) {
1368 switch (StorageClassSpec) {
1369 case SCS_unspecified:
1370 case SCS_extern:
1371 case SCS_private_extern:
1372 case SCS_static:
1373 break;
1374 default:
1378 diag::err_invalid_decl_spec_combination)
1381 else
1383 diag::err_invalid_decl_spec_combination)
1386 // Discard the thread storage class specifier to recover.
1387 ThreadStorageClassSpec = TSCS_unspecified;
1388 ThreadStorageClassSpecLoc = SourceLocation();
1389 }
1390 if (S.getLangOpts().C23 &&
1392 S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
1395 }
1396 }
1397
1398 if (S.getLangOpts().C23 &&
1400 StorageClassSpec == SCS_extern) {
1401 S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
1404 }
1405
1406 // If no type specifier was provided and we're parsing a language where
1407 // the type specifier is not optional, but we got 'auto' as a storage
1408 // class specifier, then assume this is an attempt to use C++0x's 'auto'
1409 // type specifier.
1410 if (S.getLangOpts().CPlusPlus &&
1411 TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) {
1412 TypeSpecType = TST_auto;
1413 StorageClassSpec = SCS_unspecified;
1414 TSTLoc = TSTNameLoc = StorageClassSpecLoc;
1415 StorageClassSpecLoc = SourceLocation();
1416 }
1417 // Diagnose if we've recovered from an ill-formed 'auto' storage class
1418 // specifier in a pre-C++11 dialect of C++ or in a pre-C23 dialect of C.
1419 if (!S.getLangOpts().CPlusPlus11 && !S.getLangOpts().C23 &&
1420 TypeSpecType == TST_auto)
1421 S.Diag(TSTLoc, diag::ext_auto_type_specifier);
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:1171
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:489
StringRef Identifier
Definition: Format.cpp:3009
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:187
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:779
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:743
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK)
Returns true if the given operator is implicitly static in a record context.
Definition: DeclCXX.h:2106
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: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:247
bool isVirtualSpecified() const
Definition: DeclSpec.h:648
bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, ExplicitSpecifier ExplicitSpec, SourceLocation CloseParenLoc)
Definition: DeclSpec.cpp:1076
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:915
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:648
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:1135
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:724
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:1123
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:863
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:887
void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack)
Definition: DeclSpec.cpp:995
bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:710
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:974
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:932
bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1110
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:444
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:741
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:1095
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:949
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:1157
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:462
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:471
bool SetTypeQual(TQ T, SourceLocation Loc)
Definition: DeclSpec.cpp:1020
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:561
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:966
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:456
bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1061
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:900
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:1035
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:1049
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:751
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:325
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:294
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:439
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:427
bool isStaticMember()
Returns true if this declares a static member.
Definition: DeclSpec.cpp:418
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:1901
const Expr * getExpr() const
Definition: DeclCXX.h:1910
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: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:476
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:249
Represents a C++ namespace alias.
Definition: DeclCXX.h:3124
Represent a C++ namespace.
Definition: Decl.h:547
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:5834
Expr * getIndexExpr() const
Definition: Type.h:5833
bool hasAttribute(ParsedAttr::Kind K) const
Definition: ParsedAttr.h:918
SizeType size() const
Definition: ParsedAttr.h:844
void takeAllFrom(ParsedAttributes &Other)
Definition: ParsedAttr.h:967
A (possibly-)qualified type.
Definition: Type.h:941
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1008
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:493
ASTContext & Context
Definition: Sema.h:962
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:84
const LangOptions & getLangOpts() const
Definition: Sema.h:553
SourceManager & getSourceManager() const
Definition: Sema.h:558
OpenCLOptions & getOpenCLOptions()
Definition: Sema.h:554
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:1256
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
Definition: TargetInfo.h:1487
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:7999
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: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: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:161
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