Coverage Report

Created: 2021-09-21 08:58

/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
235k
void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) {
32
235k
  assert(TemplateId && "NULL template-id annotation?");
33
0
  assert(!TemplateId->isInvalid() &&
34
235k
         "should not convert invalid template-ids to unqualified-ids");
35
36
0
  Kind = UnqualifiedIdKind::IK_TemplateId;
37
235k
  this->TemplateId = TemplateId;
38
235k
  StartLocation = TemplateId->TemplateNameLoc;
39
235k
  EndLocation = TemplateId->RAngleLoc;
40
235k
}
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.41M
                          TypeLoc TL, SourceLocation ColonColonLoc) {
55
4.41M
  Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc);
56
4.41M
  if (Range.getBegin().isInvalid())
57
4.35M
    Range.setBegin(TL.getBeginLoc());
58
4.41M
  Range.setEnd(ColonColonLoc);
59
60
4.41M
  assert(Range == Builder.getSourceRange() &&
61
4.41M
         "NestedNameSpecifierLoc range computation incorrect");
62
4.41M
}
63
64
void CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier,
65
                          SourceLocation IdentifierLoc,
66
13.4k
                          SourceLocation ColonColonLoc) {
67
13.4k
  Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc);
68
69
13.4k
  if (Range.getBegin().isInvalid())
70
77
    Range.setBegin(IdentifierLoc);
71
13.4k
  Range.setEnd(ColonColonLoc);
72
73
13.4k
  assert(Range == Builder.getSourceRange() &&
74
13.4k
         "NestedNameSpecifierLoc range computation incorrect");
75
13.4k
}
76
77
void CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace,
78
                          SourceLocation NamespaceLoc,
79
1.07M
                          SourceLocation ColonColonLoc) {
80
1.07M
  Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc);
81
82
1.07M
  if (Range.getBegin().isInvalid())
83
626k
    Range.setBegin(NamespaceLoc);
84
1.07M
  Range.setEnd(ColonColonLoc);
85
86
1.07M
  assert(Range == Builder.getSourceRange() &&
87
1.07M
         "NestedNameSpecifierLoc range computation incorrect");
88
1.07M
}
89
90
void CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
91
                          SourceLocation AliasLoc,
92
236
                          SourceLocation ColonColonLoc) {
93
236
  Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc);
94
95
236
  if (Range.getBegin().isInvalid())
96
229
    Range.setBegin(AliasLoc);
97
236
  Range.setEnd(ColonColonLoc);
98
99
236
  assert(Range == Builder.getSourceRange() &&
100
236
         "NestedNameSpecifierLoc range computation incorrect");
101
236
}
102
103
void CXXScopeSpec::MakeGlobal(ASTContext &Context,
104
139k
                              SourceLocation ColonColonLoc) {
105
139k
  Builder.MakeGlobal(Context, ColonColonLoc);
106
107
139k
  Range = SourceRange(ColonColonLoc);
108
109
139k
  assert(Range == Builder.getSourceRange() &&
110
139k
         "NestedNameSpecifierLoc range computation incorrect");
111
139k
}
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.43k
                               NestedNameSpecifier *Qualifier, SourceRange R) {
127
1.43k
  Builder.MakeTrivial(Context, Qualifier, R);
128
1.43k
  Range = R;
129
1.43k
}
130
131
9.01M
void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) {
132
9.01M
  if (!Other) {
133
1.49M
    Range = SourceRange();
134
1.49M
    Builder.Clear();
135
1.49M
    return;
136
1.49M
  }
137
138
7.52M
  Range = Other.getSourceRange();
139
7.52M
  Builder.Adopt(Other);
140
7.52M
  assert(Range == Builder.getSourceRange() &&
141
7.52M
         "NestedNameSpecifierLoc range computation incorrect");
142
7.52M
}
143
144
2.07M
SourceLocation CXXScopeSpec::getLastQualifierNameLoc() const {
145
2.07M
  if (!Builder.getRepresentation())
146
510
    return SourceLocation();
147
2.06M
  return Builder.getTemporary().getLocalBeginLoc();
148
2.07M
}
149
150
NestedNameSpecifierLoc
151
27.9M
CXXScopeSpec::getWithLocInContext(ASTContext &Context) const {
152
27.9M
  if (!Builder.getRepresentation())
153
21.5M
    return NestedNameSpecifierLoc();
154
155
6.40M
  return Builder.getWithLocInContext(Context);
156
27.9M
}
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
32.3M
                                             DeclSpec *MethodQualifiers) {
187
32.3M
  assert(!(MethodQualifiers && MethodQualifiers->getTypeQualifiers() & DeclSpec::TQ_atomic) &&
188
32.3M
         "function cannot have _Atomic qualifier");
189
190
0
  DeclaratorChunk I;
191
32.3M
  I.Kind                        = Function;
192
32.3M
  I.Loc                         = LocalRangeBegin;
193
32.3M
  I.EndLoc                      = LocalRangeEnd;
194
32.3M
  new (&I.Fun) FunctionTypeInfo;
195
32.3M
  I.Fun.hasPrototype            = hasProto;
196
32.3M
  I.Fun.isVariadic              = EllipsisLoc.isValid();
197
32.3M
  I.Fun.isAmbiguous             = isAmbiguous;
198
32.3M
  I.Fun.LParenLoc               = LParenLoc;
199
32.3M
  I.Fun.EllipsisLoc             = EllipsisLoc;
200
32.3M
  I.Fun.RParenLoc               = RParenLoc;
201
32.3M
  I.Fun.DeleteParams            = false;
202
32.3M
  I.Fun.NumParams               = NumParams;
203
32.3M
  I.Fun.Params                  = nullptr;
204
32.3M
  I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
205
32.3M
  I.Fun.RefQualifierLoc         = RefQualifierLoc;
206
32.3M
  I.Fun.MutableLoc              = MutableLoc;
207
32.3M
  I.Fun.ExceptionSpecType       = ESpecType;
208
32.3M
  I.Fun.ExceptionSpecLocBeg     = ESpecRange.getBegin();
209
32.3M
  I.Fun.ExceptionSpecLocEnd     = ESpecRange.getEnd();
210
32.3M
  I.Fun.NumExceptionsOrDecls    = 0;
211
32.3M
  I.Fun.Exceptions              = nullptr;
212
32.3M
  I.Fun.NoexceptExpr            = nullptr;
213
32.3M
  I.Fun.HasTrailingReturnType   = TrailingReturnType.isUsable() ||
214
32.3M
                                  
TrailingReturnType.isInvalid()32.3M
;
215
32.3M
  I.Fun.TrailingReturnType      = TrailingReturnType.get();
216
32.3M
  I.Fun.TrailingReturnTypeLoc   = TrailingReturnTypeLoc;
217
32.3M
  I.Fun.MethodQualifiers        = nullptr;
218
32.3M
  I.Fun.QualAttrFactory         = nullptr;
219
220
32.3M
  if (MethodQualifiers && 
(32.3M
MethodQualifiers->getTypeQualifiers()32.3M
||
221
32.3M
                           
MethodQualifiers->getAttributes().size()32.0M
)) {
222
316k
    auto &attrs = MethodQualifiers->getAttributes();
223
316k
    I.Fun.MethodQualifiers = new DeclSpec(attrs.getPool().getFactory());
224
316k
    MethodQualifiers->forEachCVRUQualifier(
225
323k
        [&](DeclSpec::TQ TypeQual, StringRef PrintName, SourceLocation SL) {
226
323k
          I.Fun.MethodQualifiers->SetTypeQual(TypeQual, SL);
227
323k
        });
228
316k
    I.Fun.MethodQualifiers->getAttributes().takeAllFrom(attrs);
229
316k
    I.Fun.MethodQualifiers->getAttributePool().takeAllFrom(attrs.getPool());
230
316k
  }
231
232
32.3M
  assert(I.Fun.ExceptionSpecType == ESpecType && "bitfield overflow");
233
234
  // new[] a parameter array if needed.
235
32.3M
  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
31.7M
    if (!TheDeclarator.InlineStorageUsed &&
241
31.7M
        
NumParams <= llvm::array_lengthof(TheDeclarator.InlineParams)31.6M
) {
242
31.6M
      I.Fun.Params = TheDeclarator.InlineParams;
243
31.6M
      new (I.Fun.Params) ParamInfo[NumParams];
244
31.6M
      I.Fun.DeleteParams = false;
245
31.6M
      TheDeclarator.InlineStorageUsed = true;
246
31.6M
    } else {
247
16.9k
      I.Fun.Params = new DeclaratorChunk::ParamInfo[NumParams];
248
16.9k
      I.Fun.DeleteParams = true;
249
16.9k
    }
250
123M
    for (unsigned i = 0; i < NumParams; 
i++91.4M
)
251
91.4M
      I.Fun.Params[i] = std::move(Params[i]);
252
31.7M
  }
