Coverage Report

Created: 2020-02-25 14:32

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