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