253
254
  // Check what exception specification information we should actually store.
255
32.3M
  switch (ESpecType) {
256
32.3M
  default: break; // By default, save nothing.
257
32.3M
  case EST_Dynamic:
258
    // new[] an exception array if needed
259
307
    if (NumExceptions) {
260
307
      I.Fun.NumExceptionsOrDecls = NumExceptions;
261
307
      I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
262
675
      for (unsigned i = 0; i != NumExceptions; 
++i368
) {
263
368
        I.Fun.Exceptions[i].Ty = Exceptions[i];
264
368
        I.Fun.Exceptions[i].Range = ExceptionRanges[i];
265
368
      }
266
307
    }
267
307
    break;
268
269
18.7k
  case EST_DependentNoexcept:
270
18.9k
  case EST_NoexceptFalse:
271
19.0k
  case EST_NoexceptTrue:
272
19.0k
    I.Fun.NoexceptExpr = NoexceptExpr;
273
19.0k
    break;
274
275
33.0k
  case EST_Unparsed:
276
33.0k
    I.Fun.ExceptionSpecTokens = ExceptionSpecTokens;
277
33.0k
    break;
278
32.3M
  }
279
280
32.3M
  if (!DeclsInPrototype.empty()) {
281
707
    assert(ESpecType == EST_None && NumExceptions == 0 &&
282
707
           "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
707
    I.Fun.DeclsInPrototype = new NamedDecl *[DeclsInPrototype.size()];
286
1.47k
    for (size_t J = 0; J < DeclsInPrototype.size(); 
++J768
)
287
768
      I.Fun.DeclsInPrototype[J] = DeclsInPrototype[J];
288
707
  }
289
290
0
  return I;
291
32.3M
}
292
293
void Declarator::setDecompositionBindings(
294
    SourceLocation LSquareLoc,
295
    ArrayRef<DecompositionDeclarator::Binding> Bindings,
296
393
    SourceLocation RSquareLoc) {
297
393
  assert(!hasName() && "declarator given multiple names!");
298
299
0
  BindingGroup.LSquareLoc = LSquareLoc;
300
393
  BindingGroup.RSquareLoc = RSquareLoc;
301
393
  BindingGroup.NumBindings = Bindings.size();
302
393
  Range.setEnd(RSquareLoc);
303
304
  // We're now past the identifier.
305
393
  SetIdentifier(nullptr, LSquareLoc);
306
393
  Name.EndLocation = RSquareLoc;
307
308
  // Allocate storage for bindings and stash them away.
309
393
  if (Bindings.size()) {
310
387
    if (!InlineStorageUsed &&
311
387
        Bindings.size() <= llvm::array_lengthof(InlineBindings)) {
312
387
      BindingGroup.Bindings = InlineBindings;
313
387
      BindingGroup.DeleteBindings = false;
314
387
      InlineStorageUsed = true;
315
387
    } else {
316
0
      BindingGroup.Bindings =
317
0
          new DecompositionDeclarator::Binding[Bindings.size()];
318
0
      BindingGroup.DeleteBindings = true;
319
0
    }
320
387
    std::uninitialized_copy(Bindings.begin(), Bindings.end(),
321
387
                            BindingGroup.Bindings);
322
387
  }
323
393
}
324
325
2.90M
bool Declarator::isDeclarationOfFunction() const {
326
2.91M
  for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; 
++i11.2k
) {
327
1.24M
    switch (DeclTypeInfo[i].Kind) {
328
1.03M
    case DeclaratorChunk::Function:
329
1.03M
      return true;
330
11.2k
    case DeclaratorChunk::Paren:
331
11.2k
      continue;
332
97.5k
    case DeclaratorChunk::Pointer:
333
125k
    case DeclaratorChunk::Reference:
334
196k
    case DeclaratorChunk::Array:
335
196k
    case DeclaratorChunk::BlockPointer:
336
200k
    case DeclaratorChunk::MemberPointer:
337
200k
    case DeclaratorChunk::Pipe:
338
200k
      return false;
339
1.24M
    }
340
0
    llvm_unreachable("Invalid type chunk");
341
0
  }
