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