Coverage Report

Created: 2022-05-14 11:35

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