342
343
1.67M
  switch (DS.getTypeSpecType()) {
344
447
    case TST_atomic:
345
589
    case TST_auto:
346
589
    case TST_auto_type:
347
245k
    case TST_bool:
348
259k
    case TST_char:
349
259k
    case TST_char8:
350
260k
    case TST_char16:
351
261k
    case TST_char32:
352
261k
    case TST_class:
353
261k
    case TST_decimal128:
354
261k
    case TST_decimal32:
355
261k
    case TST_decimal64:
356
267k
    case TST_double:
357
267k
    case TST_Accum:
358
267k
    case TST_Fract:
359
267k
    case TST_Float16:
360
267k
    case TST_float128:
361
267k
    case TST_ibm128:
362
267k
    case TST_enum:
363
267k
    case TST_error:
364
272k
    case TST_float:
365
272k
    case TST_half:
366
552k
    case TST_int:
367
552k
    case TST_int128:
368
553k
    case TST_extint:
369
732k
    case TST_struct:
370
732k
    case TST_interface:
371
736k
    case TST_union:
372
736k
    case TST_unknown_anytype:
373
736k
    case TST_unspecified:
374
748k
    case TST_void:
375
749k
    case TST_wchar:
376
749k
    case TST_BFloat16:
377
8.99M
#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
378
749k
#include "clang/Basic/OpenCLImageTypes.def"
379
749k
      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.14k
    case TST_decltype:
387
4.16k
    case TST_typeofExpr:
388
4.16k
      if (Expr *E = DS.getRepAsExpr())
389
4.16k
        return E->getType()->isFunctionType();
390
0
      return false;
391
392
493
    case TST_underlyingType:
393
919k
    case TST_typename:
394
919k
    case TST_typeofType: {
395
919k
      QualType QT = DS.getRepAsType().get();
396
919k
      if (QT.isNull())
397
0
        return false;
398
399
919k
      if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
400
117k
        QT = LIT->getType();
401
402
919k
      if (QT.isNull())
403
0
        return false;
404
405
919k
      return QT->isFunctionType();
406
919k
    }
407
1.67M
  }
408
409
0
  llvm_unreachable("Invalid TypeSpecType!");
410
0
}
411
412
2.01M
bool Declarator::isStaticMember() {
413
2.01M
  assert(getContext() == DeclaratorContext::Member);
414
2.01M
  return getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
415
2.01M
         
(1.73M
getName().Kind == UnqualifiedIdKind::IK_OperatorFunctionId1.73M
&&
416
1.73M
          CXXMethodDecl::isStaticOverloadedOperator(
417
382k
              getName().OperatorFunctionId.Operator));
418
2.01M
}
419
420
1.00M
bool Declarator::isCtorOrDtor() {
421
1.00M
  return (getName().getKind() == UnqualifiedIdKind::IK_ConstructorName) ||
422
1.00M
         
(getName().getKind() == UnqualifiedIdKind::IK_DestructorName)764k
;
423
1.00M
}
424
425
void DeclSpec::forEachCVRUQualifier(
426
316k
    llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) {
427
316k
  if (TypeQualifiers & TQ_const)
428
296k
    Handle(TQ_const, "const", TQ_constLoc);
429
316k
  if (TypeQualifiers & TQ_volatile)
430
27.4k
    Handle(TQ_volatile, "volatile", TQ_volatileLoc);
431
316k
  if (TypeQualifiers & TQ_restrict)
432
39
    Handle(TQ_restrict, "restrict", TQ_restrictLoc);
433
316k
  if (TypeQualifiers & TQ_unaligned)
434
16
    Handle(TQ_unaligned, "unaligned", TQ_unalignedLoc);
435
316k
}
436
437
void DeclSpec::forEachQualifier(
438
60
    llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) {
439
60
  forEachCVRUQualifier(Handle);
440
  // FIXME: Add code below to iterate through the attributes and call Handle.
441
60
}
442
443
49.6M
bool DeclSpec::hasTagDefinition() const {
444
49.6M
  if (!TypeSpecOwned)
445
47.2M
    return false;
446
2.38M
  return cast<TagDecl>(getRepAsDecl())->isCompleteDefinition();
447
49.6M
}
448
449
/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
450
/// declaration specifier includes.
451
///
452
105M
unsigned DeclSpec::getParsedSpecifiers() const {
453
105M
  unsigned Res = 0;
454
105M
  if (StorageClassSpec != SCS_unspecified ||
455
105M
      
ThreadStorageClassSpec != TSCS_unspecified105M
)
456
244k
    Res |= PQ_StorageClassSpecifier;
457
458
105M
  if (TypeQualifiers != TQ_unspecified)
459
4.36M
    Res |= PQ_TypeQualifier;
460
461
105M
  if (hasTypeSpecifier())
462
104M
    Res |= PQ_TypeSpecifier;
463
464
105M
  if (FS_inline_specified || 
FS_virtual_specified105M
||
hasExplicitSpecifier()105M
||
465
105M
      
FS_noreturn_specified105M
||
FS_forceinline_specified105M
)
466
5.46k
    Res |= PQ_FunctionSpecifier;
467
105M
  return Res;
468
105M
}
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
88
const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) {
484
88
  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
29
  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
88
  }
494
0
  llvm_unreachable("Unknown typespec!");
495
0
}
496
497
66
const char *DeclSpec::getSpecifierName(DeclSpec::TSCS S) {
498
66
  switch (S) {
499
0
  case DeclSpec::TSCS_unspecified:   return "unspecified";
500
16
  case DeclSpec::TSCS___thread:      return "__thread";
501
18
  case DeclSpec::TSCS_thread_local:  return "thread_local";
502
32
  case DeclSpec::TSCS__Thread_local: return "_Thread_local";
503
66
  }
504
0
  llvm_unreachable("Unknown typespec!");
505
0
}
506
507
31
const char *DeclSpec::getSpecifierName(TypeSpecifierWidth W) {
508
31
  switch (W) {
509
11
  case TypeSpecifierWidth::Unspecified:
510
11
    return "unspecified";
511
0
  case TypeSpecifierWidth::Short:
512
0
    return "short";
513
20
  case TypeSpecifierWidth::Long:
514
20
    return "long";
515
0
  case TypeSpecifierWidth::LongLong:
516
0
    return "long long";
517
31
  }
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
87
const char *DeclSpec::getSpecifierName(TypeSpecifierSign S) {
531
87
  switch (S) {
532
11
  case TypeSpecifierSign::Unspecified:
533
11
    return "unspecified";
534
44
  case TypeSpecifierSign::Signed:
535
44
    return "signed";
536
32
  case TypeSpecifierSign::Unsigned:
537
32
    return "unsigned";
538
87
  }
539
0
  llvm_unreachable("Unknown typespec!");
540
0
}
541
542
const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
543
1.90k
                                       const PrintingPolicy &Policy) {
544
1.90k
  switch (T) {
545
1.38k
  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
95
  case DeclSpec::TST_int:         return "int";
553
5
  case DeclSpec::TST_int128:      return "__int128";
554
2
  case DeclSpec::TST_extint:      return "_ExtInt";
555
1
  case DeclSpec::TST_half:        return "half";
556
23
  case DeclSpec::TST_float:       return "float";
557
31
  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
163
  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.90k
  }
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
32.4M
                                   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
32.4M
  if (S.getLangOpts().OpenCL &&
630
32.4M
      !S.getOpenCLOptions().isAvailableOption(
631
5.43k
          "cl_clang_storage_class_specifiers", S.getLangOpts())) {
632
5.43k
    switch (SC) {
633
192
    case SCS_extern:
634
192
    case SCS_private_extern:
635
435
    case SCS_static:
636
435
      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
433
      break;
642
433
    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
4.98k
    default:
648
4.98k
      break;
649
5.43k
    }
650
5.43k
  }
651
652
32.4M
  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
32.4M
  StorageClassSpec = SC;
675
32.4M
  StorageClassSpecLoc = Loc;
676
32.4M
  assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
677
0
  return false;
678
32.4M
}
679
680
bool DeclSpec::SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
681
                                         const char *&PrevSpec,
