Coverage Report

Created: 2021-01-23 06:44

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