Coverage Report

Created: 2019-07-24 05:18

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