682
994
                                         unsigned &DiagID) {
683
994
  if (ThreadStorageClassSpec != TSCS_unspecified)
684
0
    return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID);
685
686
994
  ThreadStorageClassSpec = TSC;
687
994
  ThreadStorageClassSpecLoc = Loc;
688
994
  return false;
689
994
}
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.43M
                                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.43M
  if (getTypeSpecWidth() == TypeSpecifierWidth::Unspecified)
700
1.14M
    TSWRange.setBegin(Loc);
701
  // Allow turning long -> long long.
702
291k
  else if (W != TypeSpecifierWidth::LongLong ||
703
291k
           getTypeSpecWidth() != TypeSpecifierWidth::Long)
704
0
    return BadSpecifier(W, getTypeSpecWidth(), PrevSpec, DiagID);
705
1.43M
  TypeSpecWidth = static_cast<unsigned>(W);
706
  // Remember location of the last 'long'
707
1.43M
  TSWRange.setEnd(Loc);
708
1.43M
  return false;
709
1.43M
}
710
711
bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc,
712
                                  const char *&PrevSpec,
713
8.13k
                                  unsigned &DiagID) {
714
8.13k
  if (TypeSpecComplex != TSC_unspecified)
715
0
    return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
716
8.13k
  TypeSpecComplex = C;
717
8.13k
  TSCLoc = Loc;
718
8.13k
  return false;
719
8.13k
}
720
721
bool DeclSpec::SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc,
722
1.25M
                               const char *&PrevSpec, unsigned &DiagID) {
723
1.25M
  if (getTypeSpecSign() != TypeSpecifierSign::Unspecified)
724
0
    return BadSpecifier(S, getTypeSpecSign(), PrevSpec, DiagID);
725
1.25M
  TypeSpecSign = static_cast<unsigned>(S);
726
1.25M
  TSSLoc = Loc;
727
1.25M
  return false;
728
1.25M
}
729
730
bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
731
                               const char *&PrevSpec,
732
                               unsigned &DiagID,
733
                               ParsedType Rep,
734
130M
                               const PrintingPolicy &Policy) {
735
130M
  return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Policy);
736
130M
}
737
738
bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
739
                               SourceLocation TagNameLoc,
740
                               const char *&PrevSpec,
741
                               unsigned &DiagID,
742
                               ParsedType Rep,
743
130M
                               const PrintingPolicy &Policy) {
744
130M
  assert(isTypeRep(T) && "T does not store a type");
745
0
  assert(Rep && "no type provided!");
746
130M
  if (TypeSpecType == TST_error)
747
0
    return false;
748
130M
  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
130M
  TypeSpecType = T;
754
130M
  TypeRep = Rep;
755
130M
  TSTLoc = TagKwLoc;
756
130M
  TSTNameLoc = TagNameLoc;
757
130M
  TypeSpecOwned = false;
758
130M
  return false;
759
130M
}
760
761
bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
762
                               const char *&PrevSpec,
763
                               unsigned &DiagID,
764
                               Expr *Rep,
765
80.1k
                               const PrintingPolicy &Policy) {
766
80.1k
  assert(isExprRep(T) && "T does not store an expr");
767
0
  assert(Rep && "no expression provided!");
768
80.1k
  if (TypeSpecType == TST_error)
769
0
    return false;
770
80.1k
  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
80.1k
  TypeSpecType = T;
776
80.1k
  ExprRep = Rep;
777
80.1k
  TSTLoc = Loc;
778
80.1k
  TSTNameLoc = Loc;
779
80.1k
  TypeSpecOwned = false;
780
80.1k
  return false;
781
80.1k
}
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.71M
                               const PrintingPolicy &Policy) {
797
2.71M
  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.71M
  if (TypeSpecType == TST_error)
801
0
    return false;
802
2.71M
  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.71M
  TypeSpecType = T;
808
2.71M
  DeclRep = Rep;
809
2.71M
  TSTLoc = TagKwLoc;
810
2.71M
  TSTNameLoc = TagNameLoc;
811
2.71M
  TypeSpecOwned = Owned && 
Rep != nullptr1.28M
;
812
2.71M
  return false;
813
2.71M
}
814
815
bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
816
                               unsigned &DiagID, TemplateIdAnnotation *Rep,
817
140
                               const PrintingPolicy &Policy) {
818
140
  assert(T == TST_auto || T == TST_decltype_auto);
819
0
  ConstrainedAuto = true;
820
140
  TemplateIdRep = Rep;
821
140
  return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Policy);
822
140
}
823
824
bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
825
                               const char *&PrevSpec,
826
                               unsigned &DiagID,
827
9.63M
                               const PrintingPolicy &Policy) {
828
9.63M
  assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) &&
829
9.63M
         "rep required for these type-spec kinds!");
830
9.63M
  if (TypeSpecType == TST_error)
831
22
    return false;
832
9.63M
  if (TypeSpecType != TST_unspecified) {
833
72
    PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
834
72
    DiagID = diag::err_invalid_decl_spec_combination;
835
72
    return true;
836
72
  }
837
9.63M
  TSTLoc = Loc;
838
9.63M
  TSTNameLoc = Loc;
839
9.63M
  if (TypeAltiVecVector && 
(T == TST_bool)514k
&&
!TypeAltiVecBool15.1k
) {
840
15.1k
    TypeAltiVecBool = true;
841
15.1k
    return false;
842
15.1k
  }
843
9.61M
  TypeSpecType = T;
844
9.61M
  TypeSpecOwned = false;
845
9.61M
  return false;
846
9.63M
}
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
771k
                          const PrintingPolicy &Policy) {
864
771k
  if (TypeSpecType == TST_error)
865
0
    return false;
866
771k
  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
771k
  TypeAltiVecVector = isAltiVecVector;
872
771k
  AltiVecLoc = Loc;
873
771k
  return false;
874
771k
}
875
876
bool DeclSpec::SetTypePipe(bool isPipe, SourceLocation Loc,
877
                           const char *&PrevSpec, unsigned &DiagID,
878
251
                           const PrintingPolicy &Policy) {
879
251
  if (TypeSpecType == TST_error)
880
0
    return false;
881
251
  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
245
  if (isPipe) {
888
245
    TypeSpecPipe = static_cast<unsigned>(TypeSpecifiersPipe::Pipe);
889
245
  }
890
245
  return false;
891
251
}
892
893
bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
894
                          const char *&PrevSpec, unsigned &DiagID,
