Coverage Report

Created: 2020-09-19 12:23

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