895
13.0k
                          const PrintingPolicy &Policy) {
896
13.0k
  if (TypeSpecType == TST_error)
897
0
    return false;
898
13.0k
  if (!TypeAltiVecVector || TypeAltiVecPixel ||
899
13.0k
      (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
13.0k
  TypeAltiVecPixel = isAltiVecPixel;
905
13.0k
  TSTLoc = Loc;
906
13.0k
  TSTNameLoc = Loc;
907
13.0k
  return false;
908
13.0k
}
909
910
bool DeclSpec::SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
911
                                  const char *&PrevSpec, unsigned &DiagID,
912
118k
                                  const PrintingPolicy &Policy) {
913
118k
  if (TypeSpecType == TST_error)
914
0
    return false;
915
118k
  if (!TypeAltiVecVector || TypeAltiVecBool ||
916
118k
      (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
118k
  TypeAltiVecBool = isAltiVecBool;
922
118k
  TSTLoc = Loc;
923
118k
  TSTNameLoc = Loc;
924
118k
  return false;
925
118k
}
926
927
2.94k
bool DeclSpec::SetTypeSpecError() {
928
2.94k
  TypeSpecType = TST_error;
929
2.94k
  TypeSpecOwned = false;
930
2.94k
  TSTLoc = SourceLocation();
931
2.94k
  TSTNameLoc = SourceLocation();
932
2.94k
  return false;
933
2.94k
}
934
935
bool DeclSpec::SetExtIntType(SourceLocation KWLoc, Expr *BitsExpr,
936
                             const char *&PrevSpec, unsigned &DiagID,
937
950
                             const PrintingPolicy &Policy) {
938
950
  assert(BitsExpr && "no expression provided!");
939
950
  if (TypeSpecType == TST_error)
940
0
    return false;
941
942
950
  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
950
  TypeSpecType = TST_extint;
949
950
  ExprRep = BitsExpr;
950
950
  TSTLoc = KWLoc;
951
950
  TSTNameLoc = KWLoc;
952
950
  TypeSpecOwned = false;
953
950
  return false;
954
950
}
955
956
bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
957
6.02M
                           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
6.02M
  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
6.02M
  return SetTypeQual(T, Loc);
970
6.02M
}
971
972
6.35M
bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc) {
973
6.35M
  TypeQualifiers |= T;
974
975
6.35M
  switch (T) {
976
0
  case TQ_unspecified: break;
977
6.11M
  case TQ_const:    TQ_constLoc = Loc; return false;
978
80.0k
  case TQ_restrict: TQ_restrictLoc = Loc; return false;
979
155k
  case TQ_volatile: TQ_volatileLoc = Loc; return false;
980
187
  case TQ_unaligned: TQ_unalignedLoc = Loc; return false;
981
146
  case TQ_atomic:   TQ_atomicLoc = Loc; return false;
982
6.35M
  }
983
984
0
  llvm_unreachable("Unknown type qualifier!");
985
0
}
986
987
bool DeclSpec::setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
988
28.2M
                                     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
28.2M
  if (FS_inline_specified) {
992
1
    DiagID = diag::warn_duplicate_declspec;
993
1
    PrevSpec = "inline";
994
1
    return true;
995
1
  }
996
28.2M
  FS_inline_specified = true;
997
28.2M
  FS_inlineLoc = Loc;
998
28.2M
  return false;
999
28.2M
}
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
52.1k
                                      unsigned &DiagID) {
1016
  // 'virtual virtual' is ok, but warn as this is likely not what the user
1017
  // intended.
1018
52.1k
  if (FS_virtual_specified) {
1019
1
    DiagID = diag::warn_duplicate_declspec;
1020
1
    PrevSpec = "virtual";
1021
1
    return true;
1022
1
  }
1023
52.1k
  FS_virtual_specified = true;
1024
52.1k
  FS_virtualLoc = Loc;
1025
52.1k
  return false;
1026
52.1k
}
1027
1028
bool DeclSpec::setFunctionSpecExplicit(SourceLocation Loc,
1029
                                       const char *&PrevSpec, unsigned &DiagID,
1030
                                       ExplicitSpecifier ExplicitSpec,
1031
66.4k
                                       SourceLocation CloseParenLoc) {
1032
  // 'explicit explicit' is ok, but warn as this is likely not what the user
1033
  // intended.
1034
66.4k
  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
66.4k
  FS_explicit_specifier = ExplicitSpec;
1042
66.4k
  FS_explicitLoc = Loc;
1043
66.4k
  FS_explicitCloseParenLoc = CloseParenLoc;
1044
66.4k
  return false;
1045
66.4k
}
1046
1047
bool DeclSpec::setFunctionSpecNoreturn(SourceLocation Loc,
1048
                                       const char *&PrevSpec,
1049
72
                                       unsigned &DiagID) {
1050
  // '_Noreturn _Noreturn' is ok, but warn as this is likely not what the user
1051
  // intended.
1052
72
  if (FS_noreturn_specified) {
1053
1
    DiagID = diag::warn_duplicate_declspec;
1054
1
    PrevSpec = "_Noreturn";
1055
1
    return true;
1056
1
  }
1057
71
  FS_noreturn_specified = true;
1058
71
  FS_noreturnLoc = Loc;
1059
71
  return false;
1060
72
}
1061
1062
bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
1063
47.1k
                             unsigned &DiagID) {
1064
47.1k
  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
47.1k
  Friend_specified = true;
1076
47.1k
  FriendLoc = Loc;
1077
47.1k
  return false;
1078
47.1k
}
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
316k
                                unsigned &DiagID) {
1095
316k
  if (getConstexprSpecifier() != ConstexprSpecKind::Unspecified)
1096
15
    return BadSpecifier(ConstexprKind, getConstexprSpecifier(), PrevSpec,
1097
15
                        DiagID);
1098
316k
  ConstexprSpecifier = static_cast<unsigned>(ConstexprKind);
1099
316k
  ConstexprLoc = Loc;
1100
316k
  return false;
1101
316k
}
1102
1103
165M
void DeclSpec::SaveWrittenBuiltinSpecs() {
1104
165M
  writtenBS.Sign = static_cast<int>(getTypeSpecSign());
1105
165M
  writtenBS.Width = static_cast<int>(getTypeSpecWidth());
1106
165M
  writtenBS.Type = getTypeSpecType();
1107
  // Search the list of attributes for the presence of a mode attribute.
1108
165M
  writtenBS.ModeAttr = getAttributes().hasAttribute(ParsedAttr::AT_Mode);
1109
165M
}
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
165M
void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
1116
  // Before possibly changing their values, save specs as written.
1117
165M
  SaveWrittenBuiltinSpecs();
1118
1119
  // Check the type specifier components first. No checking for an invalid
1120
  // type.
1121
165M
  if (TypeSpecType == TST_error)
1122
2.76k
    return;
1123
1124
  // If decltype(auto) is used, no other type specifiers are permitted.
1125
165M
  if (TypeSpecType == TST_decltype_auto &&
1126
165M
      
(448
getTypeSpecWidth() != TypeSpecifierWidth::Unspecified448
||
1127
448
       TypeSpecComplex != TSC_unspecified ||
1128
448
       getTypeSpecSign() != TypeSpecifierSign::Unspecified ||
1129
448
       TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
1130
448
       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
165M
  if (TypeAltiVecVector) {
1159
771k
    if (TypeAltiVecBool) {
1160
      // Sign specifiers are not allowed with vector bool. (PIM 2.1)
1161
133k
      if (getTypeSpecSign() != TypeSpecifierSign::Unspecified) {
1162
76
        S.Diag(TSSLoc, diag::err_invalid_vector_bool_decl_spec)
1163
76
            << getSpecifierName(getTypeSpecSign());
1164
76
      }
1165
      // Only char/int are valid with vector bool prior to Power10.
1166
      // Power10 adds instructions that produce vector bool data
1167
      // for quadwords as well so allow vector bool __int128.
1168
133k
      if (((TypeSpecType != TST_unspecified) && 
(TypeSpecType != TST_char)76.3k
&&
1169
133k
           
(TypeSpecType != TST_int)40.1k
&&
(TypeSpecType != TST_int128)252
) ||
1170
133k
          
TypeAltiVecPixel133k
) {
1171
60
        S.Diag(TSTLoc, diag::err_invalid_vector_bool_decl_spec)
1172
60
          << (TypeAltiVecPixel ? 
"__pixel"20
:
1173
60
                                 
getSpecifierName((TST)TypeSpecType, Policy)40
);
1174
60
      }
1175
      // vector bool __int128 requires Power10.
1176
133k
      if ((TypeSpecType == TST_int128) &&
1177
133k
          
(!S.Context.getTargetInfo().hasFeature("power10-vector"))212
)
1178
60
        S.Diag(TSTLoc, diag::err_invalid_vector_bool_int128_decl_spec);
1179
1180
      // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
1181
133k
      if ((getTypeSpecWidth() != TypeSpecifierWidth::Unspecified) &&
1182
133k
          
(getTypeSpecWidth() != TypeSpecifierWidth::Short)57.1k
&&
1183
133k
          
(getTypeSpecWidth() != TypeSpecifierWidth::LongLong)20.2k
)
1184
20
        S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec)
1185
20
            << getSpecifierName(getTypeSpecWidth());
1186
1187
      // vector bool long long requires VSX support or ZVector.
1188
133k
      if ((getTypeSpecWidth() == TypeSpecifierWidth::LongLong) &&
1189
133k
          
(!S.Context.getTargetInfo().hasFeature("vsx"))20.2k
&&
1190
133k
          
(!S.Context.getTargetInfo().hasFeature("power8-vector"))3.94k
&&
1191
133k
          
!S.getLangOpts().ZVector3.94k
)
1192
40
        S.Diag(TSTLoc, diag::err_invalid_vector_long_long_decl_spec);
1193
1194
      // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
1195
133k
      if ((TypeSpecType == TST_char) || 
(TypeSpecType == TST_int)97.4k
||
1196
133k
          
(TypeSpecType == TST_int128)57.4k
||
1197
133k
          
(getTypeSpecWidth() != TypeSpecifierWidth::Unspecified)57.2k
)
1198
133k
        TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unsigned);
1199
637k
    } else if (TypeSpecType == TST_double) {
1200
      // vector long double and vector long long double are never allowed.
1201
      // vector double is OK for Power7 and later, and ZVector.
1202
24.8k
      if (getTypeSpecWidth() == TypeSpecifierWidth::Long ||
1203
24.8k
          
getTypeSpecWidth() == TypeSpecifierWidth::LongLong24.8k
)
1204
44
        S.Diag(TSWRange.getBegin(),
1205
44
               diag::err_invalid_vector_long_double_decl_spec);
1206
24.8k
      else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
1207
24.8k
               
!S.getLangOpts().ZVector4.42k
)
1208
20
        S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec);
1209
613k
    } else if (TypeSpecType == TST_float) {
1210
      // vector float is unsupported for ZVector unless we have the
1211
      // vector-enhancements facility 1 (ISA revision 12).
1212
42.1k
      if (S.getLangOpts().ZVector &&
1213
42.1k
          
!S.Context.getTargetInfo().hasFeature("arch12")2.74k
)
1214
2
        S.Diag(TSTLoc, diag::err_invalid_vector_float_decl_spec);
1215
570k
    } else if (getTypeSpecWidth() == TypeSpecifierWidth::Long) {
1216
      // vector long is unsupported for ZVector and deprecated for AltiVec.
1217
      // It has also been historically deprecated on AIX (as an alias for
1218
      // "vector int" in both 32-bit and 64-bit modes). It was then made
1219
      // unsupported in the Clang-based XL compiler since the deprecated type
1220
      // has a number of conflicting semantics and continuing to support it
1221
      // is a disservice to users.
1222
126
      if (S.getLangOpts().ZVector ||
1223
126
          
S.Context.getTargetInfo().getTriple().isOSAIX()124
)
1224
50
        S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec);
1225
76
      else
1226
76
        S.Diag(TSWRange.getBegin(),
1227
76
               diag::warn_vector_long_decl_spec_combination)
1228
76
            << getSpecifierName((TST)TypeSpecType, Policy);
1229
126
    }
1230
1231
771k
    if (TypeAltiVecPixel) {
1232
      //TODO: perform validation
1233
13.0k
      TypeSpecType = TST_int;
1234
13.0k
      TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unsigned);
1235
13.0k
      TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Short);
1236
13.0k
      TypeSpecOwned = false;
1237
13.0k
    }
1238
771k
  }
1239
1240
165M
  bool IsFixedPointType =
1241
165M
      TypeSpecType == TST_accum || 
TypeSpecType == TST_fract165M
;
1242
1243
  // signed/unsigned are only valid with int/char/wchar_t/_Accum.
1244
165M
  if (getTypeSpecSign() != TypeSpecifierSign::Unspecified) {
1245
1.40M
    if (TypeSpecType == TST_unspecified)
1246
531k
      TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
1247
873k
    else if (TypeSpecType != TST_int && 
TypeSpecType != TST_int128407k
&&
1248
873k
             
TypeSpecType != TST_char398k
&&
TypeSpecType != TST_wchar818
&&
1249
873k
             
!IsFixedPointType812
&&
TypeSpecType != TST_extint78
) {
1250
4
      S.Diag(TSSLoc, diag::err_invalid_sign_spec)
1251
4
        << getSpecifierName((TST)TypeSpecType, Policy);
1252
      // signed double -> double.
1253
4
      TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unspecified);
1254
4
    }
1255
1.40M
  }
1256
1257
  // Validate the width of the type.
1258
165M
  switch (getTypeSpecWidth()) {
1259
164M
  case TypeSpecifierWidth::Unspecified:
1260
164M
    break;
1261
437k
  case TypeSpecifierWidth::Short:    // short int
1262
731k
  case TypeSpecifierWidth::LongLong: // long long int
1263
731k
    if (TypeSpecType == TST_unspecified)
1264
282k
      TypeSpecType = TST_int; // short -> short int, long long -> long long int.
1265
449k
    else if (!(TypeSpecType == TST_int ||
1266
449k
               
(697
IsFixedPointType697
&&
1267
697
                
getTypeSpecWidth() != TypeSpecifierWidth::LongLong694
))) {
1268
11
      S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
1269
11
          << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
1270
11
      TypeSpecType = TST_int;
1271
11
      TypeSpecSat = false;
1272
11
      TypeSpecOwned = false;
1273
11
    }
1274
731k
    break;
1275
428k
  case TypeSpecifierWidth::Long: // long double, long int
1276
428k
    if (TypeSpecType == TST_unspecified)
1277
151k
      TypeSpecType = TST_int;  // long -> long int.
1278
277k
    else if (TypeSpecType != TST_int && 
TypeSpecType != TST_double71.8k
&&
1279
277k
             
!IsFixedPointType361
) {
1280
7
      S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
1281
7
          << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
1282
7
      TypeSpecType = TST_int;
1283
7
      TypeSpecSat = false;
1284
7
      TypeSpecOwned = false;
1285
7
    }
1286
428k
    break;
1287
165M
  }
1288
1289
  // TODO: if the implementation does not implement _Complex or _Imaginary,
1290
  // disallow their use.  Need information about the backend.
1291
165M
  if (TypeSpecComplex != TSC_unspecified) {
1292
8.13k
    if (TypeSpecType == TST_unspecified) {
1293
6
      S.Diag(TSCLoc, diag::ext_plain_complex)
1294
6
        << FixItHint::CreateInsertion(
1295
6
                              S.getLocForEndOfToken(getTypeSpecComplexLoc()),
1296
6
                                                 " double");
1297
6
      TypeSpecType = TST_double;   // _Complex -> _Complex double.
1298
8.13k
    } else if (TypeSpecType == TST_int || 
TypeSpecType == TST_char7.76k
||
1299
8.13k
               
TypeSpecType == TST_extint7.69k
) {
1300
      // Note that this intentionally doesn't include _Complex _Bool.
1301
451
      if (!S.getLangOpts().CPlusPlus)
1302
350
        S.Diag(TSTLoc, diag::ext_integer_complex);
1303
7.68k
    } else if (TypeSpecType != TST_float && 
TypeSpecType != TST_double4.91k
&&
1304
7.68k
               
TypeSpecType != TST_float12893
&&
TypeSpecType != TST_float1685
) {
1305
      // FIXME: __fp16?
1306
37
      S.Diag(TSCLoc, diag::err_invalid_complex_spec)
1307
37
        << getSpecifierName((TST)TypeSpecType, Policy);
1308
37
      TypeSpecComplex = TSC_unspecified;
1309
37
    }
1310
8.13k
  }
1311
1312
  // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and
1313
  // _Thread_local can only appear with the 'static' and 'extern' storage class
1314
  // specifiers. We also allow __private_extern__ as an extension.
1315
165M
  if (ThreadStorageClassSpec != TSCS_unspecified) {
1316
994
    switch (StorageClassSpec) {
1317
612
    case SCS_unspecified:
1318
675
    case SCS_extern:
1319
689
    case SCS_private_extern:
1320
963
    case SCS_static:
1321
963
      break;
1322
31
    default:
1323
31
      if (S.getSourceManager().isBeforeInTranslationUnit(
1324
31
            getThreadStorageClassSpecLoc(), getStorageClassSpecLoc()))
1325
19
        S.Diag(getStorageClassSpecLoc(),
1326
19
             diag::err_invalid_decl_spec_combination)
1327
19
          << DeclSpec::getSpecifierName(getThreadStorageClassSpec())
1328
19
          << SourceRange(getThreadStorageClassSpecLoc());
1329
12
      else
1330
12
        S.Diag(getThreadStorageClassSpecLoc(),
1331
12
             diag::err_invalid_decl_spec_combination)
1332
12
          << DeclSpec::getSpecifierName(getStorageClassSpec())
1333
12
          << SourceRange(getStorageClassSpecLoc());
1334
      // Discard the thread storage class specifier to recover.
1335
31
      ThreadStorageClassSpec = TSCS_unspecified;
1336
31
      ThreadStorageClassSpecLoc = SourceLocation();
1337
994
    }
1338
994
  }
1339
1340
  // If no type specifier was provided and we're parsing a language where
1341
  // the type specifier is not optional, but we got 'auto' as a storage
1342
  // class specifier, then assume this is an attempt to use C++0x's 'auto'
1343
  // type specifier.
1344
165M
  if (S.getLangOpts().CPlusPlus &&
1345
165M
      
TypeSpecType == TST_unspecified60.9M
&&
StorageClassSpec == SCS_auto15.2M
) {
1346
94
    TypeSpecType = TST_auto;
1347
94
    StorageClassSpec = SCS_unspecified;
1348
94
    TSTLoc = TSTNameLoc = StorageClassSpecLoc;
1349
94
    StorageClassSpecLoc = SourceLocation();
1350
94
  }
1351
  // Diagnose if we've recovered from an ill-formed 'auto' storage class
1352
  // specifier in a pre-C++11 dialect of C++.
1353
165M
  if (!S.getLangOpts().CPlusPlus11 && 
TypeSpecType == TST_auto104M
)
1354
102
    S.Diag(TSTLoc, diag::ext_auto_type_specifier);
1355
165M
  if (S.getLangOpts().CPlusPlus && 
!S.getLangOpts().CPlusPlus1160.9M
&&
1356
165M
      
StorageClassSpec == SCS_auto229k
)
1357
21
    S.Diag(StorageClassSpecLoc, diag::warn_auto_storage_class)
1358
21
      << FixItHint::CreateRemoval(StorageClassSpecLoc);
1359
165M
  if (TypeSpecType == TST_char8)
1360
58
    S.Diag(TSTLoc, diag::warn_cxx17_compat_unicode_type);
1361
165M
  else if (TypeSpecType == TST_char16 || 
TypeSpecType == TST_char32165M
)
1362
18.9k
    S.Diag(TSTLoc, diag::warn_cxx98_compat_unicode_type)
1363
18.9k
      << (TypeSpecType == TST_char16 ? 
"char16_t"9.47k
:
"char32_t"9.47k
);
1364
165M
  if (getConstexprSpecifier() == ConstexprSpecKind::Constexpr)
1365
316k
    S.Diag(ConstexprLoc, diag::warn_cxx98_compat_constexpr);
1366
165M
  else if (getConstexprSpecifier() == ConstexprSpecKind::Consteval)
1367
147
    S.Diag(ConstexprLoc, diag::warn_cxx20_compat_consteval);
1368
165M
  else if (getConstexprSpecifier() == ConstexprSpecKind::Constinit)
1369
72
    S.Diag(ConstexprLoc, diag::warn_cxx20_compat_constinit);
1370
  // C++ [class.friend]p6:
1371
  //   No storage-class-specifier shall appear in the decl-specifier-seq
1372
  //   of a friend declaration.
1373
165M
  if (isFriendSpecified() &&
1374
165M
      
(47.1k
getStorageClassSpec()47.1k
||
getThreadStorageClassSpec()47.1k
)) {
1375
18
    SmallString<32> SpecName;
1376
18
    SourceLocation SCLoc;
1377
18
    FixItHint StorageHint, ThreadHint;
1378
1379
18
    if (DeclSpec::SCS SC = getStorageClassSpec()) {
1380
13
      SpecName = getSpecifierName(SC);
1381
13
      SCLoc = getStorageClassSpecLoc();
1382
13
      StorageHint = FixItHint::CreateRemoval(SCLoc);
1383
13
    }
1384
1385
18
    if (DeclSpec::TSCS TSC = getThreadStorageClassSpec()) {
1386
7
      if (!SpecName.empty()) 
SpecName += " "2
;
1387
7
      SpecName += getSpecifierName(TSC);
1388
7
      SCLoc = getThreadStorageClassSpecLoc();
1389
7
      ThreadHint = FixItHint::CreateRemoval(SCLoc);
1390
7
    }
1391
1392
18
    S.Diag(SCLoc, diag::err_friend_decl_spec)
1393
18
      << SpecName << StorageHint << ThreadHint;
1394
1395
18
    ClearStorageClassSpecs();
1396
18
  }
1397
1398
  // C++11 [dcl.fct.spec]p5:
1399
  //   The virtual specifier shall be used only in the initial
1400
  //   declaration of a non-static class member function;
1401
  // C++11 [dcl.fct.spec]p6:
1402
  //   The explicit specifier shall be used only in the declaration of
1403
  //   a constructor or conversion function within its class
1404
  //   definition;
1405
165M
  if (isFriendSpecified() && 
(47.1k
isVirtualSpecified()47.1k
||
hasExplicitSpecifier()47.1k
)) {
1406
14
    StringRef Keyword;
1407
14
    FixItHint Hint;
1408
14
    SourceLocation SCLoc;
1409
1410
14
    if (isVirtualSpecified()) {
1411
7
      Keyword = "virtual";
1412
7
      SCLoc = getVirtualSpecLoc();
1413
7
      Hint = FixItHint::CreateRemoval(SCLoc);
1414
7
    } else {
1415
7
      Keyword = "explicit";
1416
7
      SCLoc = getExplicitSpecLoc();
1417
7
      Hint = FixItHint::CreateRemoval(getExplicitSpecRange());
1418
7
    }
1419
1420
14
    S.Diag(SCLoc, diag::err_friend_decl_spec)
1421
14
      << Keyword << Hint;
1422
1423
14
    FS_virtual_specified = false;
1424
14
    FS_explicit_specifier = ExplicitSpecifier();
1425
14
    FS_virtualLoc = FS_explicitLoc = SourceLocation();
1426
14
  }
1427
1428
165M
  assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
1429
1430
  // Okay, now we can infer the real type.
1431
1432
  // TODO: return "auto function" and other bad things based on the real type.
1433
1434
  // 'data definition has no type or storage class'?
1435
165M
}
1436
1437
1.33M
bool DeclSpec::isMissingDeclaratorOk() {
1438
1.33M
  TST tst = getTypeSpecType();
1439
1.33M
  return isDeclRep(tst) && 
getRepAsDecl() != nullptr1.33M
&&
1440
1.33M
    
StorageClassSpec != DeclSpec::SCS_typedef1.33M
;
1441
1.33M
}
1442
1443
void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc,
1444
                                          OverloadedOperatorKind Op,
1445
360k
                                          SourceLocation SymbolLocations[3]) {
1446
360k
  Kind = UnqualifiedIdKind::IK_OperatorFunctionId;
1447
360k
  StartLocation = OperatorLoc;
1448
360k
  EndLocation = OperatorLoc;
1449
360k
  new (&OperatorFunctionId) struct OFI;
1450
360k
  OperatorFunctionId.Operator = Op;
1451
1.44M
  for (unsigned I = 0; I != 3; 
++I1.08M
) {
1452
1.08M
    OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I];
1453
1454
1.08M
    if (SymbolLocations[I].isValid())
1455
467k
      EndLocation = SymbolLocations[I];
1456
1.08M
  }
1457
360k
}
1458
1459
bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc,
1460
557
                                  const char *&PrevSpec) {
1461
557
  if (!FirstLocation.isValid())
1462
535
    FirstLocation = Loc;
1463
557
  LastLocation = Loc;
1464
557
  LastSpecifier = VS;
1465
1466
557
  if (Specifiers & VS) {
1467
4
    PrevSpec = getSpecifierName(VS);
1468
4
    return true;
1469
4
  }
1470
1471
553
  Specifiers |= VS;
1472
1473
553
  switch (VS) {
1474
0
  default: llvm_unreachable("Unknown specifier!");
1475
452
  case VS_Override: VS_overrideLoc = Loc; break;
1476
2
  case VS_GNU_Final:
1477
8
  case VS_Sealed:
1478
89
  case VS_Final:    VS_finalLoc = Loc; break;
1479
12
  case VS_Abstract: VS_abstractLoc = Loc; break;
1480
553
  }
1481
1482
553
  return false;
1483
553
}
1484
1485
751
const char *VirtSpecifiers::getSpecifierName(Specifier VS) {
1486
751
  switch (VS) {
1487
0
  default: llvm_unreachable("Unknown specifier");
1488
461
  case VS_Override: return "override";
1489
281
  case VS_Final: return "final";
1490
0
  case VS_GNU_Final: return "__final";
1491
6
  case VS_Sealed: return "sealed";
1492
3
  case VS_Abstract: return "abstract";
1493
751
  }
1494
751
}