Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Parse/ParseDecl.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- ParseDecl.cpp - Declaration Parsing --------------------*- C++ -*-===//
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 the Declaration portions of the Parser interfaces.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/ASTContext.h"
14
#include "clang/AST/DeclTemplate.h"
15
#include "clang/AST/PrettyDeclStackTrace.h"
16
#include "clang/Basic/AddressSpaces.h"
17
#include "clang/Basic/AttributeCommonInfo.h"
18
#include "clang/Basic/Attributes.h"
19
#include "clang/Basic/CharInfo.h"
20
#include "clang/Basic/TargetInfo.h"
21
#include "clang/Parse/ParseDiagnostic.h"
22
#include "clang/Parse/Parser.h"
23
#include "clang/Parse/RAIIObjectsForParser.h"
24
#include "clang/Sema/Lookup.h"
25
#include "clang/Sema/ParsedTemplate.h"
26
#include "clang/Sema/Scope.h"
27
#include "clang/Sema/SemaDiagnostic.h"
28
#include "llvm/ADT/Optional.h"
29
#include "llvm/ADT/SmallSet.h"
30
#include "llvm/ADT/SmallString.h"
31
#include "llvm/ADT/StringSwitch.h"
32
33
using namespace clang;
34
35
//===----------------------------------------------------------------------===//
36
// C99 6.7: Declarations.
37
//===----------------------------------------------------------------------===//
38
39
/// ParseTypeName
40
///       type-name: [C99 6.7.6]
41
///         specifier-qualifier-list abstract-declarator[opt]
42
///
43
/// Called type-id in C++.
44
TypeResult Parser::ParseTypeName(SourceRange *Range, DeclaratorContext Context,
45
                                 AccessSpecifier AS, Decl **OwnedType,
46
5.46M
                                 ParsedAttributes *Attrs) {
47
5.46M
  DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
48
5.46M
  if (DSC == DeclSpecContext::DSC_normal)
49
278k
    DSC = DeclSpecContext::DSC_type_specifier;
50
51
  // Parse the common declaration-specifiers piece.
52
5.46M
  DeclSpec DS(AttrFactory);
53
5.46M
  if (Attrs)
54
128k
    DS.addAttributes(*Attrs);
55
5.46M
  ParseSpecifierQualifierList(DS, AS, DSC);
56
5.46M
  if (OwnedType)
57
128k
    *OwnedType = DS.isTypeSpecOwned() ? 
DS.getRepAsDecl()48
:
nullptr128k
;
58
59
  // Parse the abstract-declarator, if present.
60
5.46M
  Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), Context);
61
5.46M
  ParseDeclarator(DeclaratorInfo);
62
5.46M
  if (Range)
63
11.9k
    *Range = DeclaratorInfo.getSourceRange();
64
65
5.46M
  if (DeclaratorInfo.isInvalidType())
66
658
    return true;
67
68
5.46M
  return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
69
5.46M
}
70
71
/// Normalizes an attribute name by dropping prefixed and suffixed __.
72
148M
static StringRef normalizeAttrName(StringRef Name) {
73
148M
  if (Name.size() >= 4 && 
Name.startswith("__")148M
&&
Name.endswith("__")142M
)
74
32.7M
    return Name.drop_front(2).drop_back(2);
75
115M
  return Name;
76
148M
}
77
78
/// isAttributeLateParsed - Return true if the attribute has arguments that
79
/// require late parsing.
80
3.31M
static bool isAttributeLateParsed(const IdentifierInfo &II) {
81
3.31M
#define CLANG_ATTR_LATE_PARSED_LIST
82
3.31M
    return llvm::StringSwitch<bool>(normalizeAttrName(II.getName()))
83
3.31M
#include "clang/Parse/AttrParserStringSwitches.inc"
84
3.31M
        .Default(false);
85
3.31M
#undef CLANG_ATTR_LATE_PARSED_LIST
86
3.31M
}
87
88
/// Check if the a start and end source location expand to the same macro.
89
static bool FindLocsWithCommonFileID(Preprocessor &PP, SourceLocation StartLoc,
90
48.9M
                                     SourceLocation EndLoc) {
91
48.9M
  if (!StartLoc.isMacroID() || 
!EndLoc.isMacroID()30.4M
)
92
18.4M
    return false;
93
94
30.4M
  SourceManager &SM = PP.getSourceManager();
95
30.4M
  if (SM.getFileID(StartLoc) != SM.getFileID(EndLoc))
96
53.5k
    return false;
97
98
30.3M
  bool AttrStartIsInMacro =
99
30.3M
      Lexer::isAtStartOfMacroExpansion(StartLoc, SM, PP.getLangOpts());
100
30.3M
  bool AttrEndIsInMacro =
101
30.3M
      Lexer::isAtEndOfMacroExpansion(EndLoc, SM, PP.getLangOpts());
102
30.3M
  return AttrStartIsInMacro && 
AttrEndIsInMacro6.87M
;
103
30.4M
}
104
105
void Parser::ParseAttributes(unsigned WhichAttrKinds, ParsedAttributes &Attrs,
106
23.5M
                             LateParsedAttrList *LateAttrs) {
107
23.5M
  bool MoreToParse;
108
47.0M
  do {
109
    // Assume there's nothing left to parse, but if any attributes are in fact
110
    // parsed, loop to ensure all specified attribute combinations are parsed.
111
47.0M
    MoreToParse = false;
112
47.0M
    if (WhichAttrKinds & PAKM_CXX11)
113
1.73M
      MoreToParse |= MaybeParseCXX11Attributes(Attrs);
114
47.0M
    if (WhichAttrKinds & PAKM_GNU)
115
47.0M
      MoreToParse |= MaybeParseGNUAttributes(Attrs, LateAttrs);
116
47.0M
    if (WhichAttrKinds & PAKM_Declspec)
117
46.0M
      MoreToParse |= MaybeParseMicrosoftDeclSpecs(Attrs);
118
47.0M
  } while (MoreToParse);
119
23.5M
}
120
121
/// ParseGNUAttributes - Parse a non-empty attributes list.
122
///
123
/// [GNU] attributes:
124
///         attribute
125
///         attributes attribute
126
///
127
/// [GNU]  attribute:
128
///          '__attribute__' '(' '(' attribute-list ')' ')'
129
///
130
/// [GNU]  attribute-list:
131
///          attrib
132
///          attribute_list ',' attrib
133
///
134
/// [GNU]  attrib:
135
///          empty
136
///          attrib-name
137
///          attrib-name '(' identifier ')'
138
///          attrib-name '(' identifier ',' nonempty-expr-list ')'
139
///          attrib-name '(' argument-expression-list [C99 6.5.2] ')'
140
///
141
/// [GNU]  attrib-name:
142
///          identifier
143
///          typespec
144
///          typequal
145
///          storageclass
146
///
147
/// Whether an attribute takes an 'identifier' is determined by the
148
/// attrib-name. GCC's behavior here is not worth imitating:
149
///
150
///  * In C mode, if the attribute argument list starts with an identifier
151
///    followed by a ',' or an ')', and the identifier doesn't resolve to
152
///    a type, it is parsed as an identifier. If the attribute actually
153
///    wanted an expression, it's out of luck (but it turns out that no
154
///    attributes work that way, because C constant expressions are very
155
///    limited).
156
///  * In C++ mode, if the attribute argument list starts with an identifier,
157
///    and the attribute *wants* an identifier, it is parsed as an identifier.
158
///    At block scope, any additional tokens between the identifier and the
159
///    ',' or ')' are ignored, otherwise they produce a parse error.
160
///
161
/// We follow the C++ model, but don't allow junk after the identifier.
162
void Parser::ParseGNUAttributes(ParsedAttributes &Attrs,
163
25.8M
                                LateParsedAttrList *LateAttrs, Declarator *D) {
164
25.8M
  assert(Tok.is(tok::kw___attribute) && "Not a GNU attribute list!");
165
166
0
  SourceLocation StartLoc = Tok.getLocation();
167
25.8M
  SourceLocation EndLoc = StartLoc;
168
169
74.7M
  while (Tok.is(tok::kw___attribute)) {
170
48.9M
    SourceLocation AttrTokLoc = ConsumeToken();
171
48.9M
    unsigned OldNumAttrs = Attrs.size();
172
48.9M
    unsigned OldNumLateAttrs = LateAttrs ? 
LateAttrs->size()4.18M
:
044.7M
;
173
174
48.9M
    if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
175
48.9M
                         "attribute")) {
176
0
      SkipUntil(tok::r_paren, StopAtSemi); // skip until ) or ;
177
0
      return;
178
0
    }
179
48.9M
    if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, "(")) {
180
0
      SkipUntil(tok::r_paren, StopAtSemi); // skip until ) or ;
181
0
      return;
182
0
    }
183
    // Parse the attribute-list. e.g. __attribute__(( weak, alias("__f") ))
184
79.3M
    
do 48.9M
{
185
      // Eat preceeding commas to allow __attribute__((,,,foo))
186
109M
      while (TryConsumeToken(tok::comma))
187
30.3M
        ;
188
189
      // Expect an identifier or declaration specifier (const, int, etc.)
190
79.3M
      if (Tok.isAnnotation())
191
0
        break;
192
79.3M
      if (Tok.is(tok::code_completion)) {
193
1
        cutOffParsing();
194
1
        Actions.CodeCompleteAttribute(AttributeCommonInfo::Syntax::AS_GNU);
195
1
        break;
196
1
      }
197
79.3M
      IdentifierInfo *AttrName = Tok.getIdentifierInfo();
198
79.3M
      if (!AttrName)
199
69
        break;
200
201
79.3M
      SourceLocation AttrNameLoc = ConsumeToken();
202
203
79.3M
      if (Tok.isNot(tok::l_paren)) {
204
49.2M
        Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
205
49.2M
                     ParsedAttr::AS_GNU);
206
49.2M
        continue;
207
49.2M
      }
208
209
      // Handle "parameterized" attributes
210
30.1M
      if (!LateAttrs || 
!isAttributeLateParsed(*AttrName)3.31M
) {
211
30.0M
        ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, &EndLoc, nullptr,
212
30.0M
                              SourceLocation(), ParsedAttr::AS_GNU, D);
213
30.0M
        continue;
214
30.0M
      }
215
216
      // Handle attributes with arguments that require late parsing.
217
11.2k
      LateParsedAttribute *LA =
218
11.2k
          new LateParsedAttribute(this, *AttrName, AttrNameLoc);
219
11.2k
      LateAttrs->push_back(LA);
220
221
      // Attributes in a class are parsed at the end of the class, along
222
      // with other late-parsed declarations.
223
11.2k
      if (!ClassStack.empty() && 
!LateAttrs->parseSoon()5.62k
)
224
5.62k
        getCurrentClass().LateParsedDeclarations.push_back(LA);
225
226
      // Be sure ConsumeAndStoreUntil doesn't see the start l_paren, since it
227
      // recursively consumes balanced parens.
228
11.2k
      LA->Toks.push_back(Tok);
229
11.2k
      ConsumeParen();
230
      // Consume everything up to and including the matching right parens.
231
11.2k
      ConsumeAndStoreUntil(tok::r_paren, LA->Toks, /*StopAtSemi=*/true);
232
233
11.2k
      Token Eof;
234
11.2k
      Eof.startToken();
235
11.2k
      Eof.setLocation(Tok.getLocation());
236
11.2k
      LA->Toks.push_back(Eof);
237
79.3M
    } while (Tok.is(tok::comma));
238
239
48.9M
    if (ExpectAndConsume(tok::r_paren))
240
4
      SkipUntil(tok::r_paren, StopAtSemi);
241
48.9M
    SourceLocation Loc = Tok.getLocation();
242
48.9M
    if (ExpectAndConsume(tok::r_paren))
243
2
      SkipUntil(tok::r_paren, StopAtSemi);
244
48.9M
    EndLoc = Loc;
245
246
    // If this was declared in a macro, attach the macro IdentifierInfo to the
247
    // parsed attribute.
248
48.9M
    auto &SM = PP.getSourceManager();
249
48.9M
    if (!SM.isWrittenInBuiltinFile(SM.getSpellingLoc(AttrTokLoc)) &&
250
48.9M
        
FindLocsWithCommonFileID(PP, AttrTokLoc, Loc)48.9M
) {
251
4.10M
      CharSourceRange ExpansionRange = SM.getExpansionRange(AttrTokLoc);
252
4.10M
      StringRef FoundName =
253
4.10M
          Lexer::getSourceText(ExpansionRange, SM, PP.getLangOpts());
254
4.10M
      IdentifierInfo *MacroII = PP.getIdentifierInfo(FoundName);
255
256
11.8M
      for (unsigned i = OldNumAttrs; i < Attrs.size(); 
++i7.79M
)
257
7.79M
        Attrs[i].setMacroIdentifier(MacroII, ExpansionRange.getBegin());
258
259
4.10M
      if (LateAttrs) {
260
809k
        for (unsigned i = OldNumLateAttrs; i < LateAttrs->size(); 
++i10.9k
)
261
10.9k
          (*LateAttrs)[i]->MacroII = MacroII;
262
798k
      }
263
4.10M
    }
264
48.9M
  }
265
266
25.8M
  Attrs.Range = SourceRange(StartLoc, EndLoc);
267
25.8M
}
268
269
/// Determine whether the given attribute has an identifier argument.
270
18.4M
static bool attributeHasIdentifierArg(const IdentifierInfo &II) {
271
18.4M
#define CLANG_ATTR_IDENTIFIER_ARG_LIST
272
18.4M
  return llvm::StringSwitch<bool>(normalizeAttrName(II.getName()))
273
18.4M
#include "clang/Parse/AttrParserStringSwitches.inc"
274
18.4M
           .Default(false);
275
18.4M
#undef CLANG_ATTR_IDENTIFIER_ARG_LIST
276
18.4M
}
277
278
/// Determine whether the given attribute has a variadic identifier argument.
279
24.1M
static bool attributeHasVariadicIdentifierArg(const IdentifierInfo &II) {
280
24.1M
#define CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
281
24.1M
  return llvm::StringSwitch<bool>(normalizeAttrName(II.getName()))
282
24.1M
#include "clang/Parse/AttrParserStringSwitches.inc"
283
24.1M
           .Default(false);
284
24.1M
#undef CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
285
24.1M
}
286
287
/// Determine whether the given attribute treats kw_this as an identifier.
288
24.1M
static bool attributeTreatsKeywordThisAsIdentifier(const IdentifierInfo &II) {
289
24.1M
#define CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
290
24.1M
  return llvm::StringSwitch<bool>(normalizeAttrName(II.getName()))
291
24.1M
#include "clang/Parse/AttrParserStringSwitches.inc"
292
24.1M
           .Default(false);
293
24.1M
#undef CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
294
24.1M
}
295
296
/// Determine if an attribute accepts parameter packs.
297
24
static bool attributeAcceptsExprPack(const IdentifierInfo &II) {
298
24
#define CLANG_ATTR_ACCEPTS_EXPR_PACK
299
24
  return llvm::StringSwitch<bool>(normalizeAttrName(II.getName()))
300
24
#include "clang/Parse/AttrParserStringSwitches.inc"
301
24
      .Default(false);
302
24
#undef CLANG_ATTR_ACCEPTS_EXPR_PACK
303
24
}
304
305
/// Determine whether the given attribute parses a type argument.
306
48.2M
static bool attributeIsTypeArgAttr(const IdentifierInfo &II) {
307
48.2M
#define CLANG_ATTR_TYPE_ARG_LIST
308
48.2M
  return llvm::StringSwitch<bool>(normalizeAttrName(II.getName()))
309
48.2M
#include "clang/Parse/AttrParserStringSwitches.inc"
310
48.2M
           .Default(false);
311
48.2M
#undef CLANG_ATTR_TYPE_ARG_LIST
312
48.2M
}
313
314
/// Determine whether the given attribute requires parsing its arguments
315
/// in an unevaluated context or not.
316
5.72M
static bool attributeParsedArgsUnevaluated(const IdentifierInfo &II) {
317
5.72M
#define CLANG_ATTR_ARG_CONTEXT_LIST
318
5.72M
  return llvm::StringSwitch<bool>(normalizeAttrName(II.getName()))
319
5.72M
#include "clang/Parse/AttrParserStringSwitches.inc"
320
5.72M
           .Default(false);
321
5.72M
#undef CLANG_ATTR_ARG_CONTEXT_LIST
322
5.72M
}
323
324
24.3M
IdentifierLoc *Parser::ParseIdentifierLoc() {
325
24.3M
  assert(Tok.is(tok::identifier) && "expected an identifier");
326
0
  IdentifierLoc *IL = IdentifierLoc::create(Actions.Context,
327
24.3M
                                            Tok.getLocation(),
328
24.3M
                                            Tok.getIdentifierInfo());
329
24.3M
  ConsumeToken();
330
24.3M
  return IL;
331
24.3M
}
332
333
void Parser::ParseAttributeWithTypeArg(IdentifierInfo &AttrName,
334
                                       SourceLocation AttrNameLoc,
335
                                       ParsedAttributes &Attrs,
336
                                       IdentifierInfo *ScopeName,
337
                                       SourceLocation ScopeLoc,
338
15.5k
                                       ParsedAttr::Syntax Syntax) {
339
15.5k
  BalancedDelimiterTracker Parens(*this, tok::l_paren);
340
15.5k
  Parens.consumeOpen();
341
342
15.5k
  TypeResult T;
343
15.5k
  if (Tok.isNot(tok::r_paren))
344
15.5k
    T = ParseTypeName();
345
346
15.5k
  if (Parens.consumeClose())
347
5
    return;
348
349
15.5k
  if (T.isInvalid())
350
5
    return;
351
352
15.5k
  if (T.isUsable())
353
15.5k
    Attrs.addNewTypeAttr(&AttrName,
354
15.5k
                         SourceRange(AttrNameLoc, Parens.getCloseLocation()),
355
15.5k
                         ScopeName, ScopeLoc, T.get(), Syntax);
356
4
  else
357
4
    Attrs.addNew(&AttrName, SourceRange(AttrNameLoc, Parens.getCloseLocation()),
358
4
                 ScopeName, ScopeLoc, nullptr, 0, Syntax);
359
15.5k
}
360
361
unsigned Parser::ParseAttributeArgsCommon(
362
    IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
363
    ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName,
364
24.1M
    SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) {
365
  // Ignore the left paren location for now.
366
24.1M
  ConsumeParen();
367
368
24.1M
  bool ChangeKWThisToIdent = attributeTreatsKeywordThisAsIdentifier(*AttrName);
369
24.1M
  bool AttributeIsTypeArgAttr = attributeIsTypeArgAttr(*AttrName);
370
24.1M
  bool AttributeHasVariadicIdentifierArg =
371
24.1M
      attributeHasVariadicIdentifierArg(*AttrName);
372
373
  // Interpret "kw_this" as an identifier if the attributed requests it.
374
24.1M
  if (ChangeKWThisToIdent && 
Tok.is(tok::kw_this)142
)
375
1
    Tok.setKind(tok::identifier);
376
377
24.1M
  ArgsVector ArgExprs;
378
24.1M
  if (Tok.is(tok::identifier)) {
379
    // If this attribute wants an 'identifier' argument, make it so.
380
18.4M
    bool IsIdentifierArg = AttributeHasVariadicIdentifierArg ||
381
18.4M
                           
attributeHasIdentifierArg(*AttrName)18.4M
;
382
18.4M
    ParsedAttr::Kind AttrKind =
383
18.4M
        ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax);
384
385
    // If we don't know how to parse this attribute, but this is the only
386
    // token in this argument, assume it's meant to be an identifier.
387
18.4M
    if (AttrKind == ParsedAttr::UnknownAttribute ||
388
18.4M
        
AttrKind == ParsedAttr::IgnoredAttribute18.4M
) {
389
7
      const Token &Next = NextToken();
390
7
      IsIdentifierArg = Next.isOneOf(tok::r_paren, tok::comma);
391
7
    }
392
393
18.4M
    if (IsIdentifierArg)
394
18.4M
      ArgExprs.push_back(ParseIdentifierLoc());
395
18.4M
  }
396
397
24.1M
  ParsedType TheParsedType;
398
24.1M
  if (!ArgExprs.empty() ? 
Tok.is(tok::comma)18.4M
:
Tok.isNot(tok::r_paren)5.68M
) {
399
    // Eat the comma.
400
5.72M
    if (!ArgExprs.empty())
401
37.1k
      ConsumeToken();
402
403
5.72M
    if (AttributeIsTypeArgAttr) {
404
      // FIXME: Multiple type arguments are not implemented.
405
59
      TypeResult T = ParseTypeName();
406
59
      if (T.isInvalid()) {
407
4
        SkipUntil(tok::r_paren, StopAtSemi);
408
4
        return 0;
409
4
      }
410
55
      if (T.isUsable())
411
55
        TheParsedType = T.get();
412
5.72M
    } else if (AttributeHasVariadicIdentifierArg) {
413
      // Parse variadic identifier arg. This can either consume identifiers or
414
      // expressions. Variadic identifier args do not support parameter packs
415
      // because those are typically used for attributes with enumeration
416
      // arguments, and those enumerations are not something the user could
417
      // express via a pack.
418
342
      do {
419
        // Interpret "kw_this" as an identifier if the attributed requests it.
420
342
        if (ChangeKWThisToIdent && 
Tok.is(tok::kw_this)269
)
421
4
          Tok.setKind(tok::identifier);
422
423
342
        ExprResult ArgExpr;
424
342
        if (Tok.is(tok::identifier)) {
425
150
          ArgExprs.push_back(ParseIdentifierLoc());
426
192
        } else {
427
192
          bool Uneval = attributeParsedArgsUnevaluated(*AttrName);
428
192
          EnterExpressionEvaluationContext Unevaluated(
429
192
              Actions,
430
192
              Uneval ? 
Sema::ExpressionEvaluationContext::Unevaluated0
431
192
                     : Sema::ExpressionEvaluationContext::ConstantEvaluated);
432
433
192
          ExprResult ArgExpr(
434
192
              Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
435
436
192
          if (ArgExpr.isInvalid()) {
437
0
            SkipUntil(tok::r_paren, StopAtSemi);
438
0
            return 0;
439
0
          }
440
192
          ArgExprs.push_back(ArgExpr.get());
441
192
        }
442
        // Eat the comma, move to the next argument
443
342
      } while (TryConsumeToken(tok::comma));
444
5.72M
    } else {
445
      // General case. Parse all available expressions.
446
5.72M
      bool Uneval = attributeParsedArgsUnevaluated(*AttrName);
447
5.72M
      EnterExpressionEvaluationContext Unevaluated(
448
5.72M
          Actions, Uneval
449
5.72M
                       ? 
Sema::ExpressionEvaluationContext::Unevaluated2.89k
450
5.72M
                       : 
Sema::ExpressionEvaluationContext::ConstantEvaluated5.71M
);
451
452
5.72M
      CommaLocsTy CommaLocs;
453
5.72M
      ExprVector ParsedExprs;
454
5.72M
      if (ParseExpressionList(ParsedExprs, CommaLocs,
455
5.72M
                              llvm::function_ref<void()>(),
456
5.72M
                              /*FailImmediatelyOnInvalidExpr=*/true,
457
5.72M
                              /*EarlyTypoCorrection=*/true)) {
458
46
        SkipUntil(tok::r_paren, StopAtSemi);
459
46
        return 0;
460
46
      }
461
462
      // Pack expansion must currently be explicitly supported by an attribute.
463
11.5M
      
for (size_t I = 0; 5.72M
I < ParsedExprs.size();
++I5.79M
) {
464
5.79M
        if (!isa<PackExpansionExpr>(ParsedExprs[I]))
465
5.79M
          continue;
466
467
24
        if (!attributeAcceptsExprPack(*AttrName)) {
468
1
          Diag(Tok.getLocation(),
469
1
               diag::err_attribute_argument_parm_pack_not_supported)
470
1
              << AttrName;
471
1
          SkipUntil(tok::r_paren, StopAtSemi);
472
1
          return 0;
473
1
        }
474
24
      }
475
476
5.72M
      ArgExprs.insert(ArgExprs.end(), ParsedExprs.begin(), ParsedExprs.end());
477
5.72M
    }
478
5.72M
  }
479
480
24.1M
  SourceLocation RParen = Tok.getLocation();
481
24.1M
  if (!ExpectAndConsume(tok::r_paren)) {
482
24.1M
    SourceLocation AttrLoc = ScopeLoc.isValid() ? 
ScopeLoc476
:
AttrNameLoc24.1M
;
483
484
24.1M
    if (AttributeIsTypeArgAttr && 
!TheParsedType.get().isNull()58
) {
485
55
      Attrs.addNewTypeAttr(AttrName, SourceRange(AttrNameLoc, RParen),
486
55
                           ScopeName, ScopeLoc, TheParsedType, Syntax);
487
24.1M
    } else {
488
24.1M
      Attrs.addNew(AttrName, SourceRange(AttrLoc, RParen), ScopeName, ScopeLoc,
489
24.1M
                   ArgExprs.data(), ArgExprs.size(), Syntax);
490
24.1M
    }
491
24.1M
  }
492
493
24.1M
  if (EndLoc)
494
24.1M
    *EndLoc = RParen;
495
496
24.1M
  return static_cast<unsigned>(ArgExprs.size() + !TheParsedType.get().isNull());
497
24.1M
}
498
499
/// Parse the arguments to a parameterized GNU attribute or
500
/// a C++11 attribute in "gnu" namespace.
501
void Parser::ParseGNUAttributeArgs(
502
    IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
503
    ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName,
504
30.1M
    SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax, Declarator *D) {
505
506
30.1M
  assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('");
507
508
0
  ParsedAttr::Kind AttrKind =
509
30.1M
      ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax);
510
511
30.1M
  if (AttrKind == ParsedAttr::AT_Availability) {
512
5.96M
    ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
513
5.96M
                               ScopeLoc, Syntax);
514
5.96M
    return;
515
24.1M
  } else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) {
516
75
    ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
517
75
                                       ScopeName, ScopeLoc, Syntax);
518
75
    return;
519
24.1M
  } else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) {
520
476
    ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
521
476
                                    ScopeName, ScopeLoc, Syntax);
522
476
    return;
523
24.1M
  } else if (AttrKind == ParsedAttr::AT_SwiftNewType) {
524
11.0k
    ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
525
11.0k
                               ScopeLoc, Syntax);
526
11.0k
    return;
527
24.1M
  } else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) {
528
180
    ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
529
180
                                     ScopeName, ScopeLoc, Syntax);
530
180
    return;
531
24.1M
  } else if (attributeIsTypeArgAttr(*AttrName)) {
532
15.5k
    ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, ScopeName,
533
15.5k
                              ScopeLoc, Syntax);
534
15.5k
    return;
535
15.5k
  }
536
537
  // These may refer to the function arguments, but need to be parsed early to
538
  // participate in determining whether it's a redeclaration.
539
24.1M
  llvm::Optional<ParseScope> PrototypeScope;
540
24.1M
  if (normalizeAttrName(AttrName->getName()) == "enable_if" &&
541
24.1M
      
D10.9k
&&
D->isFunctionDeclarator()276
) {
542
275
    DeclaratorChunk::FunctionTypeInfo FTI = D->getFunctionTypeInfo();
543
275
    PrototypeScope.emplace(this, Scope::FunctionPrototypeScope |
544
275
                                     Scope::FunctionDeclarationScope |
545
275
                                     Scope::DeclScope);
546
534
    for (unsigned i = 0; i != FTI.NumParams; 
++i259
) {
547
259
      ParmVarDecl *Param = cast<ParmVarDecl>(FTI.Params[i].Param);
548
259
      Actions.ActOnReenterCXXMethodParameter(getCurScope(), Param);
549
259
    }
550
275
  }
551
552
24.1M
  ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
553
24.1M
                           ScopeLoc, Syntax);
554
24.1M
}
555
556
unsigned Parser::ParseClangAttributeArgs(
557
    IdentifierInfo *AttrName, SourceLocation AttrNameLoc,
558
    ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName,
559
322
    SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) {
560
322
  assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('");
561
562
0
  ParsedAttr::Kind AttrKind =
563
322
      ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax);
564
565
322
  switch (AttrKind) {
566
296
  default:
567
296
    return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
568
296
                                    ScopeName, ScopeLoc, Syntax);
569
5
  case ParsedAttr::AT_ExternalSourceSymbol:
570
5
    ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
571
5
                                       ScopeName, ScopeLoc, Syntax);
572
5
    break;
573
8
  case ParsedAttr::AT_Availability:
574
8
    ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
575
8
                               ScopeLoc, Syntax);
576
8
    break;
577
4
  case ParsedAttr::AT_ObjCBridgeRelated:
578
4
    ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
579
4
                                    ScopeName, ScopeLoc, Syntax);
580
4
    break;
581
0
  case ParsedAttr::AT_SwiftNewType:
582
0
    ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
583
0
                               ScopeLoc, Syntax);
584
0
    break;
585
9
  case ParsedAttr::AT_TypeTagForDatatype:
586
9
    ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
587
9
                                     ScopeName, ScopeLoc, Syntax);
588
9
    break;
589
322
  }
590
26
  return !Attrs.empty() ? 
Attrs.begin()->getNumArgs()18
:
08
;
591
322
}
592
593
bool Parser::ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,
594
                                        SourceLocation AttrNameLoc,
595
578
                                        ParsedAttributes &Attrs) {
596
578
  unsigned ExistingAttrs = Attrs.size();
597
598
  // If the attribute isn't known, we will not attempt to parse any
599
  // arguments.
600
578
  if (!hasAttribute(AttributeCommonInfo::Syntax::AS_Declspec, nullptr, AttrName,
601
578
                    getTargetInfo(), getLangOpts())) {
602
    // Eat the left paren, then skip to the ending right paren.
603
1
    ConsumeParen();
604
1
    SkipUntil(tok::r_paren);
605
1
    return false;
606
1
  }
607
608
577
  SourceLocation OpenParenLoc = Tok.getLocation();
609
610
577
  if (AttrName->getName() == "property") {
611
    // The property declspec is more complex in that it can take one or two
612
    // assignment expressions as a parameter, but the lhs of the assignment
613
    // must be named get or put.
614
615
103
    BalancedDelimiterTracker T(*this, tok::l_paren);
616
103
    T.expectAndConsume(diag::err_expected_lparen_after,
617
103
                       AttrName->getNameStart(), tok::r_paren);
618
619
103
    enum AccessorKind {
620
103
      AK_Invalid = -1,
621
103
      AK_Put = 0,
622
103
      AK_Get = 1 // indices into AccessorNames
623
103
    };
624
103
    IdentifierInfo *AccessorNames[] = {nullptr, nullptr};
625
103
    bool HasInvalidAccessor = false;
626
627
    // Parse the accessor specifications.
628
140
    while (true) {
629
      // Stop if this doesn't look like an accessor spec.
630
140
      if (!Tok.is(tok::identifier)) {
631
        // If the user wrote a completely empty list, use a special diagnostic.
632
2
        if (Tok.is(tok::r_paren) && !HasInvalidAccessor &&
633
2
            AccessorNames[AK_Put] == nullptr &&
634
2
            AccessorNames[AK_Get] == nullptr) {
635
1
          Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
636
1
          break;
637
1
        }
638
639
1
        Diag(Tok.getLocation(), diag::err_ms_property_unknown_accessor);
640
1
        break;
641
2
      }
642
643
138
      AccessorKind Kind;
644
138
      SourceLocation KindLoc = Tok.getLocation();
645
138
      StringRef KindStr = Tok.getIdentifierInfo()->getName();
646
138
      if (KindStr == "get") {
647
97
        Kind = AK_Get;
648
97
      } else 
if (41
KindStr == "put"41
) {
649
38
        Kind = AK_Put;
650
651
        // Recover from the common mistake of using 'set' instead of 'put'.
652
38
      } else 
if (3
KindStr == "set"3
) {
653
1
        Diag(KindLoc, diag::err_ms_property_has_set_accessor)
654
1
            << FixItHint::CreateReplacement(KindLoc, "put");
655
1
        Kind = AK_Put;
656
657
        // Handle the mistake of forgetting the accessor kind by skipping
658
        // this accessor.
659
2
      } else if (NextToken().is(tok::comma) || NextToken().is(tok::r_paren)) {
660
1
        Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
661
1
        ConsumeToken();
662
1
        HasInvalidAccessor = true;
663
1
        goto next_property_accessor;
664
665
        // Otherwise, complain about the unknown accessor kind.
666
1
      } else {
667
1
        Diag(KindLoc, diag::err_ms_property_unknown_accessor);
668
1
        HasInvalidAccessor = true;
669
1
        Kind = AK_Invalid;
670
671
        // Try to keep parsing unless it doesn't look like an accessor spec.
672
1
        if (!NextToken().is(tok::equal))
673
0
          break;
674
1
      }
675
676
      // Consume the identifier.
677
137
      ConsumeToken();
678
679
      // Consume the '='.
680
137
      if (!TryConsumeToken(tok::equal)) {
681
3
        Diag(Tok.getLocation(), diag::err_ms_property_expected_equal)
682
3
            << KindStr;
683
3
        break;
684
3
      }
685
686
      // Expect the method name.
687
134
      if (!Tok.is(tok::identifier)) {
688
1
        Diag(Tok.getLocation(), diag::err_ms_property_expected_accessor_name);
689
1
        break;
690
1
      }
691
692
133
      if (Kind == AK_Invalid) {
693
        // Just drop invalid accessors.
694
132
      } else if (AccessorNames[Kind] != nullptr) {
695
        // Complain about the repeated accessor, ignore it, and keep parsing.
696
1
        Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
697
131
      } else {
698
131
        AccessorNames[Kind] = Tok.getIdentifierInfo();
699
131
      }
700
133
      ConsumeToken();
701
702
134
    next_property_accessor:
703
      // Keep processing accessors until we run out.
704
134
      if (TryConsumeToken(tok::comma))
705
37
        continue;
706
707
      // If we run into the ')', stop without consuming it.
708
97
      if (Tok.is(tok::r_paren))
709
96
        break;
710
711
1
      Diag(Tok.getLocation(), diag::err_ms_property_expected_comma_or_rparen);
712
1
      break;
713
97
    }
714
715
    // Only add the property attribute if it was well-formed.
716
103
    if (!HasInvalidAccessor)
717
101
      Attrs.addNewPropertyAttr(AttrName, AttrNameLoc, nullptr, SourceLocation(),
718
101
                               AccessorNames[AK_Get], AccessorNames[AK_Put],
719
101
                               ParsedAttr::AS_Declspec);
720
103
    T.skipToEnd();
721
103
    return !HasInvalidAccessor;
722
103
  }
723
724
474
  unsigned NumArgs =
725
474
      ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, nullptr, nullptr,
726
474
                               SourceLocation(), ParsedAttr::AS_Declspec);
727
728
  // If this attribute's args were parsed, and it was expected to have
729
  // arguments but none were provided, emit a diagnostic.
730
474
  if (ExistingAttrs < Attrs.size() && 
Attrs.back().getMaxArgs()472
&&
!NumArgs471
) {
731
1
    Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName;
732
1
    return false;
733
1
  }
734
473
  return true;
735
474
}
736
737
/// [MS] decl-specifier:
738
///             __declspec ( extended-decl-modifier-seq )
739
///
740
/// [MS] extended-decl-modifier-seq:
741
///             extended-decl-modifier[opt]
742
///             extended-decl-modifier extended-decl-modifier-seq
743
11.4k
void Parser::ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs) {
744
11.4k
  assert(getLangOpts().DeclSpecKeyword && "__declspec keyword is not enabled");
745
0
  assert(Tok.is(tok::kw___declspec) && "Not a declspec!");
746
747
0
  SourceLocation StartLoc = Tok.getLocation();
748
11.4k
  SourceLocation EndLoc = StartLoc;
749
750
22.9k
  while (Tok.is(tok::kw___declspec)) {
751
11.5k
    ConsumeToken();
752
11.5k
    BalancedDelimiterTracker T(*this, tok::l_paren);
753
11.5k
    if (T.expectAndConsume(diag::err_expected_lparen_after, "__declspec",
754
11.5k
                           tok::r_paren))
755
0
      return;
756
757
    // An empty declspec is perfectly legal and should not warn.  Additionally,
758
    // you can specify multiple attributes per declspec.
759
23.1k
    
while (11.5k
Tok.isNot(tok::r_paren)) {
760
      // Attribute not present.
761
11.5k
      if (TryConsumeToken(tok::comma))
762
4
        continue;
763
764
11.5k
      if (Tok.is(tok::code_completion)) {
765
1
        cutOffParsing();
766
1
        Actions.CodeCompleteAttribute(AttributeCommonInfo::AS_Declspec);
767
1
        return;
768
1
      }
769
770
      // We expect either a well-known identifier or a generic string.  Anything
771
      // else is a malformed declspec.
772
11.5k
      bool IsString = Tok.getKind() == tok::string_literal;
773
11.5k
      if (!IsString && 
Tok.getKind() != tok::identifier11.5k
&&
774
11.5k
          
Tok.getKind() != tok::kw_restrict2
) {
775
1
        Diag(Tok, diag::err_ms_declspec_type);
776
1
        T.skipToEnd();
777
1
        return;
778
1
      }
779
780
11.5k
      IdentifierInfo *AttrName;
781
11.5k
      SourceLocation AttrNameLoc;
782
11.5k
      if (IsString) {
783
2
        SmallString<8> StrBuffer;
784
2
        bool Invalid = false;
785
2
        StringRef Str = PP.getSpelling(Tok, StrBuffer, &Invalid);
786
2
        if (Invalid) {
787
0
          T.skipToEnd();
788
0
          return;
789
0
        }
790
2
        AttrName = PP.getIdentifierInfo(Str);
791
2
        AttrNameLoc = ConsumeStringToken();
792
11.5k
      } else {
793
11.5k
        AttrName = Tok.getIdentifierInfo();
794
11.5k
        AttrNameLoc = ConsumeToken();
795
11.5k
      }
796
797
11.5k
      bool AttrHandled = false;
798
799
      // Parse attribute arguments.
800
11.5k
      if (Tok.is(tok::l_paren))
801
578
        AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs);
802
10.9k
      else if (AttrName->getName() == "property")
803
        // The property attribute must have an argument list.
804
1
        Diag(Tok.getLocation(), diag::err_expected_lparen_after)
805
1
            << AttrName->getName();
806
807
11.5k
      if (!AttrHandled)
808
10.9k
        Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
809
10.9k
                     ParsedAttr::AS_Declspec);
810
11.5k
    }
811
11.5k
    T.consumeClose();
812
11.5k
    EndLoc = T.getCloseLocation();
813
11.5k
  }
814
815
11.4k
  Attrs.Range = SourceRange(StartLoc, EndLoc);
816
11.4k
}
817
818
349k
void Parser::ParseMicrosoftTypeAttributes(ParsedAttributes &attrs) {
819
  // Treat these like attributes
820
350k
  while (true) {
821
350k
    switch (Tok.getKind()) {
822
115
    case tok::kw___fastcall:
823
282
    case tok::kw___stdcall:
824
329
    case tok::kw___thiscall:
825
440
    case tok::kw___regcall:
826
749
    case tok::kw___cdecl:
827
886
    case tok::kw___vectorcall:
828
916
    case tok::kw___ptr64:
829
917
    case tok::kw___w64:
830
970
    case tok::kw___ptr32:
831
994
    case tok::kw___sptr:
832
1.01k
    case tok::kw___uptr: {
833
1.01k
      IdentifierInfo *AttrName = Tok.getIdentifierInfo();
834
1.01k
      SourceLocation AttrNameLoc = ConsumeToken();
835
1.01k
      attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
836
1.01k
                   ParsedAttr::AS_Keyword);
837
1.01k
      break;
838
994
    }
839
349k
    default:
840
349k
      return;
841
350k
    }
842
350k
  }
843
349k
}
844
845
304
void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
846
304
  SourceLocation StartLoc = Tok.getLocation();
847
304
  SourceLocation EndLoc = SkipExtendedMicrosoftTypeAttributes();
848
849
304
  if (EndLoc.isValid()) {
850
12
    SourceRange Range(StartLoc, EndLoc);
851
12
    Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) << Range;
852
12
  }
853
304
}
854
855
304
SourceLocation Parser::SkipExtendedMicrosoftTypeAttributes() {
856
304
  SourceLocation EndLoc;
857
858
330
  while (true) {
859
330
    switch (Tok.getKind()) {
860
2
    case tok::kw_const:
861
4
    case tok::kw_volatile:
862
6
    case tok::kw___fastcall:
863
8
    case tok::kw___stdcall:
864
10
    case tok::kw___thiscall:
865
12
    case tok::kw___cdecl:
866
14
    case tok::kw___vectorcall:
867
16
    case tok::kw___ptr32:
868
18
    case tok::kw___ptr64:
869
20
    case tok::kw___w64:
870
22
    case tok::kw___unaligned:
871
24
    case tok::kw___sptr:
872
26
    case tok::kw___uptr:
873
26
      EndLoc = ConsumeToken();
874
26
      break;
875
304
    default:
876
304
      return EndLoc;
877
330
    }
878
330
  }
879
304
}
880
881
18
void Parser::ParseBorlandTypeAttributes(ParsedAttributes &attrs) {
882
  // Treat these like attributes
883
36
  while (Tok.is(tok::kw___pascal)) {
884
18
    IdentifierInfo *AttrName = Tok.getIdentifierInfo();
885
18
    SourceLocation AttrNameLoc = ConsumeToken();
886
18
    attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
887
18
                 ParsedAttr::AS_Keyword);
888
18
  }
889
18
}
890
891
1.23k
void Parser::ParseOpenCLKernelAttributes(ParsedAttributes &attrs) {
892
  // Treat these like attributes
893
2.46k
  while (Tok.is(tok::kw___kernel)) {
894
1.23k
    IdentifierInfo *AttrName = Tok.getIdentifierInfo();
895
1.23k
    SourceLocation AttrNameLoc = ConsumeToken();
896
1.23k
    attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
897
1.23k
                 ParsedAttr::AS_Keyword);
898
1.23k
  }
899
1.23k
}
900
901
5
void Parser::ParseCUDAFunctionAttributes(ParsedAttributes &attrs) {
902
10
  while (Tok.is(tok::kw___noinline__)) {
903
5
    IdentifierInfo *AttrName = Tok.getIdentifierInfo();
904
5
    SourceLocation AttrNameLoc = ConsumeToken();
905
5
    attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
906
5
                 ParsedAttr::AS_Keyword);
907
5
  }
908
5
}
909
910
42.5k
void Parser::ParseOpenCLQualifiers(ParsedAttributes &Attrs) {
911
42.5k
  IdentifierInfo *AttrName = Tok.getIdentifierInfo();
912
42.5k
  SourceLocation AttrNameLoc = Tok.getLocation();
913
42.5k
  Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
914
42.5k
               ParsedAttr::AS_Keyword);
915
42.5k
}
916
917
668k
void Parser::ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs) {
918
  // Treat these like attributes, even though they're type specifiers.
919
1.33M
  while (true) {
920
1.33M
    switch (Tok.getKind()) {
921
104k
    case tok::kw__Nonnull:
922
639k
    case tok::kw__Nullable:
923
639k
    case tok::kw__Nullable_result:
924
668k
    case tok::kw__Null_unspecified: {
925
668k
      IdentifierInfo *AttrName = Tok.getIdentifierInfo();
926
668k
      SourceLocation AttrNameLoc = ConsumeToken();
927
668k
      if (!getLangOpts().ObjC)
928
55.3k
        Diag(AttrNameLoc, diag::ext_nullability)
929
55.3k
          << AttrName;
930
668k
      attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
931
668k
                   ParsedAttr::AS_Keyword);
932
668k
      break;
933
639k
    }
934
668k
    default:
935
668k
      return;
936
1.33M
    }
937
1.33M
  }
938
668k
}
939
940
5.75M
static bool VersionNumberSeparator(const char Separator) {
941
5.75M
  return (Separator == '.' || 
Separator == '_'90.7k
);
942
5.75M
}
943
944
/// Parse a version number.
945
///
946
/// version:
947
///   simple-integer
948
///   simple-integer '.' simple-integer
949
///   simple-integer '_' simple-integer
950
///   simple-integer '.' simple-integer '.' simple-integer
951
///   simple-integer '_' simple-integer '_' simple-integer
952
5.74M
VersionTuple Parser::ParseVersionTuple(SourceRange &Range) {
953
5.74M
  Range = SourceRange(Tok.getLocation(), Tok.getEndLoc());
954
955
5.74M
  if (!Tok.is(tok::numeric_constant)) {
956
1
    Diag(Tok, diag::err_expected_version);
957
1
    SkipUntil(tok::comma, tok::r_paren,
958
1
              StopAtSemi | StopBeforeMatch | StopAtCodeCompletion);
959
1
    return VersionTuple();
960
1
  }
961
962
  // Parse the major (and possibly minor and subminor) versions, which
963
  // are stored in the numeric constant. We utilize a quirk of the
964
  // lexer, which is that it handles something like 1.2.3 as a single
965
  // numeric constant, rather than two separate tokens.
966
5.74M
  SmallString<512> Buffer;
967
5.74M
  Buffer.resize(Tok.getLength()+1);
968
5.74M
  const char *ThisTokBegin = &Buffer[0];
969
970
  // Get the spelling of the token, which eliminates trigraphs, etc.
971
5.74M
  bool Invalid = false;
972
5.74M
  unsigned ActualLength = PP.getSpelling(Tok, ThisTokBegin, &Invalid);
973
5.74M
  if (Invalid)
974
0
    return VersionTuple();
975
976
  // Parse the major version.
977
5.74M
  unsigned AfterMajor = 0;
978
5.74M
  unsigned Major = 0;
979
15.1M
  while (AfterMajor < ActualLength && 
isDigit(ThisTokBegin[AfterMajor])15.0M
) {
980
9.39M
    Major = Major * 10 + ThisTokBegin[AfterMajor] - '0';
981
9.39M
    ++AfterMajor;
982
9.39M
  }
983
984
5.74M
  if (AfterMajor == 0) {
985
0
    Diag(Tok, diag::err_expected_version);
986
0
    SkipUntil(tok::comma, tok::r_paren,
987
0
              StopAtSemi | StopBeforeMatch | StopAtCodeCompletion);
988
0
    return VersionTuple();
989
0
  }
990
991
5.74M
  if (AfterMajor == ActualLength) {
992
37.9k
    ConsumeToken();
993
994
    // We only had a single version component.
995
37.9k
    if (Major == 0) {
996
0
      Diag(Tok, diag::err_zero_version);
997
0
      return VersionTuple();
998
0
    }
999
1000
37.9k
    return VersionTuple(Major);
1001
37.9k
  }
1002
1003
5.70M
  const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
1004
5.70M
  if (!VersionNumberSeparator(AfterMajorSeparator)
1005
5.70M
      || (AfterMajor + 1 == ActualLength)) {
1006
0
    Diag(Tok, diag::err_expected_version);
1007
0
    SkipUntil(tok::comma, tok::r_paren,
1008
0
              StopAtSemi | StopBeforeMatch | StopAtCodeCompletion);
1009
0
    return VersionTuple();
1010
0
  }
1011
1012
  // Parse the minor version.
1013
5.70M
  unsigned AfterMinor = AfterMajor + 1;
1014
5.70M
  unsigned Minor = 0;
1015
11.9M
  while (AfterMinor < ActualLength && 
isDigit(ThisTokBegin[AfterMinor])6.26M
) {
1016
6.21M
    Minor = Minor * 10 + ThisTokBegin[AfterMinor] - '0';
1017
6.21M
    ++AfterMinor;
1018
6.21M
  }
1019
1020
5.70M
  if (AfterMinor == ActualLength) {
1021
5.65M
    ConsumeToken();
1022
1023
    // We had major.minor.
1024
5.65M
    if (Major == 0 && 
Minor == 00
) {
1025
0
      Diag(Tok, diag::err_zero_version);
1026
0
      return VersionTuple();
1027
0
    }
1028
1029
5.65M
    return VersionTuple(Major, Minor);
1030
5.65M
  }
1031
1032
52.1k
  const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
1033
  // If what follows is not a '.' or '_', we have a problem.
1034
52.1k
  if (!VersionNumberSeparator(AfterMinorSeparator)) {
1035
0
    Diag(Tok, diag::err_expected_version);
1036
0
    SkipUntil(tok::comma, tok::r_paren,
1037
0
              StopAtSemi | StopBeforeMatch | StopAtCodeCompletion);
1038
0
    return VersionTuple();
1039
0
  }
1040
1041
  // Warn if separators, be it '.' or '_', do not match.
1042
52.1k
  if (AfterMajorSeparator != AfterMinorSeparator)
1043
6
    Diag(Tok, diag::warn_expected_consistent_version_separator);
1044
1045
  // Parse the subminor version.
1046
52.1k
  unsigned AfterSubminor = AfterMinor + 1;
1047
52.1k
  unsigned Subminor = 0;
1048
104k
  while (AfterSubminor < ActualLength && 
isDigit(ThisTokBegin[AfterSubminor])52.1k
) {
1049
52.1k
    Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] - '0';
1050
52.1k
    ++AfterSubminor;
1051
52.1k
  }
1052
1053
52.1k
  if (AfterSubminor != ActualLength) {
1054
0
    Diag(Tok, diag::err_expected_version);
1055
0
    SkipUntil(tok::comma, tok::r_paren,
1056
0
              StopAtSemi | StopBeforeMatch | StopAtCodeCompletion);
1057
0
    return VersionTuple();
1058
0
  }
1059
52.1k
  ConsumeToken();
1060
52.1k
  return VersionTuple(Major, Minor, Subminor);
1061
52.1k
}
1062
1063
/// Parse the contents of the "availability" attribute.
1064
///
1065
/// availability-attribute:
1066
///   'availability' '(' platform ',' opt-strict version-arg-list,
1067
///                      opt-replacement, opt-message')'
1068
///
1069
/// platform:
1070
///   identifier
1071
///
1072
/// opt-strict:
1073
///   'strict' ','
1074
///
1075
/// version-arg-list:
1076
///   version-arg
1077
///   version-arg ',' version-arg-list
1078
///
1079
/// version-arg:
1080
///   'introduced' '=' version
1081
///   'deprecated' '=' version
1082
///   'obsoleted' = version
1083
///   'unavailable'
1084
/// opt-replacement:
1085
///   'replacement' '=' <string>
1086
/// opt-message:
1087
///   'message' '=' <string>
1088
void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability,
1089
                                        SourceLocation AvailabilityLoc,
1090
                                        ParsedAttributes &attrs,
1091
                                        SourceLocation *endLoc,
1092
                                        IdentifierInfo *ScopeName,
1093
                                        SourceLocation ScopeLoc,
1094
5.96M
                                        ParsedAttr::Syntax Syntax) {
1095
5.96M
  enum { Introduced, Deprecated, Obsoleted, Unknown };
1096
5.96M
  AvailabilityChange Changes[Unknown];
1097
5.96M
  ExprResult MessageExpr, ReplacementExpr;
1098
1099
  // Opening '('.
1100
5.96M
  BalancedDelimiterTracker T(*this, tok::l_paren);
1101
5.96M
  if (T.consumeOpen()) {
1102
0
    Diag(Tok, diag::err_expected) << tok::l_paren;
1103
0
    return;
1104
0
  }
1105
1106
  // Parse the platform name.
1107
5.96M
  if (Tok.isNot(tok::identifier)) {
1108
0
    Diag(Tok, diag::err_availability_expected_platform);
1109
0
    SkipUntil(tok::r_paren, StopAtSemi);
1110
0
    return;
1111
0
  }
1112
5.96M
  IdentifierLoc *Platform = ParseIdentifierLoc();
1113
5.96M
  if (const IdentifierInfo *const Ident = Platform->Ident) {
1114
    // Canonicalize platform name from "macosx" to "macos".
1115
5.96M
    if (Ident->getName() == "macosx")
1116
922k
      Platform->Ident = PP.getIdentifierInfo("macos");
1117
    // Canonicalize platform name from "macosx_app_extension" to
1118
    // "macos_app_extension".
1119
5.04M
    else if (Ident->getName() == "macosx_app_extension")
1120
4
      Platform->Ident = PP.getIdentifierInfo("macos_app_extension");
1121
5.04M
    else
1122
5.04M
      Platform->Ident = PP.getIdentifierInfo(
1123
5.04M
          AvailabilityAttr::canonicalizePlatformName(Ident->getName()));
1124
5.96M
  }
1125
1126
  // Parse the ',' following the platform name.
1127
5.96M
  if (ExpectAndConsume(tok::comma)) {
1128
0
    SkipUntil(tok::r_paren, StopAtSemi);
1129
0
    return;
1130
0
  }
1131
1132
  // If we haven't grabbed the pointers for the identifiers
1133
  // "introduced", "deprecated", and "obsoleted", do so now.
1134
5.96M
  if (!Ident_introduced) {
1135
1.95k
    Ident_introduced = PP.getIdentifierInfo("introduced");
1136
1.95k
    Ident_deprecated = PP.getIdentifierInfo("deprecated");
1137
1.95k
    Ident_obsoleted = PP.getIdentifierInfo("obsoleted");
1138
1.95k
    Ident_unavailable = PP.getIdentifierInfo("unavailable");
1139
1.95k
    Ident_message = PP.getIdentifierInfo("message");
1140
1.95k
    Ident_strict = PP.getIdentifierInfo("strict");
1141
1.95k
    Ident_replacement = PP.getIdentifierInfo("replacement");
1142
1.95k
  }
1143
1144
  // Parse the optional "strict", the optional "replacement" and the set of
1145
  // introductions/deprecations/removals.
1146
5.96M
  SourceLocation UnavailableLoc, StrictLoc;
1147
7.56M
  do {
1148
7.56M
    if (Tok.isNot(tok::identifier)) {
1149
0
      Diag(Tok, diag::err_availability_expected_change);
1150
0
      SkipUntil(tok::r_paren, StopAtSemi);
1151
0
      return;
1152
0
    }
1153
7.56M
    IdentifierInfo *Keyword = Tok.getIdentifierInfo();
1154
7.56M
    SourceLocation KeywordLoc = ConsumeToken();
1155
1156
7.56M
    if (Keyword == Ident_strict) {
1157
7
      if (StrictLoc.isValid()) {
1158
0
        Diag(KeywordLoc, diag::err_availability_redundant)
1159
0
          << Keyword << SourceRange(StrictLoc);
1160
0
      }
1161
7
      StrictLoc = KeywordLoc;
1162
7
      continue;
1163
7
    }
1164
1165
7.56M
    if (Keyword == Ident_unavailable) {
1166
1.20M
      if (UnavailableLoc.isValid()) {
1167
1
        Diag(KeywordLoc, diag::err_availability_redundant)
1168
1
          << Keyword << SourceRange(UnavailableLoc);
1169
1
      }
1170
1.20M
      UnavailableLoc = KeywordLoc;
1171
1.20M
      continue;
1172
1.20M
    }
1173
1174
6.35M
    if (Keyword == Ident_deprecated && 
Platform->Ident1.03M
&&
1175
6.35M
        
Platform->Ident->isStr("swift")1.03M
) {
1176
      // For swift, we deprecate for all versions.
1177
3
      if (Changes[Deprecated].KeywordLoc.isValid()) {
1178
0
        Diag(KeywordLoc, diag::err_availability_redundant)
1179
0
          << Keyword
1180
0
          << SourceRange(Changes[Deprecated].KeywordLoc);
1181
0
      }
1182
1183
3
      Changes[Deprecated].KeywordLoc = KeywordLoc;
1184
      // Use a fake version here.
1185
3
      Changes[Deprecated].Version = VersionTuple(1);
1186
3
      continue;
1187
3
    }
1188
1189
6.35M
    if (Tok.isNot(tok::equal)) {
1190
1
      Diag(Tok, diag::err_expected_after) << Keyword << tok::equal;
1191
1
      SkipUntil(tok::r_paren, StopAtSemi);
1192
1
      return;
1193
1
    }
1194
6.35M
    ConsumeToken();
1195
6.35M
    if (Keyword == Ident_message || 
Keyword == Ident_replacement5.82M
) {
1196
608k
      if (Tok.isNot(tok::string_literal)) {
1197
4
        Diag(Tok, diag::err_expected_string_literal)
1198
4
          << /*Source='availability attribute'*/2;
1199
4
        SkipUntil(tok::r_paren, StopAtSemi);
1200
4
        return;
1201
4
      }
1202
608k
      if (Keyword == Ident_message)
1203
525k
        MessageExpr = ParseStringLiteralExpression();
1204
82.6k
      else
1205
82.6k
        ReplacementExpr = ParseStringLiteralExpression();
1206
      // Also reject wide string literals.
1207
608k
      if (StringLiteral *MessageStringLiteral =
1208
608k
              cast_or_null<StringLiteral>(MessageExpr.get())) {
1209
525k
        if (!MessageStringLiteral->isOrdinary()) {
1210
3
          Diag(MessageStringLiteral->getSourceRange().getBegin(),
1211
3
               diag::err_expected_string_literal)
1212
3
            << /*Source='availability attribute'*/ 2;
1213
3
          SkipUntil(tok::r_paren, StopAtSemi);
1214
3
          return;
1215
3
        }
1216
525k
      }
1217
608k
      if (Keyword == Ident_message)
1218
525k
        break;
1219
82.6k
      else
1220
82.6k
        continue;
1221
608k
    }
1222
1223
    // Special handling of 'NA' only when applied to introduced or
1224
    // deprecated.
1225
5.74M
    if ((Keyword == Ident_introduced || 
Keyword == Ident_deprecated1.03M
) &&
1226
5.74M
        
Tok.is(tok::identifier)5.74M
) {
1227
6.23k
      IdentifierInfo *NA = Tok.getIdentifierInfo();
1228
6.23k
      if (NA->getName() == "NA") {
1229
6.23k
        ConsumeToken();
1230
6.23k
        if (Keyword == Ident_introduced)
1231
6.22k
          UnavailableLoc = KeywordLoc;
1232
6.23k
        continue;
1233
6.23k
      }
1234
6.23k
    }
1235
1236
5.74M
    SourceRange VersionRange;
1237
5.74M
    VersionTuple Version = ParseVersionTuple(VersionRange);
1238
1239
5.74M
    if (Version.empty()) {
1240
0
      SkipUntil(tok::r_paren, StopAtSemi);
1241
0
      return;
1242
0
    }
1243
1244
5.74M
    unsigned Index;
1245
5.74M
    if (Keyword == Ident_introduced)
1246
4.70M
      Index = Introduced;
1247
1.03M
    else if (Keyword == Ident_deprecated)
1248
1.03M
      Index = Deprecated;
1249
60
    else if (Keyword == Ident_obsoleted)
1250
59
      Index = Obsoleted;
1251
1
    else
1252
1
      Index = Unknown;
1253
1254
5.74M
    if (Index < Unknown) {
1255
5.74M
      if (!Changes[Index].KeywordLoc.isInvalid()) {
1256
1
        Diag(KeywordLoc, diag::err_availability_redundant)
1257
1
          << Keyword
1258
1
          << SourceRange(Changes[Index].KeywordLoc,
1259
1
                         Changes[Index].VersionRange.getEnd());
1260
1
      }
1261
1262
5.74M
      Changes[Index].KeywordLoc = KeywordLoc;
1263
5.74M
      Changes[Index].Version = Version;
1264
5.74M
      Changes[Index].VersionRange = VersionRange;
1265
5.74M
    } else {
1266
1
      Diag(KeywordLoc, diag::err_availability_unknown_change)
1267
1
        << Keyword << VersionRange;
1268
1
    }
1269
1270
7.03M
  } while (TryConsumeToken(tok::comma));
1271
1272
  // Closing ')'.
1273
5.96M
  if (T.consumeClose())
1274
1
    return;
1275
1276
5.96M
  if (endLoc)
1277
5.96M
    *endLoc = T.getCloseLocation();
1278
1279
  // The 'unavailable' availability cannot be combined with any other
1280
  // availability changes. Make sure that hasn't happened.
1281
5.96M
  if (UnavailableLoc.isValid()) {
1282
1.21M
    bool Complained = false;
1283
4.84M
    for (unsigned Index = Introduced; Index != Unknown; 
++Index3.63M
) {
1284
3.63M
      if (Changes[Index].KeywordLoc.isValid()) {
1285
1
        if (!Complained) {
1286
1
          Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1287
1
            << SourceRange(Changes[Index].KeywordLoc,
1288
1
                           Changes[Index].VersionRange.getEnd());
1289
1
          Complained = true;
1290
1
        }
1291
1292
        // Clear out the availability.
1293
1
        Changes[Index] = AvailabilityChange();
1294
1
      }
1295
3.63M
    }
1296
1.21M
  }
1297
1298
  // Record this attribute
1299
5.96M
  attrs.addNew(&Availability,
1300
5.96M
               SourceRange(AvailabilityLoc, T.getCloseLocation()),
1301
5.96M
               ScopeName, ScopeLoc,
1302
5.96M
               Platform,
1303
5.96M
               Changes[Introduced],
1304
5.96M
               Changes[Deprecated],
1305
5.96M
               Changes[Obsoleted],
1306
5.96M
               UnavailableLoc, MessageExpr.get(),
1307
5.96M
               Syntax, StrictLoc, ReplacementExpr.get());
1308
5.96M
}
1309
1310
/// Parse the contents of the "external_source_symbol" attribute.
1311
///
1312
/// external-source-symbol-attribute:
1313
///   'external_source_symbol' '(' keyword-arg-list ')'
1314
///
1315
/// keyword-arg-list:
1316
///   keyword-arg
1317
///   keyword-arg ',' keyword-arg-list
1318
///
1319
/// keyword-arg:
1320
///   'language' '=' <string>
1321
///   'defined_in' '=' <string>
1322
///   'generated_declaration'
1323
void Parser::ParseExternalSourceSymbolAttribute(
1324
    IdentifierInfo &ExternalSourceSymbol, SourceLocation Loc,
1325
    ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName,
1326
80
    SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) {
1327
  // Opening '('.
1328
80
  BalancedDelimiterTracker T(*this, tok::l_paren);
1329
80
  if (T.expectAndConsume())
1330
0
    return;
1331
1332
  // Initialize the pointers for the keyword identifiers when required.
1333
80
  if (!Ident_language) {
1334
24
    Ident_language = PP.getIdentifierInfo("language");
1335
24
    Ident_defined_in = PP.getIdentifierInfo("defined_in");
1336
24
    Ident_generated_declaration = PP.getIdentifierInfo("generated_declaration");
1337
24
  }
1338
1339
80
  ExprResult Language;
1340
80
  bool HasLanguage = false;
1341
80
  ExprResult DefinedInExpr;
1342
80
  bool HasDefinedIn = false;
1343
80
  IdentifierLoc *GeneratedDeclaration = nullptr;
1344
1345
  // Parse the language/defined_in/generated_declaration keywords
1346
177
  do {
1347
177
    if (Tok.isNot(tok::identifier)) {
1348
5
      Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1349
5
      SkipUntil(tok::r_paren, StopAtSemi);
1350
5
      return;
1351
5
    }
1352
1353
172
    SourceLocation KeywordLoc = Tok.getLocation();
1354
172
    IdentifierInfo *Keyword = Tok.getIdentifierInfo();
1355
172
    if (Keyword == Ident_generated_declaration) {
1356
41
      if (GeneratedDeclaration) {
1357
4
        Diag(Tok, diag::err_external_source_symbol_duplicate_clause) << Keyword;
1358
4
        SkipUntil(tok::r_paren, StopAtSemi);
1359
4
        return;
1360
4
      }
1361
37
      GeneratedDeclaration = ParseIdentifierLoc();
1362
37
      continue;
1363
41
    }
1364
1365
131
    if (Keyword != Ident_language && 
Keyword != Ident_defined_in64
) {
1366
2
      Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1367
2
      SkipUntil(tok::r_paren, StopAtSemi);
1368
2
      return;
1369
2
    }
1370
1371
129
    ConsumeToken();
1372
129
    if (ExpectAndConsume(tok::equal, diag::err_expected_after,
1373
129
                         Keyword->getName())) {
1374
1
      SkipUntil(tok::r_paren, StopAtSemi);
1375
1
      return;
1376
1
    }
1377
1378
128
    bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn;
1379
128
    if (Keyword == Ident_language)
1380
66
      HasLanguage = true;
1381
62
    else
1382
62
      HasDefinedIn = true;
1383
1384
128
    if (Tok.isNot(tok::string_literal)) {
1385
9
      Diag(Tok, diag::err_expected_string_literal)
1386
9
          << /*Source='external_source_symbol attribute'*/ 3
1387
9
          << /*language | source container*/ (Keyword != Ident_language);
1388
9
      SkipUntil(tok::comma, tok::r_paren, StopAtSemi | StopBeforeMatch);
1389
9
      continue;
1390
9
    }
1391
119
    if (Keyword == Ident_language) {
1392
61
      if (HadLanguage) {
1393
2
        Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1394
2
            << Keyword;
1395
2
        ParseStringLiteralExpression();
1396
2
        continue;
1397
2
      }
1398
59
      Language = ParseStringLiteralExpression();
1399
59
    } else {
1400
58
      assert(Keyword == Ident_defined_in && "Invalid clause keyword!");
1401
58
      if (HadDefinedIn) {
1402
2
        Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1403
2
            << Keyword;
1404
2
        ParseStringLiteralExpression();
1405
2
        continue;
1406
2
      }
1407
56
      DefinedInExpr = ParseStringLiteralExpression();
1408
56
    }
1409
165
  } while (TryConsumeToken(tok::comma));
1410
1411
  // Closing ')'.
1412
68
  if (T.consumeClose())
1413
3
    return;
1414
65
  if (EndLoc)
1415
63
    *EndLoc = T.getCloseLocation();
1416
1417
65
  ArgsUnion Args[] = {Language.get(), DefinedInExpr.get(),
1418
65
                      GeneratedDeclaration};
1419
65
  Attrs.addNew(&ExternalSourceSymbol, SourceRange(Loc, T.getCloseLocation()),
1420
65
               ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax);
1421
65
}
1422
1423
/// Parse the contents of the "objc_bridge_related" attribute.
1424
/// objc_bridge_related '(' related_class ',' opt-class_method ',' opt-instance_method ')'
1425
/// related_class:
1426
///     Identifier
1427
///
1428
/// opt-class_method:
1429
///     Identifier: | <empty>
1430
///
1431
/// opt-instance_method:
1432
///     Identifier | <empty>
1433
///
1434
void Parser::ParseObjCBridgeRelatedAttribute(
1435
    IdentifierInfo &ObjCBridgeRelated, SourceLocation ObjCBridgeRelatedLoc,
1436
    ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName,
1437
480
    SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) {
1438
  // Opening '('.
1439
480
  BalancedDelimiterTracker T(*this, tok::l_paren);
1440
480
  if (T.consumeOpen()) {
1441
0
    Diag(Tok, diag::err_expected) << tok::l_paren;
1442
0
    return;
1443
0
  }
1444
1445
  // Parse the related class name.
1446
480
  if (Tok.isNot(tok::identifier)) {
1447
4
    Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1448
4
    SkipUntil(tok::r_paren, StopAtSemi);
1449
4
    return;
1450
4
  }
1451
476
  IdentifierLoc *RelatedClass = ParseIdentifierLoc();
1452
476
  if (ExpectAndConsume(tok::comma)) {
1453
0
    SkipUntil(tok::r_paren, StopAtSemi);
1454
0
    return;
1455
0
  }
1456
1457
  // Parse class method name.  It's non-optional in the sense that a trailing
1458
  // comma is required, but it can be the empty string, and then we record a
1459
  // nullptr.
1460
476
  IdentifierLoc *ClassMethod = nullptr;
1461
476
  if (Tok.is(tok::identifier)) {
1462
21
    ClassMethod = ParseIdentifierLoc();
1463
21
    if (!TryConsumeToken(tok::colon)) {
1464
2
      Diag(Tok, diag::err_objcbridge_related_selector_name);
1465
2
      SkipUntil(tok::r_paren, StopAtSemi);
1466
2
      return;
1467
2
    }
1468
21
  }
1469
474
  if (!TryConsumeToken(tok::comma)) {
1470
2
    if (Tok.is(tok::colon))
1471
1
      Diag(Tok, diag::err_objcbridge_related_selector_name);
1472
1
    else
1473
1
      Diag(Tok, diag::err_expected) << tok::comma;
1474
2
    SkipUntil(tok::r_paren, StopAtSemi);
1475
2
    return;
1476
2
  }
1477
1478
  // Parse instance method name.  Also non-optional but empty string is
1479
  // permitted.
1480
472
  IdentifierLoc *InstanceMethod = nullptr;
1481
472
  if (Tok.is(tok::identifier))
1482
19
    InstanceMethod = ParseIdentifierLoc();
1483
453
  else if (Tok.isNot(tok::r_paren)) {
1484
1
    Diag(Tok, diag::err_expected) << tok::r_paren;
1485
1
    SkipUntil(tok::r_paren, StopAtSemi);
1486
1
    return;
1487
1
  }
1488
1489
  // Closing ')'.
1490
471
  if (T.consumeClose())
1491
0
    return;
1492
1493
471
  if (EndLoc)
1494
471
    *EndLoc = T.getCloseLocation();
1495
1496
  // Record this attribute
1497
471
  Attrs.addNew(&ObjCBridgeRelated,
1498
471
               SourceRange(ObjCBridgeRelatedLoc, T.getCloseLocation()),
1499
471
               ScopeName, ScopeLoc, RelatedClass, ClassMethod, InstanceMethod,
1500
471
               Syntax);
1501
471
}
1502
1503
void Parser::ParseSwiftNewTypeAttribute(
1504
    IdentifierInfo &AttrName, SourceLocation AttrNameLoc,
1505
    ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName,
1506
11.0k
    SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) {
1507
11.0k
  BalancedDelimiterTracker T(*this, tok::l_paren);
1508
1509
  // Opening '('
1510
11.0k
  if (T.consumeOpen()) {
1511
0
    Diag(Tok, diag::err_expected) << tok::l_paren;
1512
0
    return;
1513
0
  }
1514
1515
11.0k
  if (Tok.is(tok::r_paren)) {
1516
1
    Diag(Tok.getLocation(), diag::err_argument_required_after_attribute);
1517
1
    T.consumeClose();
1518
1
    return;
1519
1
  }
1520
11.0k
  if (Tok.isNot(tok::kw_struct) && 
Tok.isNot(tok::kw_enum)5.37k
) {
1521
2
    Diag(Tok, diag::warn_attribute_type_not_supported)
1522
2
        << &AttrName << Tok.getIdentifierInfo();
1523
2
    if (!isTokenSpecial())
1524
2
      ConsumeToken();
1525
2
    T.consumeClose();
1526
2
    return;
1527
2
  }
1528
1529
11.0k
  auto *SwiftType = IdentifierLoc::create(Actions.Context, Tok.getLocation(),
1530
11.0k
                                          Tok.getIdentifierInfo());
1531
11.0k
  ConsumeToken();
1532
1533
  // Closing ')'
1534
11.0k
  if (T.consumeClose())
1535
0
    return;
1536
11.0k
  if (EndLoc)
1537
11.0k
    *EndLoc = T.getCloseLocation();
1538
1539
11.0k
  ArgsUnion Args[] = {SwiftType};
1540
11.0k
  Attrs.addNew(&AttrName, SourceRange(AttrNameLoc, T.getCloseLocation()),
1541
11.0k
               ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax);
1542
11.0k
}
1543
1544
void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
1545
                                              SourceLocation AttrNameLoc,
1546
                                              ParsedAttributes &Attrs,
1547
                                              SourceLocation *EndLoc,
1548
                                              IdentifierInfo *ScopeName,
1549
                                              SourceLocation ScopeLoc,
1550
189
                                              ParsedAttr::Syntax Syntax) {
1551
189
  assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('");
1552
1553
0
  BalancedDelimiterTracker T(*this, tok::l_paren);
1554
189
  T.consumeOpen();
1555
1556
189
  if (Tok.isNot(tok::identifier)) {
1557
0
    Diag(Tok, diag::err_expected) << tok::identifier;
1558
0
    T.skipToEnd();
1559
0
    return;
1560
0
  }
1561
189
  IdentifierLoc *ArgumentKind = ParseIdentifierLoc();
1562
1563
189
  if (ExpectAndConsume(tok::comma)) {
1564
0
    T.skipToEnd();
1565
0
    return;
1566
0
  }
1567
1568
189
  SourceRange MatchingCTypeRange;
1569
189
  TypeResult MatchingCType = ParseTypeName(&MatchingCTypeRange);
1570
189
  if (MatchingCType.isInvalid()) {
1571
8
    T.skipToEnd();
1572
8
    return;
1573
8
  }
1574
1575
181
  bool LayoutCompatible = false;
1576
181
  bool MustBeNull = false;
1577
234
  while (TryConsumeToken(tok::comma)) {
1578
65
    if (Tok.isNot(tok::identifier)) {
1579
4
      Diag(Tok, diag::err_expected) << tok::identifier;
1580
4
      T.skipToEnd();
1581
4
      return;
1582
4
    }
1583
61
    IdentifierInfo *Flag = Tok.getIdentifierInfo();
1584
61
    if (Flag->isStr("layout_compatible"))
1585
46
      LayoutCompatible = true;
1586
15
    else if (Flag->isStr("must_be_null"))
1587
7
      MustBeNull = true;
1588
8
    else {
1589
8
      Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1590
8
      T.skipToEnd();
1591
8
      return;
1592
8
    }
1593
53
    ConsumeToken(); // consume flag
1594
53
  }
1595
1596
169
  if (!T.consumeClose()) {
1597
169
    Attrs.addNewTypeTagForDatatype(&AttrName, AttrNameLoc, ScopeName, ScopeLoc,
1598
169
                                   ArgumentKind, MatchingCType.get(),
1599
169
                                   LayoutCompatible, MustBeNull, Syntax);
1600
169
  }
1601
1602
169
  if (EndLoc)
1603
169
    *EndLoc = T.getCloseLocation();
1604
169
}
1605
1606
/// DiagnoseProhibitedCXX11Attribute - We have found the opening square brackets
1607
/// of a C++11 attribute-specifier in a location where an attribute is not
1608
/// permitted. By C++11 [dcl.attr.grammar]p6, this is ill-formed. Diagnose this
1609
/// situation.
1610
///
1611
/// \return \c true if we skipped an attribute-like chunk of tokens, \c false if
1612
/// this doesn't appear to actually be an attribute-specifier, and the caller
1613
/// should try to parse it.
1614
12
bool Parser::DiagnoseProhibitedCXX11Attribute() {
1615
12
  assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square));
1616
1617
0
  switch (isCXX11AttributeSpecifier(/*Disambiguate*/true)) {
1618
4
  case CAK_NotAttributeSpecifier:
1619
    // No diagnostic: we're in Obj-C++11 and this is not actually an attribute.
1620
4
    return false;
1621
1622
4
  case CAK_InvalidAttributeSpecifier:
1623
4
    Diag(Tok.getLocation(), diag::err_l_square_l_square_not_attribute);
1624
4
    return false;
1625
1626
4
  case CAK_AttributeSpecifier:
1627
    // Parse and discard the attributes.
1628
4
    SourceLocation BeginLoc = ConsumeBracket();
1629
4
    ConsumeBracket();
1630
4
    SkipUntil(tok::r_square);
1631
4
    assert(Tok.is(tok::r_square) && "isCXX11AttributeSpecifier lied");
1632
0
    SourceLocation EndLoc = ConsumeBracket();
1633
4
    Diag(BeginLoc, diag::err_attributes_not_allowed)
1634
4
      << SourceRange(BeginLoc, EndLoc);
1635
4
    return true;
1636
12
  }
1637
0
  llvm_unreachable("All cases handled above.");
1638
0
}
1639
1640
/// We have found the opening square brackets of a C++11
1641
/// attribute-specifier in a location where an attribute is not permitted, but
1642
/// we know where the attributes ought to be written. Parse them anyway, and
1643
/// provide a fixit moving them to the right place.
1644
void Parser::DiagnoseMisplacedCXX11Attribute(ParsedAttributes &Attrs,
1645
24
                                             SourceLocation CorrectLocation) {
1646
24
  assert((Tok.is(tok::l_square) && NextToken().is(tok::l_square)) ||
1647
24
         Tok.is(tok::kw_alignas));
1648
1649
  // Consume the attributes.
1650
0
  SourceLocation Loc = Tok.getLocation();
1651
24
  ParseCXX11Attributes(Attrs);
1652
24
  CharSourceRange AttrRange(SourceRange(Loc, Attrs.Range.getEnd()), true);
1653
  // FIXME: use err_attributes_misplaced
1654
24
  Diag(Loc, diag::err_attributes_not_allowed)
1655
24
    << FixItHint::CreateInsertionFromRange(CorrectLocation, AttrRange)
1656
24
    << FixItHint::CreateRemoval(AttrRange);
1657
24
}
1658
1659
void Parser::DiagnoseProhibitedAttributes(
1660
118
    const SourceRange &Range, const SourceLocation CorrectLocation) {
1661
118
  if (CorrectLocation.isValid()) {
1662
13
    CharSourceRange AttrRange(Range, true);
1663
13
    Diag(CorrectLocation, diag::err_attributes_misplaced)
1664
13
        << FixItHint::CreateInsertionFromRange(CorrectLocation, AttrRange)
1665
13
        << FixItHint::CreateRemoval(AttrRange);
1666
13
  } else
1667
105
    Diag(Range.getBegin(), diag::err_attributes_not_allowed) << Range;
1668
118
}
1669
1670
void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
1671
                                     bool DiagnoseEmptyAttrs,
1672
1.00M
                                     bool WarnOnUnknownAttrs) {
1673
1674
1.00M
  if (DiagnoseEmptyAttrs && 
Attrs.empty()1.00M
&&
Attrs.Range.isValid()955k
) {
1675
    // An attribute list has been parsed, but it was empty.
1676
    // This is the case for [[]].
1677
25
    const auto &LangOpts = getLangOpts();
1678
25
    auto &SM = PP.getSourceManager();
1679
25
    Token FirstLSquare;
1680
25
    Lexer::getRawToken(Attrs.Range.getBegin(), FirstLSquare, SM, LangOpts);
1681
1682
25
    if (FirstLSquare.is(tok::l_square)) {
1683
12
      llvm::Optional<Token> SecondLSquare =
1684
12
          Lexer::findNextToken(FirstLSquare.getLocation(), SM, LangOpts);
1685
1686
12
      if (SecondLSquare && SecondLSquare->is(tok::l_square)) {
1687
        // The attribute range starts with [[, but is empty. So this must
1688
        // be [[]], which we are supposed to diagnose because
1689
        // DiagnoseEmptyAttrs is true.
1690
12
        Diag(Attrs.Range.getBegin(), DiagID) << Attrs.Range;
1691
12
        return;
1692
12
      }
1693
12
    }
1694
25
  }
1695
1696
1.00M
  for (const ParsedAttr &AL : Attrs) {
1697
49.8k
    if (!AL.isCXX11Attribute() && 
!AL.isC2xAttribute()49.8k
)
1698
49.8k
      continue;
1699
13
    if (AL.getKind() == ParsedAttr::UnknownAttribute) {
1700
7
      if (WarnOnUnknownAttrs)
1701
7
        Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
1702
7
            << AL << AL.getRange();
1703
7
    } else {
1704
6
      Diag(AL.getLoc(), DiagID) << AL;
1705
6
      AL.setInvalid();
1706
6
    }
1707
13
  }
1708
1.00M
}
1709
1710
454k
void Parser::DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs) {
1711
454k
  for (const ParsedAttr &PA : Attrs) {
1712
207k
    if (PA.isCXX11Attribute() || 
PA.isC2xAttribute()207k
)
1713
20
      Diag(PA.getLoc(), diag::ext_cxx11_attr_placement) << PA << PA.getRange();
1714
207k
  }
1715
454k
}
1716
1717
// Usually, `__attribute__((attrib)) class Foo {} var` means that attribute
1718
// applies to var, not the type Foo.
1719
// As an exception to the rule, __declspec(align(...)) before the
1720
// class-key affects the type instead of the variable.
1721
// Also, Microsoft-style [attributes] seem to affect the type instead of the
1722
// variable.
1723
// This function moves attributes that should apply to the type off DS to Attrs.
1724
void Parser::stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs,
1725
                                            DeclSpec &DS,
1726
2.53M
                                            Sema::TagUseKind TUK) {
1727
2.53M
  if (TUK == Sema::TUK_Reference)
1728
1.03M
    return;
1729
1730
1.50M
  llvm::SmallVector<ParsedAttr *, 1> ToBeMoved;
1731
1732
1.50M
  for (ParsedAttr &AL : DS.getAttributes()) {
1733
259
    if ((AL.getKind() == ParsedAttr::AT_Aligned &&
1734
259
         
AL.isDeclspecAttribute()41
) ||
1735
259
        
AL.isMicrosoftAttribute()251
)
1736
63
      ToBeMoved.push_back(&AL);
1737
259
  }
1738
1739
1.50M
  for (ParsedAttr *AL : ToBeMoved) {
1740
63
    DS.getAttributes().remove(AL);
1741
63
    Attrs.addAtEnd(AL);
1742
63
  }
1743
1.50M
}
1744
1745
/// ParseDeclaration - Parse a full 'declaration', which consists of
1746
/// declaration-specifiers, some number of declarators, and a semicolon.
1747
/// 'Context' should be a DeclaratorContext value.  This returns the
1748
/// location of the semicolon in DeclEnd.
1749
///
1750
///       declaration: [C99 6.7]
1751
///         block-declaration ->
1752
///           simple-declaration
1753
///           others                   [FIXME]
1754
/// [C++]   template-declaration
1755
/// [C++]   namespace-definition
1756
/// [C++]   using-directive
1757
/// [C++]   using-declaration
1758
/// [C++11/C11] static_assert-declaration
1759
///         others... [FIXME]
1760
///
1761
Parser::DeclGroupPtrTy Parser::ParseDeclaration(DeclaratorContext Context,
1762
                                                SourceLocation &DeclEnd,
1763
                                                ParsedAttributes &DeclAttrs,
1764
                                                ParsedAttributes &DeclSpecAttrs,
1765
5.05M
                                                SourceLocation *DeclSpecStart) {
1766
5.05M
  ParenBraceBracketBalancer BalancerRAIIObj(*this);
1767
  // Must temporarily exit the objective-c container scope for
1768
  // parsing c none objective-c decls.
1769
5.05M
  ObjCDeclContextSwitch ObjCDC(*this);
1770
1771
5.05M
  Decl *SingleDecl = nullptr;
1772
5.05M
  switch (Tok.getKind()) {
1773
1.28M
  case tok::kw_template:
1774
1.28M
  case tok::kw_export:
1775
1.28M
    ProhibitAttributes(DeclAttrs);
1776
1.28M
    ProhibitAttributes(DeclSpecAttrs);
1777
1.28M
    SingleDecl =
1778
1.28M
        ParseDeclarationStartingWithTemplate(Context, DeclEnd, DeclAttrs);
1779
1.28M
    break;
1780
191k
  case tok::kw_inline:
1781
    // Could be the start of an inline namespace. Allowed as an ext in C++03.
1782
191k
    if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_namespace)) {
1783
191k
      ProhibitAttributes(DeclAttrs);
1784
191k
      ProhibitAttributes(DeclSpecAttrs);
1785
191k
      SourceLocation InlineLoc = ConsumeToken();
1786
191k
      return ParseNamespace(Context, DeclEnd, InlineLoc);
1787
191k
    }
1788
6
    return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
1789
6
                                  true, nullptr, DeclSpecStart);
1790
238k
  case tok::kw_namespace:
1791
238k
    ProhibitAttributes(DeclAttrs);
1792
238k
    ProhibitAttributes(DeclSpecAttrs);
1793
238k
    return ParseNamespace(Context, DeclEnd);
1794
249k
  case tok::kw_using: {
1795
249k
    ParsedAttributes Attrs(AttrFactory);
1796
249k
    takeAndConcatenateAttrs(DeclAttrs, DeclSpecAttrs, Attrs);
1797
249k
    return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
1798
249k
                                            DeclEnd, Attrs);
1799
191k
  }
1800
40.4k
  case tok::kw_static_assert:
1801
45.1k
  case tok::kw__Static_assert:
1802
45.1k
    ProhibitAttributes(DeclAttrs);
1803
45.1k
    ProhibitAttributes(DeclSpecAttrs);
1804
45.1k
    SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
1805
45.1k
    break;
1806
3.04M
  default:
1807
3.04M
    return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
1808
3.04M
                                  true, nullptr, DeclSpecStart);
1809
5.05M
  }
1810
1811
  // This routine returns a DeclGroup, if the thing we parsed only contains a
1812
  // single decl, convert it now.
1813
1.33M
  return Actions.ConvertDeclToDeclGroup(SingleDecl);
1814
5.05M
}
1815
1816
///       simple-declaration: [C99 6.7: declaration] [C++ 7p1: dcl.dcl]
1817
///         declaration-specifiers init-declarator-list[opt] ';'
1818
/// [C++11] attribute-specifier-seq decl-specifier-seq[opt]
1819
///             init-declarator-list ';'
1820
///[C90/C++]init-declarator-list ';'                             [TODO]
1821
/// [OMP]   threadprivate-directive
1822
/// [OMP]   allocate-directive                                   [TODO]
1823
///
1824
///       for-range-declaration: [C++11 6.5p1: stmt.ranged]
1825
///         attribute-specifier-seq[opt] type-specifier-seq declarator
1826
///
1827
/// If RequireSemi is false, this does not check for a ';' at the end of the
1828
/// declaration.  If it is true, it checks for and eats it.
1829
///
1830
/// If FRI is non-null, we might be parsing a for-range-declaration instead
1831
/// of a simple-declaration. If we find that we are, we also parse the
1832
/// for-range-initializer, and place it here.
1833
///
1834
/// DeclSpecStart is used when decl-specifiers are parsed before parsing
1835
/// the Declaration. The SourceLocation for this Decl is set to
1836
/// DeclSpecStart if DeclSpecStart is non-null.
1837
Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(
1838
    DeclaratorContext Context, SourceLocation &DeclEnd,
1839
    ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs,
1840
3.17M
    bool RequireSemi, ForRangeInit *FRI, SourceLocation *DeclSpecStart) {
1841
  // Need to retain these for diagnostics before we add them to the DeclSepc.
1842
3.17M
  ParsedAttributesView OriginalDeclSpecAttrs;
1843
3.17M
  OriginalDeclSpecAttrs.addAll(DeclSpecAttrs.begin(), DeclSpecAttrs.end());
1844
3.17M
  OriginalDeclSpecAttrs.Range = DeclSpecAttrs.Range;
1845
1846
  // Parse the common declaration-specifiers piece.
1847
3.17M
  ParsingDeclSpec DS(*this);
1848
3.17M
  DS.takeAttributesFrom(DeclSpecAttrs);
1849
1850
3.17M
  DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
1851
3.17M
  ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS_none, DSContext);
1852
1853
  // If we had a free-standing type definition with a missing semicolon, we
1854
  // may get this far before the problem becomes obvious.
1855
3.17M
  if (DS.hasTagDefinition() &&
1856
3.17M
      
DiagnoseMissingSemiAfterTagDefinition(DS, AS_none, DSContext)297k
)
1857
0
    return nullptr;
1858
1859
  // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
1860
  // declaration-specifiers init-declarator-list[opt] ';'
1861
3.17M
  if (Tok.is(tok::semi)) {
1862
34.4k
    ProhibitAttributes(DeclAttrs);
1863
34.4k
    DeclEnd = Tok.getLocation();
1864
34.4k
    if (RequireSemi) 
ConsumeToken()34.4k
;
1865
34.4k
    RecordDecl *AnonRecord = nullptr;
1866
34.4k
    Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
1867
34.4k
        getCurScope(), AS_none, DS, ParsedAttributesView::none(), AnonRecord);
1868
34.4k
    DS.complete(TheDecl);
1869
34.4k
    if (AnonRecord) {
1870
37
      Decl* decls[] = {AnonRecord, TheDecl};
1871
37
      return Actions.BuildDeclaratorGroup(decls);
1872
37
    }
1873
34.4k
    return Actions.ConvertDeclToDeclGroup(TheDecl);
1874
34.4k
  }
1875
1876
3.14M
  if (DeclSpecStart)
1877
2.43k
    DS.SetRangeStart(*DeclSpecStart);
1878
1879
3.14M
  return ParseDeclGroup(DS, Context, DeclAttrs, &DeclEnd, FRI);
1880
3.17M
}
1881
1882
/// Returns true if this might be the start of a declarator, or a common typo
1883
/// for a declarator.
1884
136k
bool Parser::MightBeDeclarator(DeclaratorContext Context) {
1885
136k
  switch (Tok.getKind()) {
1886
0
  case tok::annot_cxxscope:
1887
0
  case tok::annot_template_id:
1888
0
  case tok::caret:
1889
0
  case tok::code_completion:
1890
0
  case tok::coloncolon:
1891
0
  case tok::ellipsis:
1892
3
  case tok::kw___attribute:
1893
6
  case tok::kw_operator:
1894
11
  case tok::l_paren:
1895
18
  case tok::star:
1896
18
    return true;
1897
1898
18
  case tok::amp:
1899
21
  case tok::ampamp:
1900
21
    return getLangOpts().CPlusPlus;
1901
1902
0
  case tok::l_square: // Might be an attribute on an unnamed bit-field.
1903
0
    return Context == DeclaratorContext::Member && getLangOpts().CPlusPlus11 &&
1904
0
           NextToken().is(tok::l_square);
1905
1906
2.04k
  case tok::colon: // Might be a typo for '::' or an unnamed bit-field.
1907
2.04k
    return Context == DeclaratorContext::Member || 
getLangOpts().CPlusPlus0
;
1908
1909
134k
  case tok::identifier:
1910
134k
    switch (NextToken().getKind()) {
1911
0
    case tok::code_completion:
1912
20
    case tok::coloncolon:
1913
15.1k
    case tok::comma:
1914
15.8k
    case tok::equal:
1915
15.8k
    case tok::equalequal: // Might be a typo for '='.
1916
15.8k
    case tok::kw_alignas:
1917
15.8k
    case tok::kw_asm:
1918
113k
    case tok::kw___attribute:
1919
113k
    case tok::l_brace:
1920
113k
    case tok::l_paren:
1921
113k
    case tok::l_square:
1922
113k
    case tok::less:
1923
113k
    case tok::r_brace:
1924
113k
    case tok::r_paren:
1925
113k
    case tok::r_square:
1926
114k
    case tok::semi:
1927
114k
      return true;
1928
1929
19.6k
    case tok::colon:
1930
      // At namespace scope, 'identifier:' is probably a typo for 'identifier::'
1931
      // and in block scope it's probably a label. Inside a class definition,
1932
      // this is a bit-field.
1933
19.6k
      return Context == DeclaratorContext::Member ||
1934
19.6k
             
(3
getLangOpts().CPlusPlus3
&&
Context == DeclaratorContext::File3
);
1935
1936
18
    case tok::identifier: // Possible virt-specifier.
1937
18
      return getLangOpts().CPlusPlus11 && 
isCXX11VirtSpecifier(NextToken())14
;
1938
1939
10
    default:
1940
10
      return false;
1941
134k
    }
1942
1943
56
  default:
1944
56
    return false;
1945
136k
  }
1946
136k
}
1947
1948
/// Skip until we reach something which seems like a sensible place to pick
1949
/// up parsing after a malformed declaration. This will sometimes stop sooner
1950
/// than SkipUntil(tok::r_brace) would, but will never stop later.
1951
545
void Parser::SkipMalformedDecl() {
1952
1.28k
  while (true) {
1953
1.28k
    switch (Tok.getKind()) {
1954
89
    case tok::l_brace:
1955
      // Skip until matching }, then stop. We've probably skipped over
1956
      // a malformed class or function definition or similar.
1957
89
      ConsumeBrace();
1958
89
      SkipUntil(tok::r_brace);
1959
89
      if (Tok.isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
1960
        // This declaration isn't over yet. Keep skipping.
1961
4
        continue;
1962
4
      }
1963
85
      TryConsumeToken(tok::semi);
1964
85
      return;
1965
1966
0
    case tok::l_square:
1967
0
      ConsumeBracket();
1968
0
      SkipUntil(tok::r_square);
1969
0
      continue;
1970
1971
48
    case tok::l_paren:
1972
48
      ConsumeParen();
1973
48
      SkipUntil(tok::r_paren);
1974
48
      continue;
1975
1976
10
    case tok::r_brace:
1977
10
      return;
1978
1979
294
    case tok::semi:
1980
294
      ConsumeToken();
1981
294
      return;
1982
1983
2
    case tok::kw_inline:
1984
      // 'inline namespace' at the start of a line is almost certainly
1985
      // a good place to pick back up parsing, except in an Objective-C
1986
      // @interface context.
1987
2
      if (Tok.isAtStartOfLine() && 
NextToken().is(tok::kw_namespace)1
&&
1988
2
          
(1
!ParsingInObjCContainer1
||
CurParsedObjCImpl0
))
1989
1
        return;
1990
1
      break;
1991
1992
6
    case tok::kw_namespace:
1993
      // 'namespace' at the start of a line is almost certainly a good
1994
      // place to pick back up parsing, except in an Objective-C
1995
      // @interface context.
1996
6
      if (Tok.isAtStartOfLine() &&
1997
6
          
(4
!ParsingInObjCContainer4
||
CurParsedObjCImpl3
))
1998
2
        return;
1999
4
      break;
2000
2001
4
    case tok::at:
2002
      // @end is very much like } in Objective-C contexts.
2003
2
      if (NextToken().isObjCAtKeyword(tok::objc_end) &&
2004
2
          ParsingInObjCContainer)
2005
2
        return;
2006
0
      break;
2007
2008
2
    case tok::minus:
2009
15
    case tok::plus:
2010
      // - and + probably start new method declarations in Objective-C contexts.
2011
15
      if (Tok.isAtStartOfLine() && 
ParsingInObjCContainer4
)
2012
4
        return;
2013
11
      break;
2014
2015
126
    case tok::eof:
2016
126
    case tok::annot_module_begin:
2017
147
    case tok::annot_module_end:
2018
147
    case tok::annot_module_include:
2019
147
      return;
2020
2021
667
    default:
2022
667
      break;
2023
1.28k
    }
2024
2025
683
    ConsumeAnyToken();
2026
683
  }
2027
545
}
2028
2029
/// ParseDeclGroup - Having concluded that this is either a function
2030
/// definition or a group of object declarations, actually parse the
2031
/// result.
2032
Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
2033
                                              DeclaratorContext Context,
2034
                                              ParsedAttributes &Attrs,
2035
                                              SourceLocation *DeclEnd,
2036
27.0M
                                              ForRangeInit *FRI) {
2037
  // Parse the first declarator.
2038
  // Consume all of the attributes from `Attrs` by moving them to our own local
2039
  // list. This ensures that we will not attempt to interpret them as statement
2040
  // attributes higher up the callchain.
2041
27.0M
  ParsedAttributes LocalAttrs(AttrFactory);
2042
27.0M
  LocalAttrs.takeAllFrom(Attrs);
2043
27.0M
  ParsingDeclarator D(*this, DS, LocalAttrs, Context);
2044
27.0M
  ParseDeclarator(D);
2045
2046
  // Bail out if the first declarator didn't seem well-formed.
2047
27.0M
  if (!D.hasName() && 
!D.mayOmitIdentifier()397
) {
2048
397
    SkipMalformedDecl();
2049
397
    return nullptr;
2050
397
  }
2051
2052
27.0M
  if (Tok.is(tok::kw_requires))
2053
13
    ParseTrailingRequiresClause(D);
2054
2055
  // Save late-parsed attributes for now; they need to be parsed in the
2056
  // appropriate function scope after the function Decl has been constructed.
2057
  // These will be parsed in ParseFunctionDefinition or ParseLexedAttrList.
2058
27.0M
  LateParsedAttrList LateParsedAttrs(true);
2059
27.0M
  if (D.isFunctionDeclarator()) {
2060
22.9M
    MaybeParseGNUAttributes(D, &LateParsedAttrs);
2061
2062
    // The _Noreturn keyword can't appear here, unlike the GNU noreturn
2063
    // attribute. If we find the keyword here, tell the user to put it
2064
    // at the start instead.
2065
22.9M
    if (Tok.is(tok::kw__Noreturn)) {
2066
6
      SourceLocation Loc = ConsumeToken();
2067
6
      const char *PrevSpec;
2068
6
      unsigned DiagID;
2069
2070
      // We can offer a fixit if it's valid to mark this function as _Noreturn
2071
      // and we don't have any other declarators in this declaration.
2072
6
      bool Fixit = !DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
2073
6
      MaybeParseGNUAttributes(D, &LateParsedAttrs);
2074
6
      Fixit &= Tok.isOneOf(tok::semi, tok::l_brace, tok::kw_try);
2075
2076
6
      Diag(Loc, diag::err_c11_noreturn_misplaced)
2077
6
          << (Fixit ? FixItHint::CreateRemoval(Loc) : 
FixItHint()0
)
2078
6
          << (Fixit ? FixItHint::CreateInsertion(D.getBeginLoc(), "_Noreturn ")
2079
6
                    : 
FixItHint()0
);
2080
6
    }
2081
22.9M
  }
2082
2083
  // Check to see if we have a function *definition* which must have a body.
2084
27.0M
  if (D.isFunctionDeclarator()) {
2085
22.9M
    if (Tok.is(tok::equal) && 
NextToken().is(tok::code_completion)714
) {
2086
2
      cutOffParsing();
2087
2
      Actions.CodeCompleteAfterFunctionEquals(D);
2088
2
      return nullptr;
2089
2
    }
2090
    // We're at the point where the parsing of function declarator is finished.
2091
    //
2092
    // A common error is that users accidently add a virtual specifier
2093
    // (e.g. override) in an out-line method definition.
2094
    // We attempt to recover by stripping all these specifiers coming after
2095
    // the declarator.
2096
22.9M
    
while (auto 22.9M
Specifier = isCXX11VirtSpecifier()) {
2097
4
      Diag(Tok, diag::err_virt_specifier_outside_class)
2098
4
          << VirtSpecifiers::getSpecifierName(Specifier)
2099
4
          << FixItHint::CreateRemoval(Tok.getLocation());
2100
4
      ConsumeToken();
2101
4
    }
2102
    // Look at the next token to make sure that this isn't a function
2103
    // declaration.  We have to check this because __attribute__ might be the
2104
    // start of a function definition in GCC-extended K&R C.
2105
22.9M
    if (!isDeclarationAfterDeclarator()) {
2106
2107
      // Function definitions are only allowed at file scope and in C++ classes.
2108
      // The C++ inline method definition case is handled elsewhere, so we only
2109
      // need to handle the file scope definition case.
2110
2.40M
      if (Context == DeclaratorContext::File) {
2111
2.40M
        if (isStartOfFunctionDefinition(D)) {
2112
2.40M
          if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
2113
9
            Diag(Tok, diag::err_function_declared_typedef);
2114
2115
            // Recover by treating the 'typedef' as spurious.
2116
9
            DS.ClearStorageClassSpecs();
2117
9
          }
2118
2119
2.40M
          Decl *TheDecl = ParseFunctionDefinition(D, ParsedTemplateInfo(),
2120
2.40M
                                                  &LateParsedAttrs);
2121
2.40M
          return Actions.ConvertDeclToDeclGroup(TheDecl);
2122
2.40M
        }
2123
2124
38
        if (isDeclarationSpecifier()) {
2125
          // If there is an invalid declaration specifier right after the
2126
          // function prototype, then we must be in a missing semicolon case
2127
          // where this isn't actually a body.  Just fall through into the code
2128
          // that handles it as a prototype, and let the top-level code handle
2129
          // the erroneous declspec where it would otherwise expect a comma or
2130
          // semicolon.
2131
33
        } else {
2132
33
          Diag(Tok, diag::err_expected_fn_body);
2133
33
          SkipUntil(tok::semi);
2134
33
          return nullptr;
2135
33
        }
2136
38
      } else {
2137
10
        if (Tok.is(tok::l_brace)) {
2138
7
          Diag(Tok, diag::err_function_definition_not_allowed);
2139
7
          SkipMalformedDecl();
2140
7
          return nullptr;
2141
7
        }
2142
10
      }
2143
2.40M
    }
2144
22.9M
  }
2145
2146
24.6M
  if (ParseAsmAttributesAfterDeclarator(D))
2147
8
    return nullptr;
2148
2149
  // C++0x [stmt.iter]p1: Check if we have a for-range-declarator. If so, we
2150
  // must parse and analyze the for-range-initializer before the declaration is
2151
  // analyzed.
2152
  //
2153
  // Handle the Objective-C for-in loop variable similarly, although we
2154
  // don't need to parse the container in advance.
2155
24.6M
  if (FRI && 
(133k
Tok.is(tok::colon)133k
||
isTokIdentifier_in()131k
)) {
2156
1.49k
    bool IsForRangeLoop = false;
2157
1.49k
    if (TryConsumeToken(tok::colon, FRI->ColonLoc)) {
2158
1.46k
      IsForRangeLoop = true;
2159
1.46k
      if (getLangOpts().OpenMP)
2160
143
        Actions.startOpenMPCXXRangeFor();
2161
1.46k
      if (Tok.is(tok::l_brace))
2162
10
        FRI->RangeExpr = ParseBraceInitializer();
2163
1.45k
      else
2164
1.45k
        FRI->RangeExpr = ParseExpression();
2165
1.46k
    }
2166
2167
1.49k
    Decl *ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
2168
1.49k
    if (IsForRangeLoop) {
2169
1.46k
      Actions.ActOnCXXForRangeDecl(ThisDecl);
2170
1.46k
    } else {
2171
      // Obj-C for loop
2172
37
      if (auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl))
2173
36
        VD->setObjCForDecl(true);
2174
37
    }
2175
1.49k
    Actions.FinalizeDeclaration(ThisDecl);
2176
1.49k
    D.complete(ThisDecl);
2177
1.49k
    return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, ThisDecl);
2178
1.49k
  }
2179
2180
24.6M
  SmallVector<Decl *, 8> DeclsInGroup;
2181
24.6M
  Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(
2182
24.6M
      D, ParsedTemplateInfo(), FRI);
2183
24.6M
  if (LateParsedAttrs.size() > 0)
2184
698
    ParseLexedAttributeList(LateParsedAttrs, FirstDecl, true, false);
2185
24.6M
  D.complete(FirstDecl);
2186
24.6M
  if (FirstDecl)
2187
24.6M
    DeclsInGroup.push_back(FirstDecl);
2188
2189
24.6M
  bool ExpectSemi = Context != DeclaratorContext::ForInit;
2190
2191
  // If we don't have a comma, it is either the end of the list (a ';') or an
2192
  // error, bail out.
2193
24.6M
  SourceLocation CommaLoc;
2194
24.8M
  while (TryConsumeToken(tok::comma, CommaLoc)) {
2195
172k
    if (Tok.isAtStartOfLine() && 
ExpectSemi114k
&&
!MightBeDeclarator(Context)114k
) {
2196
      // This comma was followed by a line-break and something which can't be
2197
      // the start of a declarator. The comma was probably a typo for a
2198
      // semicolon.
2199
40
      Diag(CommaLoc, diag::err_expected_semi_declaration)
2200
40
        << FixItHint::CreateReplacement(CommaLoc, ";");
2201
40
      ExpectSemi = false;
2202
40
      break;
2203
40
    }
2204
2205
    // Parse the next declarator.
2206
172k
    D.clear();
2207
172k
    D.setCommaLoc(CommaLoc);
2208
2209
    // Accept attributes in an init-declarator.  In the first declarator in a
2210
    // declaration, these would be part of the declspec.  In subsequent
2211
    // declarators, they become part of the declarator itself, so that they
2212
    // don't apply to declarators after *this* one.  Examples:
2213
    //    short __attribute__((common)) var;    -> declspec
2214
    //    short var __attribute__((common));    -> declarator
2215
    //    short x, __attribute__((common)) var;    -> declarator
2216
172k
    MaybeParseGNUAttributes(D);
2217
2218
    // MSVC parses but ignores qualifiers after the comma as an extension.
2219
172k
    if (getLangOpts().MicrosoftExt)
2220
304
      DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2221
2222
172k
    ParseDeclarator(D);
2223
172k
    if (!D.isInvalidType()) {
2224
      // C++2a [dcl.decl]p1
2225
      //    init-declarator:
2226
      //        declarator initializer[opt]
2227
      //        declarator requires-clause
2228
172k
      if (Tok.is(tok::kw_requires))
2229
0
        ParseTrailingRequiresClause(D);
2230
172k
      Decl *ThisDecl = ParseDeclarationAfterDeclarator(D);
2231
172k
      D.complete(ThisDecl);
2232
172k
      if (ThisDecl)
2233
172k
        DeclsInGroup.push_back(ThisDecl);
2234
172k
    }
2235
172k
  }
2236
2237
24.6M
  if (DeclEnd)
2238
3.14M
    *DeclEnd = Tok.getLocation();
2239
2240
24.6M
  if (ExpectSemi && ExpectAndConsumeSemi(
2241
24.4M
                        Context == DeclaratorContext::File
2242
24.4M
                            ? 
diag::err_invalid_token_after_toplevel_declarator23.1M
2243
24.4M
                            : 
diag::err_expected_semi_declaration1.36M
)) {
2244
    // Okay, there was no semicolon and one was expected.  If we see a
2245
    // declaration specifier, just assume it was missing and continue parsing.
2246
    // Otherwise things are very confused and we skip to recover.
2247
312
    if (!isDeclarationSpecifier()) {
2248
290
      SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
2249
290
      TryConsumeToken(tok::semi);
2250
290
    }
2251
312
  }
2252
2253
24.6M
  return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup);
2254
24.6M
}
2255
2256
/// Parse an optional simple-asm-expr and attributes, and attach them to a
2257
/// declarator. Returns true on an error.
2258
24.9M
bool Parser::ParseAsmAttributesAfterDeclarator(Declarator &D) {
2259
  // If a simple-asm-expr is present, parse it.
2260
24.9M
  if (Tok.is(tok::kw_asm)) {
2261
58.0k
    SourceLocation Loc;
2262
58.0k
    ExprResult AsmLabel(ParseSimpleAsm(/*ForAsmLabel*/ true, &Loc));
2263
58.0k
    if (AsmLabel.isInvalid()) {
2264
8
      SkipUntil(tok::semi, StopBeforeMatch);
2265
8
      return true;
2266
8
    }
2267
2268
58.0k
    D.setAsmLabel(AsmLabel.get());
2269
58.0k
    D.SetRangeEnd(Loc);
2270
58.0k
  }
2271
2272
24.9M
  MaybeParseGNUAttributes(D);
2273
24.9M
  return false;
2274
24.9M
}
2275
2276
/// Parse 'declaration' after parsing 'declaration-specifiers
2277
/// declarator'. This method parses the remainder of the declaration
2278
/// (including any attributes or initializer, among other things) and
2279
/// finalizes the declaration.
2280
///
2281
///       init-declarator: [C99 6.7]
2282
///         declarator
2283
///         declarator '=' initializer
2284
/// [GNU]   declarator simple-asm-expr[opt] attributes[opt]
2285
/// [GNU]   declarator simple-asm-expr[opt] attributes[opt] '=' initializer
2286
/// [C++]   declarator initializer[opt]
2287
///
2288
/// [C++] initializer:
2289
/// [C++]   '=' initializer-clause
2290
/// [C++]   '(' expression-list ')'
2291
/// [C++0x] '=' 'default'                                                [TODO]
2292
/// [C++0x] '=' 'delete'
2293
/// [C++0x] braced-init-list
2294
///
2295
/// According to the standard grammar, =default and =delete are function
2296
/// definitions, but that definitely doesn't fit with the parser here.
2297
///
2298
Decl *Parser::ParseDeclarationAfterDeclarator(
2299
320k
    Declarator &D, const ParsedTemplateInfo &TemplateInfo) {
2300
320k
  if (ParseAsmAttributesAfterDeclarator(D))
2301
0
    return nullptr;
2302
2303
320k
  return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
2304
320k
}
2305
2306
Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
2307
24.9M
    Declarator &D, const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
2308
  // RAII type used to track whether we're inside an initializer.
2309
24.9M
  struct InitializerScopeRAII {
2310
24.9M
    Parser &P;
2311
24.9M
    Declarator &D;
2312
24.9M
    Decl *ThisDecl;
2313
2314
24.9M
    InitializerScopeRAII(Parser &P, Declarator &D, Decl *ThisDecl)
2315
24.9M
        : P(P), D(D), ThisDecl(ThisDecl) {
2316
868k
      if (ThisDecl && 
P.getLangOpts().CPlusPlus868k
) {
2317
803k
        Scope *S = nullptr;
2318
803k
        if (D.getCXXScopeSpec().isSet()) {
2319
2.61k
          P.EnterScope(0);
2320
2.61k
          S = P.getCurScope();
2321
2.61k
        }
2322
803k
        P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl);
2323
803k
      }
2324
868k
    }
2325
24.9M
    ~InitializerScopeRAII() 
{ pop(); }868k
2326
24.9M
    void pop() {
2327
1.73M
      if (ThisDecl && 
P.getLangOpts().CPlusPlus868k
) {
2328
803k
        Scope *S = nullptr;
2329
803k
        if (D.getCXXScopeSpec().isSet())
2330
2.61k
          S = P.getCurScope();
2331
803k
        P.Actions.ActOnCXXExitDeclInitializer(S, ThisDecl);
2332
803k
        if (S)
2333
2.61k
          P.ExitScope();
2334
803k
      }
2335
1.73M
      ThisDecl = nullptr;
2336
1.73M
    }
2337
24.9M
  };
2338
2339
24.9M
  enum class InitKind { Uninitialized, Equal, CXXDirect, CXXBraced };
2340
24.9M
  InitKind TheInitKind;
2341
  // If a '==' or '+=' is found, suggest a fixit to '='.
2342
24.9M
  if (isTokenEqualOrEqualTypo())
2343
784k
    TheInitKind = InitKind::Equal;
2344
24.1M
  else if (Tok.is(tok::l_paren))
2345
78.8k
    TheInitKind = InitKind::CXXDirect;
2346
24.0M
  else if (getLangOpts().CPlusPlus11 && 
Tok.is(tok::l_brace)9.64M
&&
2347
24.0M
           
(5.58k
!CurParsedObjCImpl5.58k
||
!D.isFunctionDeclarator()1
))
2348
5.58k
    TheInitKind = InitKind::CXXBraced;
2349
24.0M
  else
2350
24.0M
    TheInitKind = InitKind::Uninitialized;
2351
24.9M
  if (TheInitKind != InitKind::Uninitialized)
2352
868k
    D.setHasInitializer();
2353
2354
  // Inform Sema that we just parsed this declarator.
2355
24.9M
  Decl *ThisDecl = nullptr;
2356
24.9M
  Decl *OuterDecl = nullptr;
2357
24.9M
  switch (TemplateInfo.Kind) {
2358
24.8M
  case ParsedTemplateInfo::NonTemplate:
2359
24.8M
    ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
2360
24.8M
    break;
2361
2362
95.6k
  case ParsedTemplateInfo::Template:
2363
99.3k
  case ParsedTemplateInfo::ExplicitSpecialization: {
2364
99.3k
    ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
2365
99.3k
                                               *TemplateInfo.TemplateParams,
2366
99.3k
                                               D);
2367
99.3k
    if (VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl)) {
2368
      // Re-direct this decl to refer to the templated decl so that we can
2369
      // initialize it.
2370
3.75k
      ThisDecl = VT->getTemplatedDecl();
2371
3.75k
      OuterDecl = VT;
2372
3.75k
    }
2373
99.3k
    break;
2374
95.6k
  }
2375
48.9k
  case ParsedTemplateInfo::ExplicitInstantiation: {
2376
48.9k
    if (Tok.is(tok::semi)) {
2377
48.9k
      DeclResult ThisRes = Actions.ActOnExplicitInstantiation(
2378
48.9k
          getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
2379
48.9k
      if (ThisRes.isInvalid()) {
2380
113
        SkipUntil(tok::semi, StopBeforeMatch);
2381
113
        return nullptr;
2382
113
      }
2383
48.7k
      ThisDecl = ThisRes.get();
2384
48.7k
    } else {
2385
      // FIXME: This check should be for a variable template instantiation only.
2386
2387
      // Check that this is a valid instantiation
2388
6
      if (D.getName().getKind() != UnqualifiedIdKind::IK_TemplateId) {
2389
        // If the declarator-id is not a template-id, issue a diagnostic and
2390
        // recover by ignoring the 'template' keyword.
2391
3
        Diag(Tok, diag::err_template_defn_explicit_instantiation)
2392
3
            << 2 << FixItHint::CreateRemoval(TemplateInfo.TemplateLoc);
2393
3
        ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
2394
3
      } else {
2395
3
        SourceLocation LAngleLoc =
2396
3
            PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
2397
3
        Diag(D.getIdentifierLoc(),
2398
3
             diag::err_explicit_instantiation_with_definition)
2399
3
            << SourceRange(TemplateInfo.TemplateLoc)
2400
3
            << FixItHint::CreateInsertion(LAngleLoc, "<>");
2401
2402
        // Recover as if it were an explicit specialization.
2403
3
        TemplateParameterLists FakedParamLists;
2404
3
        FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
2405
3
            0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, None,
2406
3
            LAngleLoc, nullptr));
2407
2408
3
        ThisDecl =
2409
3
            Actions.ActOnTemplateDeclarator(getCurScope(), FakedParamLists, D);
2410
3
      }
2411
6
    }
2412
48.7k
    break;
2413
48.9k
    }
2414
24.9M
  }
2415
2416
24.9M
  switch (TheInitKind) {
2417
  // Parse declarator '=' initializer.
2418
784k
  case InitKind::Equal: {
2419
784k
    SourceLocation EqualLoc = ConsumeToken();
2420
2421
784k
    if (Tok.is(tok::kw_delete)) {
2422
3
      if (D.isFunctionDeclarator())
2423
1
        Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration)
2424
1
          << 1 /* delete */;
2425
2
      else
2426
2
        Diag(ConsumeToken(), diag::err_deleted_non_function);
2427
784k
    } else if (Tok.is(tok::kw_default)) {
2428
2
      if (D.isFunctionDeclarator())
2429
1
        Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration)
2430
1
          << 0 /* default */;
2431
1
      else
2432
1
        Diag(ConsumeToken(), diag::err_default_special_members)
2433
1
            << getLangOpts().CPlusPlus20;
2434
784k
    } else {
2435
784k
      InitializerScopeRAII InitScope(*this, D, ThisDecl);
2436
2437
784k
      if (Tok.is(tok::code_completion)) {
2438
42
        cutOffParsing();
2439
42
        Actions.CodeCompleteInitializer(getCurScope(), ThisDecl);
2440
42
        Actions.FinalizeDeclaration(ThisDecl);
2441
42
        return nullptr;
2442
42
      }
2443
2444
784k
      PreferredType.enterVariableInit(Tok.getLocation(), ThisDecl);
2445
784k
      ExprResult Init = ParseInitializer();
2446
2447
      // If this is the only decl in (possibly) range based for statement,
2448
      // our best guess is that the user meant ':' instead of '='.
2449
784k
      if (Tok.is(tok::r_paren) && 
FRI5
&&
D.isFirstDeclarator()3
) {
2450
3
        Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2451
3
            << FixItHint::CreateReplacement(EqualLoc, ":");
2452
        // We are trying to stop parser from looking for ';' in this for
2453
        // statement, therefore preventing spurious errors to be issued.
2454
3
        FRI->ColonLoc = EqualLoc;
2455
3
        Init = ExprError();
2456
3
        FRI->RangeExpr = Init;
2457
3
      }
2458
2459
784k
      InitScope.pop();
2460
2461
784k
      if (Init.isInvalid()) {
2462
1.40k
        SmallVector<tok::TokenKind, 2> StopTokens;
2463
1.40k
        StopTokens.push_back(tok::comma);
2464
1.40k
        if (D.getContext() == DeclaratorContext::ForInit ||
2465
1.40k
            
D.getContext() == DeclaratorContext::SelectionInit1.40k
)
2466
4
          StopTokens.push_back(tok::r_paren);
2467
1.40k
        SkipUntil(StopTokens, StopAtSemi | StopBeforeMatch);
2468
1.40k
        Actions.ActOnInitializerError(ThisDecl);
2469
1.40k
      } else
2470
783k
        Actions.AddInitializerToDecl(ThisDecl, Init.get(),
2471
783k
                                     /*DirectInit=*/false);
2472
784k
    }
2473
784k
    break;
2474
784k
  }
2475
784k
  case InitKind::CXXDirect: {
2476
    // Parse C++ direct initializer: '(' expression-list ')'
2477
78.8k
    BalancedDelimiterTracker T(*this, tok::l_paren);
2478
78.8k
    T.consumeOpen();
2479
2480
78.8k
    ExprVector Exprs;
2481
78.8k
    CommaLocsTy CommaLocs;
2482
2483
78.8k
    InitializerScopeRAII InitScope(*this, D, ThisDecl);
2484
2485
78.8k
    auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2486
78.8k
    auto RunSignatureHelp = [&]() {
2487
13
      QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
2488
13
          ThisVarDecl->getType()->getCanonicalTypeInternal(),
2489
13
          ThisDecl->getLocation(), Exprs, T.getOpenLocation(),
2490
13
          /*Braced=*/false);
2491
13
      CalledSignatureHelp = true;
2492
13
      return PreferredType;
2493
13
    };
2494
122k
    auto SetPreferredType = [&] {
2495
122k
      PreferredType.enterFunctionArgument(Tok.getLocation(), RunSignatureHelp);
2496
122k
    };
2497
2498
78.8k
    llvm::function_ref<void()> ExpressionStarts;
2499
78.8k
    if (ThisVarDecl) {
2500
      // ParseExpressionList can sometimes succeed even when ThisDecl is not
2501
      // VarDecl. This is an error and it is reported in a call to
2502
      // Actions.ActOnInitializerError(). However, we call
2503
      // ProduceConstructorSignatureHelp only on VarDecls.
2504
78.8k
      ExpressionStarts = SetPreferredType;
2505
78.8k
    }
2506
78.8k
    if (ParseExpressionList(Exprs, CommaLocs, ExpressionStarts)) {
2507
76
      if (ThisVarDecl && 
PP.isCodeCompletionReached()75
&&
!CalledSignatureHelp19
) {
2508
2
        Actions.ProduceConstructorSignatureHelp(
2509
2
            ThisVarDecl->getType()->getCanonicalTypeInternal(),
2510
2
            ThisDecl->getLocation(), Exprs, T.getOpenLocation(),
2511
2
            /*Braced=*/false);
2512
2
        CalledSignatureHelp = true;
2513
2
      }
2514
76
      Actions.ActOnInitializerError(ThisDecl);
2515
76
      SkipUntil(tok::r_paren, StopAtSemi);
2516
78.7k
    } else {
2517
      // Match the ')'.
2518
78.7k
      T.consumeClose();
2519
2520
78.7k
      assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
2521
78.7k
             "Unexpected number of commas!");
2522
2523
0
      InitScope.pop();
2524
2525
78.7k
      ExprResult Initializer = Actions.ActOnParenListExpr(T.getOpenLocation(),
2526
78.7k
                                                          T.getCloseLocation(),
2527
78.7k
                                                          Exprs);
2528
78.7k
      Actions.AddInitializerToDecl(ThisDecl, Initializer.get(),
2529
78.7k
                                   /*DirectInit=*/true);
2530
78.7k
    }
2531
0
    break;
2532
784k
  }
2533
5.58k
  case InitKind::CXXBraced: {
2534
    // Parse C++0x braced-init-list.
2535
5.58k
    Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2536
2537
5.58k
    InitializerScopeRAII InitScope(*this, D, ThisDecl);
2538
2539
5.58k
    PreferredType.enterVariableInit(Tok.getLocation(), ThisDecl);
2540
5.58k
    ExprResult Init(ParseBraceInitializer());
2541
2542
5.58k
    InitScope.pop();
2543
2544
5.58k
    if (Init.isInvalid()) {
2545
21
      Actions.ActOnInitializerError(ThisDecl);
2546
21
    } else
2547
5.56k
      Actions.AddInitializerToDecl(ThisDecl, Init.get(), /*DirectInit=*/true);
2548
5.58k
    break;
2549
784k
  }
2550
24.0M
  case InitKind::Uninitialized: {
2551
24.0M
    Actions.ActOnUninitializedDecl(ThisDecl);
2552
24.0M
    break;
2553
784k
  }
2554
24.9M
  }
2555
2556
24.9M
  Actions.FinalizeDeclaration(ThisDecl);
2557
24.9M
  return OuterDecl ? 
OuterDecl3.75k
:
ThisDecl24.9M
;
2558
24.9M
}
2559
2560
/// ParseSpecifierQualifierList
2561
///        specifier-qualifier-list:
2562
///          type-specifier specifier-qualifier-list[opt]
2563
///          type-qualifier specifier-qualifier-list[opt]
2564
/// [GNU]    attributes     specifier-qualifier-list[opt]
2565
///
2566
void Parser::ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS,
2567
14.6M
                                         DeclSpecContext DSC) {
2568
  /// specifier-qualifier-list is a subset of declaration-specifiers.  Just
2569
  /// parse declaration-specifiers and complain about extra stuff.
2570
  /// TODO: diagnose attribute-specifiers and alignment-specifiers.
2571
14.6M
  ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC);
2572
2573
  // Validate declspec for type-name.
2574
14.6M
  unsigned Specs = DS.getParsedSpecifiers();
2575
14.6M
  if (isTypeSpecifier(DSC) && 
!DS.hasTypeSpecifier()5.67M
) {
2576
154
    Diag(Tok, diag::err_expected_type);
2577
154
    DS.SetTypeSpecError();
2578
14.6M
  } else if (Specs == DeclSpec::PQ_None && 
!DS.hasAttributes()47
) {
2579
29
    Diag(Tok, diag::err_typename_requires_specqual);
2580
29
    if (!DS.hasTypeSpecifier())
2581
29
      DS.SetTypeSpecError();
2582
29
  }
2583
2584
  // Issue diagnostic and remove storage class if present.
2585
14.6M
  if (Specs & DeclSpec::PQ_StorageClassSpecifier) {
2586
16
    if (DS.getStorageClassSpecLoc().isValid())
2587
11
      Diag(DS.getStorageClassSpecLoc(),diag::err_typename_invalid_storageclass);
2588
5
    else
2589
5
      Diag(DS.getThreadStorageClassSpecLoc(),
2590
5
           diag::err_typename_invalid_storageclass);
2591
16
    DS.ClearStorageClassSpecs();
2592
16
  }
2593
2594
  // Issue diagnostic and remove function specifier if present.
2595
14.6M
  if (Specs & DeclSpec::PQ_FunctionSpecifier) {
2596
6
    if (DS.isInlineSpecified())
2597
2
      Diag(DS.getInlineSpecLoc(), diag::err_typename_invalid_functionspec);
2598
6
    if (DS.isVirtualSpecified())
2599
2
      Diag(DS.getVirtualSpecLoc(), diag::err_typename_invalid_functionspec);
2600
6
    if (DS.hasExplicitSpecifier())
2601
2
      Diag(DS.getExplicitSpecLoc(), diag::err_typename_invalid_functionspec);
2602
6
    DS.ClearFunctionSpecs();
2603
6
  }
2604
2605
  // Issue diagnostic and remove constexpr specifier if present.
2606
14.6M
  if (DS.hasConstexprSpecifier() && 
DSC != DeclSpecContext::DSC_condition34
) {
2607
7
    Diag(DS.getConstexprSpecLoc(), diag::err_typename_invalid_constexpr)
2608
7
        << static_cast<int>(DS.getConstexprSpecifier());
2609
7
    DS.ClearConstexprSpec();
2610
7
  }
2611
14.6M
}
2612
2613
/// isValidAfterIdentifierInDeclaratorAfterDeclSpec - Return true if the
2614
/// specified token is valid after the identifier in a declarator which
2615
/// immediately follows the declspec.  For example, these things are valid:
2616
///
2617
///      int x   [             4];         // direct-declarator
2618
///      int x   (             int y);     // direct-declarator
2619
///  int(int x   )                         // direct-declarator
2620
///      int x   ;                         // simple-declaration
2621
///      int x   =             17;         // init-declarator-list
2622
///      int x   ,             y;          // init-declarator-list
2623
///      int x   __asm__       ("foo");    // init-declarator-list
2624
///      int x   :             4;          // struct-declarator
2625
///      int x   {             5};         // C++'0x unified initializers
2626
///
2627
/// This is not, because 'x' does not immediately follow the declspec (though
2628
/// ')' happens to be valid anyway).
2629
///    int (x)
2630
///
2631
292
static bool isValidAfterIdentifierInDeclarator(const Token &T) {
2632
292
  return T.isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2633
292
                   tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2634
292
                   tok::colon);
2635
292
}
2636
2637
/// ParseImplicitInt - This method is called when we have an non-typename
2638
/// identifier in a declspec (which normally terminates the decl spec) when
2639
/// the declspec has no type specifier.  In this case, the declspec is either
2640
/// malformed or is "implicit int" (in K&R and C89).
2641
///
2642
/// This method handles diagnosing this prettily and returns false if the
2643
/// declspec is done being processed.  If it recovers and thinks there may be
2644
/// other pieces of declspec after it, it returns true.
2645
///
2646
bool Parser::ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
2647
                              const ParsedTemplateInfo &TemplateInfo,
2648
                              AccessSpecifier AS, DeclSpecContext DSC,
2649
1.66k
                              ParsedAttributes &Attrs) {
2650
1.66k
  assert(Tok.is(tok::identifier) && "should have identifier");
2651
2652
0
  SourceLocation Loc = Tok.getLocation();
2653
  // If we see an identifier that is not a type name, we normally would
2654
  // parse it as the identifier being declared.  However, when a typename
2655
  // is typo'd or the definition is not included, this will incorrectly
2656
  // parse the typename as the identifier name and fall over misparsing
2657
  // later parts of the diagnostic.
2658
  //
2659
  // As such, we try to do some look-ahead in cases where this would
2660
  // otherwise be an "implicit-int" case to see if this is invalid.  For
2661
  // example: "static foo_t x = 4;"  In this case, if we parsed foo_t as
2662
  // an identifier with implicit int, we'd get a parse error because the
2663
  // next token is obviously invalid for a type.  Parse these as a case
2664
  // with an invalid type specifier.
2665
1.66k
  assert(!DS.hasTypeSpecifier() && "Type specifier checked above");
2666
2667
  // Since we know that this either implicit int (which is rare) or an
2668
  // error, do lookahead to try to do better recovery. This never applies
2669
  // within a type specifier. Outside of C++, we allow this even if the
2670
  // language doesn't "officially" support implicit int -- we support
2671
  // implicit int as an extension in some language modes.
2672
1.66k
  if (!isTypeSpecifier(DSC) && 
getLangOpts().isImplicitIntAllowed()1.50k
&&
2673
1.66k
      
isValidAfterIdentifierInDeclarator(NextToken())292
) {
2674
    // If this token is valid for implicit int, e.g. "static x = 4", then
2675
    // we just avoid eating the identifier, so it will be parsed as the
2676
    // identifier in the declarator.
2677
99
    return false;
2678
99
  }
2679
2680
  // Early exit as Sema has a dedicated missing_actual_pipe_type diagnostic
2681
  // for incomplete declarations such as `pipe p`.
2682
1.56k
  if (getLangOpts().OpenCLCPlusPlus && 
DS.isTypeSpecPipe()5
)
2683
3
    return false;
2684
2685
1.56k
  if (getLangOpts().CPlusPlus &&
2686
1.56k
      
DS.getStorageClassSpec() == DeclSpec::SCS_auto1.34k
) {
2687
    // Don't require a type specifier if we have the 'auto' storage class
2688
    // specifier in C++98 -- we'll promote it to a type specifier.
2689
74
    if (SS)
2690
3
      AnnotateScopeToken(*SS, /*IsNewAnnotation*/false);
2691
74
    return false;
2692
74
  }
2693
2694
1.48k
  if (getLangOpts().CPlusPlus && 
(1.26k
!SS1.26k
||
SS->isEmpty()532
) &&
2695
1.48k
      
getLangOpts().MSVCCompat735
) {
2696
    // Lookup of an unqualified type name has failed in MSVC compatibility mode.
2697
    // Give Sema a chance to recover if we are in a template with dependent base
2698
    // classes.
2699
41
    if (ParsedType T = Actions.ActOnMSVCUnknownTypeName(
2700
41
            *Tok.getIdentifierInfo(), Tok.getLocation(),
2701
41
            DSC == DeclSpecContext::DSC_template_type_arg)) {
2702
15
      const char *PrevSpec;
2703
15
      unsigned DiagID;
2704
15
      DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, T,
2705
15
                         Actions.getASTContext().getPrintingPolicy());
2706
15
      DS.SetRangeEnd(Tok.getLocation());
2707
15
      ConsumeToken();
2708
15
      return false;
2709
15
    }
2710
41
  }
2711
2712
  // Otherwise, if we don't consume this token, we are going to emit an
2713
  // error anyway.  Try to recover from various common problems.  Check
2714
  // to see if this was a reference to a tag name without a tag specified.
2715
  // This is a common problem in C (saying 'foo' instead of 'struct foo').
2716
  //
2717
  // C++ doesn't need this, and isTagName doesn't take SS.
2718
1.47k
  if (SS == nullptr) {
2719
939
    const char *TagName = nullptr, *FixitTagName = nullptr;
2720
939
    tok::TokenKind TagKind = tok::unknown;
2721
2722
939
    switch (Actions.isTagName(*Tok.getIdentifierInfo(), getCurScope())) {
2723
901
      default: break;
2724
901
      case DeclSpec::TST_enum:
2725
11
        TagName="enum"  ; FixitTagName = "enum "  ; TagKind=tok::kw_enum ;break;
2726
0
      case DeclSpec::TST_union:
2727
0
        TagName="union" ; FixitTagName = "union " ;TagKind=tok::kw_union ;break;
2728
18
      case DeclSpec::TST_struct:
2729
18
        TagName="struct"; FixitTagName = "struct ";TagKind=tok::kw_struct;break;
2730
0
      case DeclSpec::TST_interface:
2731
0
        TagName="__interface"; FixitTagName = "__interface ";
2732
0
        TagKind=tok::kw___interface;break;
2733
9
      case DeclSpec::TST_class:
2734
9
        TagName="class" ; FixitTagName = "class " ;TagKind=tok::kw_class ;break;
2735
939
    }
2736
2737
939
    if (TagName) {
2738
38
      IdentifierInfo *TokenName = Tok.getIdentifierInfo();
2739
38
      LookupResult R(Actions, TokenName, SourceLocation(),
2740
38
                     Sema::LookupOrdinaryName);
2741
2742
38
      Diag(Loc, diag::err_use_of_tag_name_without_tag)
2743
38
        << TokenName << TagName << getLangOpts().CPlusPlus
2744
38
        << FixItHint::CreateInsertion(Tok.getLocation(), FixitTagName);
2745
2746
38
      if (Actions.LookupParsedName(R, getCurScope(), SS)) {
2747
23
        for (LookupResult::iterator I = R.begin(), IEnd = R.end();
2748
46
             I != IEnd; 
++I23
)
2749
23
          Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2750
23
            << TokenName << TagName;
2751
23
      }
2752
2753
      // Parse this as a tag as if the missing tag were present.
2754
38
      if (TagKind == tok::kw_enum)
2755
11
        ParseEnumSpecifier(Loc, DS, TemplateInfo, AS,
2756
11
                           DeclSpecContext::DSC_normal);
2757
27
      else
2758
27
        ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2759
27
                            /*EnteringContext*/ false,
2760
27
                            DeclSpecContext::DSC_normal, Attrs);
2761
38
      return true;
2762
38
    }
2763
939
  }
2764
2765
  // Determine whether this identifier could plausibly be the name of something
2766
  // being declared (with a missing type).
2767
1.43k
  if (!isTypeSpecifier(DSC) && 
(1.29k
!SS1.29k
||
DSC == DeclSpecContext::DSC_top_level495
||
2768
1.29k
                                
DSC == DeclSpecContext::DSC_class304
)) {
2769
    // Look ahead to the next token to try to figure out what this declaration
2770
    // was supposed to be.
2771
1.11k
    switch (NextToken().getKind()) {
2772
72
    case tok::l_paren: {
2773
      // static x(4); // 'x' is not a type
2774
      // x(int n);    // 'x' is not a type
2775
      // x (*p)[];    // 'x' is a type
2776
      //
2777
      // Since we're in an error case, we can afford to perform a tentative
2778
      // parse to determine which case we're in.
2779
72
      TentativeParsingAction PA(*this);
2780
72
      ConsumeToken();
2781
72
      TPResult TPR = TryParseDeclarator(/*mayBeAbstract*/false);
2782
72
      PA.Revert();
2783
2784
72
      if (TPR != TPResult::False) {
2785
        // The identifier is followed by a parenthesized declarator.
2786
        // It's supposed to be a type.
2787
2
        break;
2788
2
      }
2789
2790
      // If we're in a context where we could be declaring a constructor,
2791
      // check whether this is a constructor declaration with a bogus name.
2792
70
      if (DSC == DeclSpecContext::DSC_class ||
2793
70
          
(44
DSC == DeclSpecContext::DSC_top_level44
&&
SS42
)) {
2794
45
        IdentifierInfo *II = Tok.getIdentifierInfo();
2795
45
        if (Actions.isCurrentClassNameTypo(II, SS)) {
2796
10
          Diag(Loc, diag::err_constructor_bad_name)
2797
10
            << Tok.getIdentifierInfo() << II
2798
10
            << FixItHint::CreateReplacement(Tok.getLocation(), II->getName());
2799
10
          Tok.setIdentifierInfo(II);
2800
10
        }
2801
45
      }
2802
      // Fall through.
2803
70
      LLVM_FALLTHROUGH;
2804
70
    }
2805
82
    case tok::comma:
2806
111
    case tok::equal:
2807
111
    case tok::kw_asm:
2808
126
    case tok::l_brace:
2809
129
    case tok::l_square:
2810
195
    case tok::semi:
2811
      // This looks like a variable or function declaration. The type is
2812
      // probably missing. We're done parsing decl-specifiers.
2813
      // But only if we are not in a function prototype scope.
2814
195
      if (getCurScope()->isFunctionPrototypeScope())
2815
10
        break;
2816
185
      if (SS)
2817
47
        AnnotateScopeToken(*SS, /*IsNewAnnotation*/false);
2818
185
      return false;
2819
2820
918
    default:
2821
      // This is probably supposed to be a type. This includes cases like:
2822
      //   int f(itn);
2823
      //   struct S { unsigned : 4; };
2824
918
      break;
2825
1.11k
    }
2826
1.11k
  }
2827
2828
  // This is almost certainly an invalid type name. Let Sema emit a diagnostic
2829
  // and attempt to recover.
2830
1.24k
  ParsedType T;
2831
1.24k
  IdentifierInfo *II = Tok.getIdentifierInfo();
2832
1.24k
  bool IsTemplateName = getLangOpts().CPlusPlus && 
NextToken().is(tok::less)1.04k
;
2833
1.24k
  Actions.DiagnoseUnknownTypeName(II, Loc, getCurScope(), SS, T,
2834
1.24k
                                  IsTemplateName);
2835
1.24k
  if (T) {
2836
    // The action has suggested that the type T could be used. Set that as
2837
    // the type in the declaration specifiers, consume the would-be type
2838
    // name token, and we're done.
2839
267
    const char *PrevSpec;
2840
267
    unsigned DiagID;
2841
267
    DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, T,
2842
267
                       Actions.getASTContext().getPrintingPolicy());
2843
267
    DS.SetRangeEnd(Tok.getLocation());
2844
267
    ConsumeToken();
2845
    // There may be other declaration specifiers after this.
2846
267
    return true;
2847
981
  } else if (II != Tok.getIdentifierInfo()) {
2848
    // If no type was suggested, the correction is to a keyword
2849
13
    Tok.setKind(II->getTokenID());
2850
    // There may be other declaration specifiers after this.
2851
13
    return true;
2852
13
  }
2853
2854
  // Otherwise, the action had no suggestion for us.  Mark this as an error.
2855
968
  DS.SetTypeSpecError();
2856
968
  DS.SetRangeEnd(Tok.getLocation());
2857
968
  ConsumeToken();
2858
2859
  // Eat any following template arguments.
2860
968
  if (IsTemplateName) {
2861
11
    SourceLocation LAngle, RAngle;
2862
11
    TemplateArgList Args;
2863
11
    ParseTemplateIdAfterTemplateName(true, LAngle, Args, RAngle);
2864
11
  }
2865
2866
  // TODO: Could inject an invalid typedef decl in an enclosing scope to
2867
  // avoid rippling error messages on subsequent uses of the same type,
2868
  // could be useful if #include was forgotten.
2869
968
  return true;
2870
1.24k
}
2871
2872
/// Determine the declaration specifier context from the declarator
2873
/// context.
2874
///
2875
/// \param Context the declarator context, which is one of the
2876
/// DeclaratorContext enumerator values.
2877
Parser::DeclSpecContext
2878
9.94M
Parser::getDeclSpecContextFromDeclaratorContext(DeclaratorContext Context) {
2879
9.94M
  if (Context == DeclaratorContext::Member)
2880
0
    return DeclSpecContext::DSC_class;
2881
9.94M
  if (Context == DeclaratorContext::File)
2882
2.95M
    return DeclSpecContext::DSC_top_level;
2883
6.99M
  if (Context == DeclaratorContext::TemplateParam)
2884
0
    return DeclSpecContext::DSC_template_param;
2885
6.99M
  if (Context == DeclaratorContext::TemplateArg ||
2886
6.99M
      
Context == DeclaratorContext::TemplateTypeArg2.07M
)
2887
5.04M
    return DeclSpecContext::DSC_template_type_arg;
2888
1.94M
  if (Context == DeclaratorContext::TrailingReturn ||
2889
1.94M
      
Context == DeclaratorContext::TrailingReturnVar1.94M
)
2890
10.3k
    return DeclSpecContext::DSC_trailing;
2891
1.93M
  if (Context == DeclaratorContext::AliasDecl ||
2892
1.93M
      
Context == DeclaratorContext::AliasTemplate1.86M
)
2893
128k
    return DeclSpecContext::DSC_alias_declaration;
2894
1.80M
  if (Context == DeclaratorContext::Association)
2895
490
    return DeclSpecContext::DSC_association;
2896
1.80M
  return DeclSpecContext::DSC_normal;
2897
1.80M
}
2898
2899
/// ParseAlignArgument - Parse the argument to an alignment-specifier.
2900
///
2901
/// FIXME: Simply returns an alignof() expression if the argument is a
2902
/// type. Ideally, the type should be propagated directly into Sema.
2903
///
2904
/// [C11]   type-id
2905
/// [C11]   constant-expression
2906
/// [C++0x] type-id ...[opt]
2907
/// [C++0x] assignment-expression ...[opt]
2908
ExprResult Parser::ParseAlignArgument(SourceLocation Start,
2909
10.5k
                                      SourceLocation &EllipsisLoc) {
2910
10.5k
  ExprResult ER;
2911
10.5k
  if (isTypeIdInParens()) {
2912
878
    SourceLocation TypeLoc = Tok.getLocation();
2913
878
    ParsedType Ty = ParseTypeName().get();
2914
878
    SourceRange TypeRange(Start, Tok.getLocation());
2915
878
    ER = Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true,
2916
878
                                               Ty.getAsOpaquePtr(), TypeRange);
2917
878
  } else
2918
9.62k
    ER = ParseConstantExpression();
2919
2920
10.5k
  if (getLangOpts().CPlusPlus11)
2921
10.4k
    TryConsumeToken(tok::ellipsis, EllipsisLoc);
2922
2923
10.5k
  return ER;
2924
10.5k
}
2925
2926
/// ParseAlignmentSpecifier - Parse an alignment-specifier, and add the
2927
/// attribute to Attrs.
2928
///
2929
/// alignment-specifier:
2930
/// [C11]   '_Alignas' '(' type-id ')'
2931
/// [C11]   '_Alignas' '(' constant-expression ')'
2932
/// [C++11] 'alignas' '(' type-id ...[opt] ')'
2933
/// [C++11] 'alignas' '(' assignment-expression ...[opt] ')'
2934
void Parser::ParseAlignmentSpecifier(ParsedAttributes &Attrs,
2935
10.5k
                                     SourceLocation *EndLoc) {
2936
10.5k
  assert(Tok.isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
2937
10.5k
         "Not an alignment-specifier!");
2938
2939
0
  IdentifierInfo *KWName = Tok.getIdentifierInfo();
2940
10.5k
  SourceLocation KWLoc = ConsumeToken();
2941
2942
10.5k
  BalancedDelimiterTracker T(*this, tok::l_paren);
2943
10.5k
  if (T.expectAndConsume())
2944
1
    return;
2945
2946
10.5k
  SourceLocation EllipsisLoc;
2947
10.5k
  ExprResult ArgExpr = ParseAlignArgument(T.getOpenLocation(), EllipsisLoc);
2948
10.5k
  if (ArgExpr.isInvalid()) {
2949
10
    T.skipToEnd();
2950
10
    return;
2951
10
  }
2952
2953
10.4k
  T.consumeClose();
2954
10.4k
  if (EndLoc)
2955
9.31k
    *EndLoc = T.getCloseLocation();
2956
2957
10.4k
  ArgsVector ArgExprs;
2958
10.4k
  ArgExprs.push_back(ArgExpr.get());
2959
10.4k
  Attrs.addNew(KWName, KWLoc, nullptr, KWLoc, ArgExprs.data(), 1,
2960
10.4k
               ParsedAttr::AS_Keyword, EllipsisLoc);
2961
10.4k
}
2962
2963
1.05k
ExprResult Parser::ParseExtIntegerArgument() {
2964
1.05k
  assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
2965
1.05k
         "Not an extended int type");
2966
0
  ConsumeToken();
2967
2968
1.05k
  BalancedDelimiterTracker T(*this, tok::l_paren);
2969
1.05k
  if (T.expectAndConsume())
2970
1
    return ExprError();
2971
2972
1.05k
  ExprResult ER = ParseConstantExpression();
2973
1.05k
  if (ER.isInvalid()) {
2974
1
    T.skipToEnd();
2975
1
    return ExprError();
2976
1
  }
2977
2978
1.05k
  if(T.consumeClose())
2979
1
    return ExprError();
2980
1.05k
  return ER;
2981
1.05k
}
2982
2983
/// Determine whether we're looking at something that might be a declarator
2984
/// in a simple-declaration. If it can't possibly be a declarator, maybe
2985
/// diagnose a missing semicolon after a prior tag definition in the decl
2986
/// specifier.
2987
///
2988
/// \return \c true if an error occurred and this can't be any kind of
2989
/// declaration.
2990
bool
2991
Parser::DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS,
2992
                                              DeclSpecContext DSContext,
2993
1.14M
                                              LateParsedAttrList *LateAttrs) {
2994
1.14M
  assert(DS.hasTagDefinition() && "shouldn't call this");
2995
2996
1.14M
  bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
2997
1.14M
                          
DSContext == DeclSpecContext::DSC_top_level1.10M
);
2998
2999
1.14M
  if (getLangOpts().CPlusPlus &&
3000
1.14M
      Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
3001
363k
                  tok::annot_template_id) &&
3002
1.14M
      
TryAnnotateCXXScopeToken(EnteringContext)63.9k
) {
3003
0
    SkipMalformedDecl();
3004
0
    return true;
3005
0
  }
3006
3007
1.14M
  bool HasScope = Tok.is(tok::annot_cxxscope);
3008
  // Make a copy in case GetLookAheadToken invalidates the result of NextToken.
3009
1.14M
  Token AfterScope = HasScope ? 
NextToken()20
:
Tok1.14M
;
3010
3011
  // Determine whether the following tokens could possibly be a
3012
  // declarator.
3013
1.14M
  bool MightBeDeclarator = true;
3014
1.14M
  if (Tok.isOneOf(tok::kw_typename, tok::annot_typename)) {
3015
    // A declarator-id can't start with 'typename'.
3016
0
    MightBeDeclarator = false;
3017
1.14M
  } else if (AfterScope.is(tok::annot_template_id)) {
3018
    // If we have a type expressed as a template-id, this cannot be a
3019
    // declarator-id (such a type cannot be redeclared in a simple-declaration).
3020
8
    TemplateIdAnnotation *Annot =
3021
8
        static_cast<TemplateIdAnnotation *>(AfterScope.getAnnotationValue());
3022
8
    if (Annot->Kind == TNK_Type_template)
3023
8
      MightBeDeclarator = false;
3024
1.14M
  } else if (AfterScope.is(tok::identifier)) {
3025
271k
    const Token &Next = HasScope ? 
GetLookAheadToken(2)10
:
NextToken()271k
;
3026
3027
    // These tokens cannot come after the declarator-id in a
3028
    // simple-declaration, and are likely to come after a type-specifier.
3029
271k
    if (Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
3030
271k
                     tok::annot_cxxscope, tok::coloncolon)) {
3031
      // Missing a semicolon.
3032
5
      MightBeDeclarator = false;
3033
271k
    } else if (HasScope) {
3034
      // If the declarator-id has a scope specifier, it must redeclare a
3035
      // previously-declared entity. If that's a type (and this is not a
3036
      // typedef), that's an error.
3037
9
      CXXScopeSpec SS;
3038
9
      Actions.RestoreNestedNameSpecifierAnnotation(
3039
9
          Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3040
9
      IdentifierInfo *Name = AfterScope.getIdentifierInfo();
3041
9
      Sema::NameClassification Classification = Actions.ClassifyName(
3042
9
          getCurScope(), SS, Name, AfterScope.getLocation(), Next,
3043
9
          /*CCC=*/nullptr);
3044
9
      switch (Classification.getKind()) {
3045
0
      case Sema::NC_Error:
3046
0
        SkipMalformedDecl();
3047
0
        return true;
3048
3049
0
      case Sema::NC_Keyword:
3050
0
        llvm_unreachable("typo correction is not possible here");
3051
3052
1
      case Sema::NC_Type:
3053
1
      case Sema::NC_TypeTemplate:
3054
1
      case Sema::NC_UndeclaredNonType:
3055
1
      case Sema::NC_UndeclaredTemplate:
3056
        // Not a previously-declared non-type entity.
3057
1
        MightBeDeclarator = false;
3058
1
        break;
3059
3060
1
      case Sema::NC_Unknown:
3061
5
      case Sema::NC_NonType:
3062
5
      case Sema::NC_DependentNonType:
3063
8
      case Sema::NC_OverloadSet:
3064
8
      case Sema::NC_VarTemplate:
3065
8
      case Sema::NC_FunctionTemplate:
3066
8
      case Sema::NC_Concept:
3067
        // Might be a redeclaration of a prior entity.
3068
8
        break;
3069
9
      }
3070
9
    }
3071
271k
  }
3072
3073
1.14M
  if (MightBeDeclarator)
3074
1.14M
    return false;
3075
3076
14
  const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
3077
14
  Diag(PP.getLocForEndOfToken(DS.getRepAsDecl()->getEndLoc()),
3078
14
       diag::err_expected_after)
3079
14
      << DeclSpec::getSpecifierName(DS.getTypeSpecType(), PPol) << tok::semi;
3080
3081
  // Try to recover from the typo, by dropping the tag definition and parsing
3082
  // the problematic tokens as a type.
3083
  //
3084
  // FIXME: Split the DeclSpec into pieces for the standalone
3085
  // declaration and pieces for the following declaration, instead
3086
  // of assuming that all the other pieces attach to new declaration,
3087
  // and call ParsedFreeStandingDeclSpec as appropriate.
3088
14
  DS.ClearTypeSpecType();
3089
14
  ParsedTemplateInfo NotATemplate;
3090
14
  ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
3091
14
  return false;
3092
1.14M
}
3093
3094
// Choose the apprpriate diagnostic error for why fixed point types are
3095
// disabled, set the previous specifier, and mark as invalid.
3096
static void SetupFixedPointError(const LangOptions &LangOpts,
3097
                                 const char *&PrevSpec, unsigned &DiagID,
3098
9
                                 bool &isInvalid) {
3099
9
  assert(!LangOpts.FixedPoint);
3100
0
  DiagID = diag::err_fixed_point_not_enabled;
3101
9
  PrevSpec = "";  // Not used by diagnostic
3102
9
  isInvalid = true;
3103
9
}
3104
3105
/// ParseDeclarationSpecifiers
3106
///       declaration-specifiers: [C99 6.7]
3107
///         storage-class-specifier declaration-specifiers[opt]
3108
///         type-specifier declaration-specifiers[opt]
3109
/// [C99]   function-specifier declaration-specifiers[opt]
3110
/// [C11]   alignment-specifier declaration-specifiers[opt]
3111
/// [GNU]   attributes declaration-specifiers[opt]
3112
/// [Clang] '__module_private__' declaration-specifiers[opt]
3113
/// [ObjC1] '__kindof' declaration-specifiers[opt]
3114
///
3115
///       storage-class-specifier: [C99 6.7.1]
3116
///         'typedef'
3117
///         'extern'
3118
///         'static'
3119
///         'auto'
3120
///         'register'
3121
/// [C++]   'mutable'
3122
/// [C++11] 'thread_local'
3123
/// [C11]   '_Thread_local'
3124
/// [GNU]   '__thread'
3125
///       function-specifier: [C99 6.7.4]
3126
/// [C99]   'inline'
3127
/// [C++]   'virtual'
3128
/// [C++]   'explicit'
3129
/// [OpenCL] '__kernel'
3130
///       'friend': [C++ dcl.friend]
3131
///       'constexpr': [C++0x dcl.constexpr]
3132
void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
3133
                                        const ParsedTemplateInfo &TemplateInfo,
3134
                                        AccessSpecifier AS,
3135
                                        DeclSpecContext DSContext,
3136
112M
                                        LateParsedAttrList *LateAttrs) {
3137
112M
  if (DS.getSourceRange().isInvalid()) {
3138
    // Start the range at the current token but make the end of the range
3139
    // invalid.  This will make the entire range invalid unless we successfully
3140
    // consume a token.
3141
112M
    DS.SetRangeStart(Tok.getLocation());
3142
112M
    DS.SetRangeEnd(SourceLocation());
3143
112M
  }
3144
3145
112M
  bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3146
112M
                          
DSContext == DeclSpecContext::DSC_top_level109M
);
3147
112M
  bool AttrsLastTime = false;
3148
112M
  ParsedAttributes attrs(AttrFactory);
3149
  // We use Sema's policy to get bool macros right.
3150
112M
  PrintingPolicy Policy = Actions.getPrintingPolicy();
3151
302M
  while (true) {
3152
302M
    bool isInvalid = false;
3153
302M
    bool isStorageClass = false;
3154
302M
    const char *PrevSpec = nullptr;
3155
302M
    unsigned DiagID = 0;
3156
3157
    // This value needs to be set to the location of the last token if the last
3158
    // token of the specifier is already consumed.
3159
302M
    SourceLocation ConsumedEnd;
3160
3161
    // HACK: MSVC doesn't consider _Atomic to be a keyword and its STL
3162
    // implementation for VS2013 uses _Atomic as an identifier for one of the
3163
    // classes in <atomic>.
3164
    //
3165
    // A typedef declaration containing _Atomic<...> is among the places where
3166
    // the class is used.  If we are currently parsing such a declaration, treat
3167
    // the token as an identifier.
3168
302M
    if (getLangOpts().MSVCCompat && 
Tok.is(tok::kw__Atomic)1.02M
&&
3169
302M
        
DS.getStorageClassSpec() == clang::DeclSpec::SCS_typedef40
&&
3170
302M
        
!DS.hasTypeSpecifier()7
&&
GetLookAheadToken(1).is(tok::less)7
)
3171
5
      Tok.setKind(tok::identifier);
3172
3173
302M
    SourceLocation Loc = Tok.getLocation();
3174
3175
    // Helper for image types in OpenCL.
3176
302M
    auto handleOpenCLImageKW = [&] (StringRef Ext, TypeSpecifierType ImageTypeSpec) {
3177
      // Check if the image type is supported and otherwise turn the keyword into an identifier
3178
      // because image types from extensions are not reserved identifiers.
3179
8.09k
      if (!StringRef(Ext).empty() && 
!getActions().getOpenCLOptions().isSupported(Ext, getLangOpts())1.14k
) {
3180
4
        Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
3181
4
        Tok.setKind(tok::identifier);
3182
4
        return false;
3183
4
      }
3184
8.09k
      isInvalid = DS.SetTypeSpecType(ImageTypeSpec, Loc, PrevSpec, DiagID, Policy);
3185
8.09k
      return true;
3186
8.09k
    };
3187
3188
    // Turn off usual access checking for template specializations and
3189
    // instantiations.
3190
302M
    bool IsTemplateSpecOrInst =
3191
302M
        (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
3192
302M
         
TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization302M
);
3193
3194
302M
    switch (Tok.getKind()) {
3195
72.8M
    default:
3196
112M
    DoneWithDeclSpec:
3197
112M
      if (!AttrsLastTime)
3198
112M
        ProhibitAttributes(attrs);
3199
115
      else {
3200
        // Reject C++11 / C2x attributes that aren't type attributes.
3201
115
        for (const ParsedAttr &PA : attrs) {
3202
98
          if (!PA.isCXX11Attribute() && 
!PA.isC2xAttribute()35
)
3203
0
            continue;
3204
98
          if (PA.getKind() == ParsedAttr::UnknownAttribute)
3205
            // We will warn about the unknown attribute elsewhere (in
3206
            // SemaDeclAttr.cpp)
3207
4
            continue;
3208
          // GCC ignores this attribute when placed on the DeclSpec in [[]]
3209
          // syntax, so we do the same.
3210
94
          if (PA.getKind() == ParsedAttr::AT_VectorSize) {
3211
1
            Diag(PA.getLoc(), diag::warn_attribute_ignored) << PA;
3212
1
            PA.setInvalid();
3213
1
            continue;
3214
1
          }
3215
          // We reject AT_LifetimeBound and AT_AnyX86NoCfCheck, even though they
3216
          // are type attributes, because we historically haven't allowed these
3217
          // to be used as type attributes in C++11 / C2x syntax.
3218
93
          if (PA.isTypeAttr() && 
PA.getKind() != ParsedAttr::AT_LifetimeBound78
&&
3219
93
              
PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck77
)
3220
76
            continue;
3221
17
          Diag(PA.getLoc(), diag::err_attribute_not_type_attr) << PA;
3222
17
          PA.setInvalid();
3223
17
        }
3224
3225
115
        DS.takeAttributesFrom(attrs);
3226
115
      }
3227
3228
      // If this is not a declaration specifier token, we're done reading decl
3229
      // specifiers.  First verify that DeclSpec's are consistent.
3230
112M
      DS.Finish(Actions, Policy);
3231
112M
      return;
3232
3233
26.0k
    case tok::l_square:
3234
26.0k
    case tok::kw_alignas:
3235
26.0k
      if (!standardAttributesAllowed() || 
!isCXX11AttributeSpecifier()18.7k
)
3236
25.9k
        goto DoneWithDeclSpec;
3237
3238
130
      ProhibitAttributes(attrs);
3239
      // FIXME: It would be good to recover by accepting the attributes,
3240
      //        but attempting to do that now would cause serious
3241
      //        madness in terms of diagnostics.
3242
130
      attrs.clear();
3243
130
      attrs.Range = SourceRange();
3244
3245
130
      ParseCXX11Attributes(attrs);
3246
130
      AttrsLastTime = true;
3247
130
      continue;
3248
3249
45
    case tok::code_completion: {
3250
45
      Sema::ParserCompletionContext CCC = Sema::PCC_Namespace;
3251
45
      if (DS.hasTypeSpecifier()) {
3252
35
        bool AllowNonIdentifiers
3253
35
          = (getCurScope()->getFlags() & (Scope::ControlScope |
3254
35
                                          Scope::BlockScope |
3255
35
                                          Scope::TemplateParamScope |
3256
35
                                          Scope::FunctionPrototypeScope |
3257
35
                                          Scope::AtCatchScope)) == 0;
3258
35
        bool AllowNestedNameSpecifiers
3259
35
          = DSContext == DeclSpecContext::DSC_top_level ||
3260
35
            
(24
DSContext == DeclSpecContext::DSC_class24
&&
DS.isFriendSpecified()13
);
3261
3262
35
        cutOffParsing();
3263
35
        Actions.CodeCompleteDeclSpec(getCurScope(), DS,
3264
35
                                     AllowNonIdentifiers,
3265
35
                                     AllowNestedNameSpecifiers);
3266
35
        return;
3267
35
      }
3268
3269
10
      if (getCurScope()->getFnParent() || 
getCurScope()->getBlockParent()9
)
3270
1
        CCC = Sema::PCC_LocalDeclarationSpecifiers;
3271
9
      else if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
3272
0
        CCC = DSContext == DeclSpecContext::DSC_class ? Sema::PCC_MemberTemplate
3273
0
                                                      : Sema::PCC_Template;
3274
9
      else if (DSContext == DeclSpecContext::DSC_class)
3275
8
        CCC = Sema::PCC_Class;
3276
1
      else if (CurParsedObjCImpl)
3277
0
        CCC = Sema::PCC_ObjCImplementation;
3278
3279
10
      cutOffParsing();
3280
10
      Actions.CodeCompleteOrdinaryName(getCurScope(), CCC);
3281
10
      return;
3282
45
    }
3283
3284
652
    case tok::coloncolon: // ::foo::bar
3285
      // C++ scope specifier.  Annotate and loop, or bail out on error.
3286
652
      if (TryAnnotateCXXScopeToken(EnteringContext)) {
3287
0
        if (!DS.hasTypeSpecifier())
3288
0
          DS.SetTypeSpecError();
3289
0
        goto DoneWithDeclSpec;
3290
0
      }
3291
652
      if (Tok.is(tok::coloncolon)) // ::new or ::delete
3292
3
        goto DoneWithDeclSpec;
3293
649
      continue;
3294
3295
163k
    case tok::annot_cxxscope: {
3296
163k
      if (DS.hasTypeSpecifier() || 
DS.isTypeAltiVecVector()163k
)
3297
60
        goto DoneWithDeclSpec;
3298
3299
163k
      CXXScopeSpec SS;
3300
163k
      Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3301
163k
                                                   Tok.getAnnotationRange(),
3302
163k
                                                   SS);
3303
3304
      // We are looking for a qualified typename.
3305
163k
      Token Next = NextToken();
3306
3307
163k
      TemplateIdAnnotation *TemplateId = Next.is(tok::annot_template_id)
3308
163k
                                             ? 
takeTemplateIdAnnotation(Next)26.3k
3309
163k
                                             : 
nullptr137k
;
3310
163k
      if (TemplateId && 
TemplateId->hasInvalidName()26.3k
) {
3311
        // We found something like 'T::U<Args> x', but U is not a template.
3312
        // Assume it was supposed to be a type.
3313
6
        DS.SetTypeSpecError();
3314
6
        ConsumeAnnotationToken();
3315
6
        break;
3316
6
      }
3317
3318
163k
      if (TemplateId && 
TemplateId->Kind == TNK_Type_template26.2k
) {
3319
        // We have a qualified template-id, e.g., N::A<int>
3320
3321
        // If this would be a valid constructor declaration with template
3322
        // arguments, we will reject the attempt to form an invalid type-id
3323
        // referring to the injected-class-name when we annotate the token,
3324
        // per C++ [class.qual]p2.
3325
        //
3326
        // To improve diagnostics for this case, parse the declaration as a
3327
        // constructor (and reject the extra template arguments later).
3328
26.2k
        if ((DSContext == DeclSpecContext::DSC_top_level ||
3329
26.2k
             
DSContext == DeclSpecContext::DSC_class22.3k
) &&
3330
26.2k
            
TemplateId->Name13.1k
&&
3331
26.2k
            
Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)13.1k
&&
3332
26.2k
            
isConstructorDeclarator(/*Unqualified=*/false)25
) {
3333
          // The user meant this to be an out-of-line constructor
3334
          // definition, but template arguments are not allowed
3335
          // there.  Just allow this as a constructor; we'll
3336
          // complain about it later.
3337
16
          goto DoneWithDeclSpec;
3338
16
        }
3339
3340
26.2k
        DS.getTypeSpecScope() = SS;
3341
26.2k
        ConsumeAnnotationToken(); // The C++ scope.
3342
26.2k
        assert(Tok.is(tok::annot_template_id) &&
3343
26.2k
               "ParseOptionalCXXScopeSpecifier not working");
3344
0
        AnnotateTemplateIdTokenAsType(SS);
3345
26.2k
        continue;
3346
26.2k
      }
3347
3348
137k
      if (TemplateId && 
TemplateId->Kind == TNK_Concept_template34
&&
3349
137k
          
GetLookAheadToken(2).isOneOf(tok::kw_auto, tok::kw_decltype)26
) {
3350
26
        DS.getTypeSpecScope() = SS;
3351
        // This is a qualified placeholder-specifier, e.g., ::C<int> auto ...
3352
        // Consume the scope annotation and continue to consume the template-id
3353
        // as a placeholder-specifier.
3354
26
        ConsumeAnnotationToken();
3355
26
        continue;
3356
26
      }
3357
3358
137k
      if (Next.is(tok::annot_typename)) {
3359
0
        DS.getTypeSpecScope() = SS;
3360
0
        ConsumeAnnotationToken(); // The C++ scope.
3361
0
        TypeResult T = getTypeAnnotation(Tok);
3362
0
        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename,
3363
0
                                       Tok.getAnnotationEndLoc(),
3364
0
                                       PrevSpec, DiagID, T, Policy);
3365
0
        if (isInvalid)
3366
0
          break;
3367
0
        DS.SetRangeEnd(Tok.getAnnotationEndLoc());
3368
0
        ConsumeAnnotationToken(); // The typename
3369
0
      }
3370
3371
137k
      if (Next.isNot(tok::identifier))
3372
5.57k
        goto DoneWithDeclSpec;
3373
3374
      // Check whether this is a constructor declaration. If we're in a
3375
      // context where the identifier could be a class name, and it has the
3376
      // shape of a constructor declaration, process it as one.
3377
131k
      if ((DSContext == DeclSpecContext::DSC_top_level ||
3378
131k
           
DSContext == DeclSpecContext::DSC_class68.6k
) &&
3379
131k
          Actions.isCurrentClassName(*Next.getIdentifierInfo(), getCurScope(),
3380
83.1k
                                     &SS) &&
3381
131k
          
isConstructorDeclarator(/*Unqualified*/ false)49.0k
)
3382
49.0k
        goto DoneWithDeclSpec;
3383
3384
      // C++20 [temp.spec] 13.9/6.
3385
      // This disables the access checking rules for function template explicit
3386
      // instantiation and explicit specialization:
3387
      // - `return type`.
3388
82.6k
      SuppressAccessChecks SAC(*this, IsTemplateSpecOrInst);
3389
3390
82.6k
      ParsedType TypeRep =
3391
82.6k
          Actions.getTypeName(*Next.getIdentifierInfo(), Next.getLocation(),
3392
82.6k
                              getCurScope(), &SS, false, false, nullptr,
3393
82.6k
                              /*IsCtorOrDtorName=*/false,
3394
82.6k
                              /*WantNontrivialTypeSourceInfo=*/true,
3395
82.6k
                              isClassTemplateDeductionContext(DSContext));
3396
3397
82.6k
      if (IsTemplateSpecOrInst)
3398
7.87k
        SAC.done();
3399
3400
      // If the referenced identifier is not a type, then this declspec is
3401
      // erroneous: We already checked about that it has no type specifier, and
3402
      // C++ doesn't have implicit int.  Diagnose it as a typo w.r.t. to the
3403
      // typename.
3404
82.6k
      if (!TypeRep) {
3405
544
        if (TryAnnotateTypeConstraint())
3406
0
          goto DoneWithDeclSpec;
3407
544
        if (Tok.isNot(tok::annot_cxxscope) ||
3408
544
            NextToken().isNot(tok::identifier))
3409
9
          continue;
3410
        // Eat the scope spec so the identifier is current.
3411
535
        ConsumeAnnotationToken();
3412
535
        ParsedAttributes Attrs(AttrFactory);
3413
535
        if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3414
485
          if (!Attrs.empty()) {
3415
0
            AttrsLastTime = true;
3416
0
            attrs.takeAllFrom(Attrs);
3417
0
          }
3418
485
          continue;
3419
485
        }
3420
50
        goto DoneWithDeclSpec;
3421
535
      }
3422
3423
82.1k
      DS.getTypeSpecScope() = SS;
3424
82.1k
      ConsumeAnnotationToken(); // The C++ scope.
3425
3426
82.1k
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
3427
82.1k
                                     DiagID, TypeRep, Policy);
3428
82.1k
      if (isInvalid)
3429
0
        break;
3430
3431
82.1k
      DS.SetRangeEnd(Tok.getLocation());
3432
82.1k
      ConsumeToken(); // The typename.
3433
3434
82.1k
      continue;
3435
82.1k
    }
3436
3437
33.8M
    case tok::annot_typename: {
3438
      // If we've previously seen a tag definition, we were almost surely
3439
      // missing a semicolon after it.
3440
33.8M
      if (DS.hasTypeSpecifier() && 
DS.hasTagDefinition()3
)
3441
0
        goto DoneWithDeclSpec;
3442
3443
33.8M
      TypeResult T = getTypeAnnotation(Tok);
3444
33.8M
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
3445
33.8M
                                     DiagID, T, Policy);
3446
33.8M
      if (isInvalid)
3447
3
        break;
3448
3449
33.8M
      DS.SetRangeEnd(Tok.getAnnotationEndLoc());
3450
33.8M
      ConsumeAnnotationToken(); // The typename
3451
3452
33.8M
      continue;
3453
33.8M
    }
3454
3455
1
    case tok::kw___is_signed:
3456
      // GNU libstdc++ 4.4 uses __is_signed as an identifier, but Clang
3457
      // typically treats it as a trait. If we see __is_signed as it appears
3458
      // in libstdc++, e.g.,
3459
      //
3460
      //   static const bool __is_signed;
3461
      //
3462
      // then treat __is_signed as an identifier rather than as a keyword.
3463
1
      if (DS.getTypeSpecType() == TST_bool &&
3464
1
          DS.getTypeQualifiers() == DeclSpec::TQ_const &&
3465
1
          DS.getStorageClassSpec() == DeclSpec::SCS_static)
3466
1
        TryKeywordIdentFallback(true);
3467
3468
      // We're done with the declaration-specifiers.
3469
1
      goto DoneWithDeclSpec;
3470
3471
      // typedef-name
3472
7
    case tok::kw___super:
3473
28.2k
    case tok::kw_decltype:
3474
106M
    case tok::identifier: {
3475
      // This identifier can only be a typedef name if we haven't already seen
3476
      // a type-specifier.  Without this check we misparse:
3477
      //  typedef int X; struct Y { short X; };  as 'short int'.
3478
106M
      if (DS.hasTypeSpecifier())
3479
39.5M
        goto DoneWithDeclSpec;
3480
3481
      // If the token is an identifier named "__declspec" and Microsoft
3482
      // extensions are not enabled, it is likely that there will be cascading
3483
      // parse errors if this really is a __declspec attribute. Attempt to
3484
      // recognize that scenario and recover gracefully.
3485
67.1M
      if (!getLangOpts().DeclSpecKeyword && 
Tok.is(tok::identifier)66.9M
&&
3486
67.1M
          
Tok.getIdentifierInfo()->getName().equals("__declspec")66.8M
) {
3487
2
        Diag(Loc, diag::err_ms_attributes_not_enabled);
3488
3489
        // The next token should be an open paren. If it is, eat the entire
3490
        // attribute declaration and continue.
3491
2
        if (NextToken().is(tok::l_paren)) {
3492
          // Consume the __declspec identifier.
3493
2
          ConsumeToken();
3494
3495
          // Eat the parens and everything between them.
3496
2
          BalancedDelimiterTracker T(*this, tok::l_paren);
3497
2
          if (T.consumeOpen()) {
3498
0
            assert(false && "Not a left paren?");
3499
0
            return;
3500
0
          }
3501
2
          T.skipToEnd();
3502
2
          continue;
3503
2
        }
3504
2
      }
3505
3506
      // In C++, check to see if this is a scope specifier like foo::bar::, if
3507
      // so handle it as such.  This is important for ctor parsing.
3508
67.1M
      if (getLangOpts().CPlusPlus) {
3509
        // C++20 [temp.spec] 13.9/6.
3510
        // This disables the access checking rules for function template
3511
        // explicit instantiation and explicit specialization:
3512
        // - `return type`.
3513
28.5M
        SuppressAccessChecks SAC(*this, IsTemplateSpecOrInst);
3514
3515
28.5M
        const bool Success = TryAnnotateCXXScopeToken(EnteringContext);
3516
3517
28.5M
        if (IsTemplateSpecOrInst)
3518
25.4k
          SAC.done();
3519
3520
28.5M
        if (Success) {
3521
25
          if (IsTemplateSpecOrInst)
3522
0
            SAC.redelay();
3523
25
          DS.SetTypeSpecError();
3524
25
          goto DoneWithDeclSpec;
3525
25
        }
3526
3527
28.5M
        if (!Tok.is(tok::identifier))
3528
979k
          continue;
3529
28.5M
      }
3530
3531
      // Check for need to substitute AltiVec keyword tokens.
3532
66.1M
      if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid))
3533
74.2k
        break;
3534
3535
      // [AltiVec] 2.2: [If the 'vector' specifier is used] The syntax does not
3536
      //                allow the use of a typedef name as a type specifier.
3537
66.0M
      if (DS.isTypeAltiVecVector())
3538
1.86k
        goto DoneWithDeclSpec;
3539
3540
66.0M
      if (DSContext == DeclSpecContext::DSC_objc_method_result &&
3541
66.0M
          
isObjCInstancetype()111k
) {
3542
110k
        ParsedType TypeRep = Actions.ActOnObjCInstanceType(Loc);
3543
110k
        assert(TypeRep);
3544
0
        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
3545
110k
                                       DiagID, TypeRep, Policy);
3546
110k
        if (isInvalid)
3547
0
          break;
3548
3549
110k
        DS.SetRangeEnd(Loc);
3550
110k
        ConsumeToken();
3551
110k
        continue;
3552
110k
      }
3553
3554
      // If we're in a context where the identifier could be a class name,
3555
      // check whether this is a constructor declaration.
3556
65.9M
      if (getLangOpts().CPlusPlus && 
DSContext == DeclSpecContext::DSC_class27.5M
&&
3557
65.9M
          
Actions.isCurrentClassName(*Tok.getIdentifierInfo(), getCurScope())1.73M
&&
3558
65.9M
          
isConstructorDeclarator(/*Unqualified*/true)452k
)
3559
309k
        goto DoneWithDeclSpec;
3560
3561
65.6M
      ParsedType TypeRep = Actions.getTypeName(
3562
65.6M
          *Tok.getIdentifierInfo(), Tok.getLocation(), getCurScope(), nullptr,
3563
65.6M
          false, false, nullptr, false, false,
3564
65.6M
          isClassTemplateDeductionContext(DSContext));
3565
3566
      // If this is not a typedef name, don't parse it as part of the declspec,
3567
      // it must be an implicit int or an error.
3568
65.6M
      if (!TypeRep) {
3569
1.18k
        if (TryAnnotateTypeConstraint())
3570
0
          goto DoneWithDeclSpec;
3571
1.18k
        if (Tok.isNot(tok::identifier))
3572
57
          continue;
3573
1.12k
        ParsedAttributes Attrs(AttrFactory);
3574
1.12k
        if (ParseImplicitInt(DS, nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3575
801
          if (!Attrs.empty()) {
3576
0
            AttrsLastTime = true;
3577
0
            attrs.takeAllFrom(Attrs);
3578
0
          }
3579
801
          continue;
3580
801
        }
3581
326
        goto DoneWithDeclSpec;
3582
1.12k
      }
3583
3584
      // Likewise, if this is a context where the identifier could be a template
3585
      // name, check whether this is a deduction guide declaration.
3586
65.6M
      if (getLangOpts().CPlusPlus17 &&
3587
65.6M
          
(347k
DSContext == DeclSpecContext::DSC_class347k
||
3588
347k
           
DSContext == DeclSpecContext::DSC_top_level265k
) &&
3589
65.6M
          Actions.isDeductionGuideName(getCurScope(), *Tok.getIdentifierInfo(),
3590
140k
                                       Tok.getLocation()) &&
3591
65.6M
          isConstructorDeclarator(/*Unqualified*/ true,
3592
1.10k
                                  /*DeductionGuide*/ true))
3593
889
        goto DoneWithDeclSpec;
3594
3595
65.6M
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
3596
65.6M
                                     DiagID, TypeRep, Policy);
3597
65.6M
      if (isInvalid)
3598
0
        break;
3599
3600
65.6M
      DS.SetRangeEnd(Tok.getLocation());
3601
65.6M
      ConsumeToken(); // The identifier
3602
3603
      // Objective-C supports type arguments and protocol references
3604
      // following an Objective-C object or object pointer
3605
      // type. Handle either one of them.
3606
65.6M
      if (Tok.is(tok::less) && 
getLangOpts().ObjC52.2k
) {
3607
52.2k
        SourceLocation NewEndLoc;
3608
52.2k
        TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3609
52.2k
                                  Loc, TypeRep, /*consumeLastToken=*/true,
3610
52.2k
                                  NewEndLoc);
3611
52.2k
        if (NewTypeRep.isUsable()) {
3612
52.2k
          DS.UpdateTypeRep(NewTypeRep.get());
3613
52.2k
          DS.SetRangeEnd(NewEndLoc);
3614
52.2k
        }
3615
52.2k
      }
3616
3617
      // Need to support trailing type qualifiers (e.g. "id<p> const").
3618
      // If a type specifier follows, it will be diagnosed elsewhere.
3619
65.6M
      continue;
3620
65.6M
    }
3621
3622
      // type-name or placeholder-specifier
3623
813k
    case tok::annot_template_id: {
3624
813k
      TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
3625
3626
813k
      if (TemplateId->hasInvalidName()) {
3627
0
        DS.SetTypeSpecError();
3628
0
        break;
3629
0
      }
3630
3631
813k
      if (TemplateId->Kind == TNK_Concept_template) {
3632
        // If we've already diagnosed that this type-constraint has invalid
3633
        // arguemnts, drop it and just form 'auto' or 'decltype(auto)'.
3634
202
        if (TemplateId->hasInvalidArgs())
3635
2
          TemplateId = nullptr;
3636
3637
202
        if (NextToken().is(tok::identifier)) {
3638
1
          Diag(Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
3639
1
              << FixItHint::CreateInsertion(NextToken().getLocation(), "auto");
3640
          // Attempt to continue as if 'auto' was placed here.
3641
1
          isInvalid = DS.SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID,
3642
1
                                         TemplateId, Policy);
3643
1
          break;
3644
1
        }
3645
201
        if (!NextToken().isOneOf(tok::kw_auto, tok::kw_decltype))
3646
0
            goto DoneWithDeclSpec;
3647
201
        ConsumeAnnotationToken();
3648
201
        SourceLocation AutoLoc = Tok.getLocation();
3649
201
        if (TryConsumeToken(tok::kw_decltype)) {
3650
16
          BalancedDelimiterTracker Tracker(*this, tok::l_paren);
3651
16
          if (Tracker.consumeOpen()) {
3652
            // Something like `void foo(Iterator decltype i)`
3653
1
            Diag(Tok, diag::err_expected) << tok::l_paren;
3654
15
          } else {
3655
15
            if (!TryConsumeToken(tok::kw_auto)) {
3656
              // Something like `void foo(Iterator decltype(int) i)`
3657
1
              Tracker.skipToEnd();
3658
1
              Diag(Tok, diag::err_placeholder_expected_auto_or_decltype_auto)
3659
1
                << FixItHint::CreateReplacement(SourceRange(AutoLoc,
3660
1
                                                            Tok.getLocation()),
3661
1
                                                "auto");
3662
14
            } else {
3663
14
              Tracker.consumeClose();
3664
14
            }
3665
15
          }
3666
16
          ConsumedEnd = Tok.getLocation();
3667
16
          DS.setTypeofParensRange(Tracker.getRange());
3668
          // Even if something went wrong above, continue as if we've seen
3669
          // `decltype(auto)`.
3670
16
          isInvalid = DS.SetTypeSpecType(TST_decltype_auto, Loc, PrevSpec,
3671
16
                                         DiagID, TemplateId, Policy);
3672
185
        } else {
3673
185
          isInvalid = DS.SetTypeSpecType(TST_auto, AutoLoc, PrevSpec, DiagID,
3674
185
                                         TemplateId, Policy);
3675
185
        }
3676
201
        break;
3677
201
      }
3678
3679
813k
      if (TemplateId->Kind != TNK_Type_template &&
3680
813k
          
TemplateId->Kind != TNK_Undeclared_template101
) {
3681
        // This template-id does not refer to a type name, so we're
3682
        // done with the type-specifiers.
3683
12
        goto DoneWithDeclSpec;
3684
12
      }
3685
3686
      // If we're in a context where the template-id could be a
3687
      // constructor name or specialization, check whether this is a
3688
      // constructor declaration.
3689
813k
      if (getLangOpts().CPlusPlus && DSContext == DeclSpecContext::DSC_class &&
3690
813k
          
Actions.isCurrentClassName(*TemplateId->Name, getCurScope())114k
&&
3691
813k
          
isConstructorDeclarator(/*Unqualified=*/true)17.5k
)
3692
30
        goto DoneWithDeclSpec;
3693
3694
      // Turn the template-id annotation token into a type annotation
3695
      // token, then try again to parse it as a type-specifier.
3696
813k
      CXXScopeSpec SS;
3697
813k
      AnnotateTemplateIdTokenAsType(SS);
3698
813k
      continue;
3699
813k
    }
3700
3701
    // Attributes support.
3702
22.6M
    case tok::kw___attribute:
3703
22.6M
    case tok::kw___declspec:
3704
22.6M
      ParseAttributes(PAKM_GNU | PAKM_Declspec, DS.getAttributes(), LateAttrs);
3705
22.6M
      continue;
3706
3707
    // Microsoft single token adornments.
3708
23
    case tok::kw___forceinline: {
3709
23
      isInvalid = DS.setFunctionSpecForceInline(Loc, PrevSpec, DiagID);
3710
23
      IdentifierInfo *AttrName = Tok.getIdentifierInfo();
3711
23
      SourceLocation AttrNameLoc = Tok.getLocation();
3712
23
      DS.getAttributes().addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc,
3713
23
                                nullptr, 0, ParsedAttr::AS_Keyword);
3714
23
      break;
3715
22.6M
    }
3716
3717
128
    case tok::kw___unaligned:
3718
128
      isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID,
3719
128
                                 getLangOpts());
3720
128
      break;
3721
3722
2
    case tok::kw___sptr:
3723
2
    case tok::kw___uptr:
3724
2
    case tok::kw___ptr64:
3725
6
    case tok::kw___ptr32:
3726
7
    case tok::kw___w64:
3727
278
    case tok::kw___cdecl:
3728
409
    case tok::kw___stdcall:
3729
500
    case tok::kw___fastcall:
3730
535
    case tok::kw___thiscall:
3731
642
    case tok::kw___regcall:
3732
764
    case tok::kw___vectorcall:
3733
764
      ParseMicrosoftTypeAttributes(DS.getAttributes());
3734
764
      continue;
3735
3736
    // Borland single token adornments.
3737
14
    case tok::kw___pascal:
3738
14
      ParseBorlandTypeAttributes(DS.getAttributes());
3739
14
      continue;
3740
3741
    // OpenCL single token adornments.
3742
1.23k
    case tok::kw___kernel:
3743
1.23k
      ParseOpenCLKernelAttributes(DS.getAttributes());
3744
1.23k
      continue;
3745
3746
    // CUDA/HIP single token adornments.
3747
5
    case tok::kw___noinline__:
3748
5
      ParseCUDAFunctionAttributes(DS.getAttributes());
3749
5
      continue;
3750
3751
    // Nullability type specifiers.
3752
36.2k
    case tok::kw__Nonnull:
3753
351k
    case tok::kw__Nullable:
3754
351k
    case tok::kw__Nullable_result:
3755
372k
    case tok::kw__Null_unspecified:
3756
372k
      ParseNullabilityTypeSpecifiers(DS.getAttributes());
3757
372k
      continue;
3758
3759
    // Objective-C 'kindof' types.
3760
1.19k
    case tok::kw___kindof:
3761
1.19k
      DS.getAttributes().addNew(Tok.getIdentifierInfo(), Loc, nullptr, Loc,
3762
1.19k
                                nullptr, 0, ParsedAttr::AS_Keyword);
3763
1.19k
      (void)ConsumeToken();
3764
1.19k
      continue;
3765
3766
    // storage-class-specifier
3767
2.18M
    case tok::kw_typedef:
3768
2.18M
      isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_typedef, Loc,
3769
2.18M
                                         PrevSpec, DiagID, Policy);
3770
2.18M
      isStorageClass = true;
3771
2.18M
      break;
3772
2.07M
    case tok::kw_extern:
3773
2.07M
      if (DS.getThreadStorageClassSpec() == DeclSpec::TSCS___thread)
3774
2
        Diag(Tok, diag::ext_thread_before) << "extern";
3775
2.07M
      isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_extern, Loc,
3776
2.07M
                                         PrevSpec, DiagID, Policy);
3777
2.07M
      isStorageClass = true;
3778
2.07M
      break;
3779
66
    case tok::kw___private_extern__:
3780
66
      isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_private_extern,
3781
66
                                         Loc, PrevSpec, DiagID, Policy);
3782
66
      isStorageClass = true;
3783
66
      break;
3784
20.6M
    case tok::kw_static:
3785
20.6M
      if (DS.getThreadStorageClassSpec() == DeclSpec::TSCS___thread)
3786
11
        Diag(Tok, diag::ext_thread_before) << "static";
3787
20.6M
      isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc,
3788
20.6M
                                         PrevSpec, DiagID, Policy);
3789
20.6M
      isStorageClass = true;
3790
20.6M
      break;
3791
53.1k
    case tok::kw_auto:
3792
53.1k
      if (getLangOpts().CPlusPlus11) {
3793
53.0k
        if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
3794
35
          isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
3795
35
                                             PrevSpec, DiagID, Policy);
3796
35
          if (!isInvalid)
3797
31
            Diag(Tok, diag::ext_auto_storage_class)
3798
31
              << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
3799
35
        } else
3800
53.0k
          isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec,
3801
53.0k
                                         DiagID, Policy);
3802
53.0k
      } else
3803
147
        isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
3804
147
                                           PrevSpec, DiagID, Policy);
3805
53.1k
      isStorageClass = true;
3806
53.1k
      break;
3807
51
    case tok::kw___auto_type:
3808
51
      Diag(Tok, diag::ext_auto_type);
3809
51
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto_type, Loc, PrevSpec,
3810
51
                                     DiagID, Policy);
3811
51
      break;
3812
679
    case tok::kw_register:
3813
679
      isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_register, Loc,
3814
679
                                         PrevSpec, DiagID, Policy);
3815
679
      isStorageClass = true;
3816
679
      break;
3817
3.32k
    case tok::kw_mutable:
3818
3.32k
      isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_mutable, Loc,
3819
3.32k
                                         PrevSpec, DiagID, Policy);
3820
3.32k
      isStorageClass = true;
3821
3.32k
      break;
3822
343
    case tok::kw___thread:
3823
343
      isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS___thread, Loc,
3824
343
                                               PrevSpec, DiagID);
3825
343
      isStorageClass = true;
3826
343
      break;
3827
588
    case tok::kw_thread_local:
3828
588
      isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS_thread_local, Loc,
3829
588
                                               PrevSpec, DiagID);
3830
588
      isStorageClass = true;
3831
588
      break;
3832
101
    case tok::kw__Thread_local:
3833
101
      if (!getLangOpts().C11)
3834
80
        Diag(Tok, diag::ext_c11_feature) << Tok.getName();
3835
101
      isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS__Thread_local,
3836
101
                                               Loc, PrevSpec, DiagID);
3837
101
      isStorageClass = true;
3838
101
      break;
3839
3840
    // function-specifier
3841
20.7M
    case tok::kw_inline:
3842
20.7M
      isInvalid = DS.setFunctionSpecInline(Loc, PrevSpec, DiagID);
3843
20.7M
      break;
3844
56.0k
    case tok::kw_virtual:
3845
      // C++ for OpenCL does not allow virtual function qualifier, to avoid
3846
      // function pointers restricted in OpenCL v2.0 s6.9.a.
3847
56.0k
      if (getLangOpts().OpenCLCPlusPlus &&
3848
56.0k
          !getActions().getOpenCLOptions().isAvailableOption(
3849
6
              "__cl_clang_function_pointers", getLangOpts())) {
3850
3
        DiagID = diag::err_openclcxx_virtual_function;
3851
3
        PrevSpec = Tok.getIdentifierInfo()->getNameStart();
3852
3
        isInvalid = true;
3853
56.0k
      } else {
3854
56.0k
        isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
3855
56.0k
      }
3856
56.0k
      break;
3857
88.8k
    case tok::kw_explicit: {
3858
88.8k
      SourceLocation ExplicitLoc = Loc;
3859
88.8k
      SourceLocation CloseParenLoc;
3860
88.8k
      ExplicitSpecifier ExplicitSpec(nullptr, ExplicitSpecKind::ResolvedTrue);
3861
88.8k
      ConsumedEnd = ExplicitLoc;
3862
88.8k
      ConsumeToken(); // kw_explicit
3863
88.8k
      if (Tok.is(tok::l_paren)) {
3864
148
        if (getLangOpts().CPlusPlus20 || 
isExplicitBool() == TPResult::True44
) {
3865
142
          Diag(Tok.getLocation(), getLangOpts().CPlusPlus20
3866
142
                                      ? 
diag::warn_cxx17_compat_explicit_bool104
3867
142
                                      : 
diag::ext_explicit_bool38
);
3868
3869
142
          ExprResult ExplicitExpr(static_cast<Expr *>(nullptr));
3870
142
          BalancedDelimiterTracker Tracker(*this, tok::l_paren);
3871
142
          Tracker.consumeOpen();
3872
142
          ExplicitExpr = ParseConstantExpression();
3873
142
          ConsumedEnd = Tok.getLocation();
3874
142
          if (ExplicitExpr.isUsable()) {
3875
133
            CloseParenLoc = Tok.getLocation();
3876
133
            Tracker.consumeClose();
3877
133
            ExplicitSpec =
3878
133
                Actions.ActOnExplicitBoolSpecifier(ExplicitExpr.get());
3879
133
          } else
3880
9
            Tracker.skipToEnd();
3881
142
        } else {
3882
6
          Diag(Tok.getLocation(), diag::warn_cxx20_compat_explicit_bool);
3883
6
        }
3884
148
      }
3885
88.8k
      isInvalid = DS.setFunctionSpecExplicit(ExplicitLoc, PrevSpec, DiagID,
3886
88.8k
                                             ExplicitSpec, CloseParenLoc);
3887
88.8k
      break;
3888
351k
    }
3889
78
    case tok::kw__Noreturn:
3890
78
      if (!getLangOpts().C11)
3891
40
        Diag(Tok, diag::ext_c11_feature) << Tok.getName();
3892
78
      isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID);
3893
78
      break;
3894
3895
    // alignment-specifier
3896
1.18k
    case tok::kw__Alignas:
3897
1.18k
      if (!getLangOpts().C11)
3898
1.14k
        Diag(Tok, diag::ext_c11_feature) << Tok.getName();
3899
1.18k
      ParseAlignmentSpecifier(DS.getAttributes());
3900
1.18k
      continue;
3901
3902
    // friend
3903
77.6k
    case tok::kw_friend:
3904
77.6k
      if (DSContext == DeclSpecContext::DSC_class)
3905
77.6k
        isInvalid = DS.SetFriendSpec(Loc, PrevSpec, DiagID);
3906
15
      else {
3907
15
        PrevSpec = ""; // not actually used by the diagnostic
3908
15
        DiagID = diag::err_friend_invalid_in_context;
3909
15
        isInvalid = true;
3910
15
      }
3911
77.6k
      break;
3912
3913
    // Modules
3914
52
    case tok::kw___module_private__:
3915
52
      isInvalid = DS.setModulePrivateSpec(Loc, PrevSpec, DiagID);
3916
52
      break;
3917
3918
    // constexpr, consteval, constinit specifiers
3919
395k
    case tok::kw_constexpr:
3920
395k
      isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc,
3921
395k
                                      PrevSpec, DiagID);
3922
395k
      break;
3923
197
    case tok::kw_consteval:
3924
197
      isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Consteval, Loc,
3925
197
                                      PrevSpec, DiagID);
3926
197
      break;
3927
85
    case tok::kw_constinit:
3928
85
      isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constinit, Loc,
3929
85
                                      PrevSpec, DiagID);
3930
85
      break;
3931
3932
    // type-specifier
3933
251k
    case tok::kw_short:
3934
251k
      isInvalid = DS.SetTypeSpecWidth(TypeSpecifierWidth::Short, Loc, PrevSpec,
3935
251k
                                      DiagID, Policy);
3936
251k
      break;
3937
891k
    case tok::kw_long:
3938
891k
      if (DS.getTypeSpecWidth() != TypeSpecifierWidth::Long)
3939
693k
        isInvalid = DS.SetTypeSpecWidth(TypeSpecifierWidth::Long, Loc, PrevSpec,
3940
693k
                                        DiagID, Policy);
3941
197k
      else
3942
197k
        isInvalid = DS.SetTypeSpecWidth(TypeSpecifierWidth::LongLong, Loc,
3943
197k
                                        PrevSpec, DiagID, Policy);
3944
891k
      break;
3945
3.20k
    case tok::kw___int64:
3946
3.20k
      isInvalid = DS.SetTypeSpecWidth(TypeSpecifierWidth::LongLong, Loc,
3947
3.20k
                                      PrevSpec, DiagID, Policy);
3948
3.20k
      break;
3949
70.6k
    case tok::kw_signed:
3950
70.6k
      isInvalid =
3951
70.6k
          DS.SetTypeSpecSign(TypeSpecifierSign::Signed, Loc, PrevSpec, DiagID);
3952
70.6k
      break;
3953
727k
    case tok::kw_unsigned:
3954
727k
      isInvalid = DS.SetTypeSpecSign(TypeSpecifierSign::Unsigned, Loc, PrevSpec,
3955
727k
                                     DiagID);
3956
727k
      break;
3957
8.31k
    case tok::kw__Complex:
3958
8.31k
      if (!getLangOpts().C99)
3959
2.45k
        Diag(Tok, diag::ext_c99_feature) << Tok.getName();
3960
8.31k
      isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec,
3961
8.31k
                                        DiagID);
3962
8.31k
      break;
3963
10
    case tok::kw__Imaginary:
3964
10
      if (!getLangOpts().C99)
3965
3
        Diag(Tok, diag::ext_c99_feature) << Tok.getName();
3966
10
      isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec,
3967
10
                                        DiagID);
3968
10
      break;
3969
3.61M
    case tok::kw_void:
3970
3.61M
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec,
3971
3.61M
                                     DiagID, Policy);
3972
3.61M
      break;
3973
1.01M
    case tok::kw_char:
3974
1.01M
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec,
3975
1.01M
                                     DiagID, Policy);
3976
1.01M
      break;
3977
2.30M
    case tok::kw_int:
3978
2.30M
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec,
3979
2.30M
                                     DiagID, Policy);
3980
2.30M
      break;
3981
0
    case tok::kw__ExtInt:
3982
1.04k
    case tok::kw__BitInt: {
3983
1.04k
      DiagnoseBitIntUse(Tok);
3984
1.04k
      ExprResult ER = ParseExtIntegerArgument();
3985
1.04k
      if (ER.isInvalid())
3986
3
        continue;
3987
1.04k
      isInvalid = DS.SetBitIntType(Loc, ER.get(), PrevSpec, DiagID, Policy);
3988
1.04k
      ConsumedEnd = PrevTokLocation;
3989
1.04k
      break;
3990
1.04k
    }
3991
906
    case tok::kw___int128:
3992
906
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec,
3993
906
                                     DiagID, Policy);
3994
906
      break;
3995
20.0k
    case tok::kw_half:
3996
20.0k
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec,
3997
20.0k
                                     DiagID, Policy);
3998
20.0k
      break;
3999
724
    case tok::kw___bf16:
4000
724
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_BFloat16, Loc, PrevSpec,
4001
724
                                     DiagID, Policy);
4002
724
      break;
4003
342k
    case tok::kw_float:
4004
342k
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec,
4005
342k
                                     DiagID, Policy);
4006
342k
      break;
4007
524k
    case tok::kw_double:
4008
524k
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec,
4009
524k
                                     DiagID, Policy);
4010
524k
      break;
4011
1.40k
    case tok::kw__Float16:
4012
1.40k
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float16, Loc, PrevSpec,
4013
1.40k
                                     DiagID, Policy);
4014
1.40k
      break;
4015
1.01k
    case tok::kw__Accum:
4016
1.01k
      if (!getLangOpts().FixedPoint) {
4017
9
        SetupFixedPointError(getLangOpts(), PrevSpec, DiagID, isInvalid);
4018
1.00k
      } else {
4019
1.00k
        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_accum, Loc, PrevSpec,
4020
1.00k
                                       DiagID, Policy);
4021
1.00k
      }
4022
1.01k
      break;
4023
554
    case tok::kw__Fract:
4024
554
      if (!getLangOpts().FixedPoint) {
4025
0
        SetupFixedPointError(getLangOpts(), PrevSpec, DiagID, isInvalid);
4026
554
      } else {
4027
554
        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_fract, Loc, PrevSpec,
4028
554
                                       DiagID, Policy);
4029
554
      }
4030
554
      break;
4031
561
    case tok::kw__Sat:
4032
561
      if (!getLangOpts().FixedPoint) {
4033
0
        SetupFixedPointError(getLangOpts(), PrevSpec, DiagID, isInvalid);
4034
561
      } else {
4035
561
        isInvalid = DS.SetTypeSpecSat(Loc, PrevSpec, DiagID);
4036
561
      }
4037
561
      break;
4038
453
    case tok::kw___float128:
4039
453
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec,
4040
453
                                     DiagID, Policy);
4041
453
      break;
4042
108
    case tok::kw___ibm128:
4043
108
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_ibm128, Loc, PrevSpec,
4044
108
                                     DiagID, Policy);
4045
108
      break;
4046
141k
    case tok::kw_wchar_t:
4047
141k
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec,
4048
141k
                                     DiagID, Policy);
4049
141k
      break;
4050
181
    case tok::kw_char8_t:
4051
181
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char8, Loc, PrevSpec,
4052
181
                                     DiagID, Policy);
4053
181
      break;
4054
8.00k
    case tok::kw_char16_t:
4055
8.00k
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec,
4056
8.00k
                                     DiagID, Policy);
4057
8.00k
      break;
4058
8.01k
    case tok::kw_char32_t:
4059
8.01k
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec,
4060
8.01k
                                     DiagID, Policy);
4061
8.01k
      break;
4062
714k
    case tok::kw_bool:
4063
836k
    case tok::kw__Bool:
4064
836k
      if (Tok.is(tok::kw__Bool) && 
!getLangOpts().C99122k
)
4065
2
        Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4066
4067
836k
      if (Tok.is(tok::kw_bool) &&
4068
836k
          
DS.getTypeSpecType() != DeclSpec::TST_unspecified714k
&&
4069
836k
          
DS.getStorageClassSpec() == DeclSpec::SCS_typedef3
) {
4070
3
        PrevSpec = ""; // Not used by the diagnostic.
4071
3
        DiagID = diag::err_bool_redeclaration;
4072
        // For better error recovery.
4073
3
        Tok.setKind(tok::identifier);
4074
3
        isInvalid = true;
4075
836k
      } else {
4076
836k
        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec,
4077
836k
                                       DiagID, Policy);
4078
836k
      }
4079
836k
      break;
4080
6
    case tok::kw__Decimal32:
4081
6
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec,
4082
6
                                     DiagID, Policy);
4083
6
      break;
4084
0
    case tok::kw__Decimal64:
4085
0
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec,
4086
0
                                     DiagID, Policy);
4087
0
      break;
4088
2
    case tok::kw__Decimal128:
4089
2
      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec,
4090
2
                                     DiagID, Policy);
4091
2
      break;
4092
36.3k
    case tok::kw___vector:
4093
36.3k
      isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID, Policy);
4094
36.3k
      break;
4095
24
    case tok::kw___pixel:
4096
24
      isInvalid = DS.SetTypeAltiVecPixel(true, Loc, PrevSpec, DiagID, Policy);
4097
24
      break;
4098
203
    case tok::kw___bool:
4099
203
      isInvalid = DS.SetTypeAltiVecBool(true, Loc, PrevSpec, DiagID, Policy);
4100
203
      break;
4101
260
    case tok::kw_pipe:
4102
260
      if (!getLangOpts().OpenCL ||
4103
260
          getLangOpts().getOpenCLCompatibleVersion() < 200) {
4104
        // OpenCL 2.0 and later define this keyword. OpenCL 1.2 and earlier
4105
        // should support the "pipe" word as identifier.
4106
1
        Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
4107
1
        Tok.setKind(tok::identifier);
4108
1
        goto DoneWithDeclSpec;
4109
259
      } else if (!getLangOpts().OpenCLPipes) {
4110
4
        DiagID = diag::err_opencl_unknown_type_specifier;
4111
4
        PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4112
4
        isInvalid = true;
4113
4
      } else
4114
255
        isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy);
4115
259
      break;
4116
// We only need to enumerate each image type once.
4117
259
#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
4118
259
#define IMAGE_WRITE_TYPE(Type, Id, Ext)
4119
259
#define IMAGE_READ_TYPE(ImgType, Id, Ext) \
4120
8.09k
    case tok::kw_##ImgType##_t: \
4121
8.09k
      if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
4122
8.09k
        
goto DoneWithDeclSpec4
; \
4123
8.09k
      break;
4124
259
#include "clang/Basic/OpenCLImageTypes.def"
4125
1.06k
    case tok::kw___unknown_anytype:
4126
62
      isInvalid = DS.SetTypeSpecType(TST_unknown_anytype, Loc,
4127
62
                                     PrevSpec, DiagID, Policy);
4128
62
      break;
4129
4130
    // class-specifier:
4131
191k
    case tok::kw_class:
4132
1.90M
    case tok::kw_struct:
4133
1.90M
    case tok::kw___interface:
4134
1.95M
    case tok::kw_union: {
4135
1.95M
      tok::TokenKind Kind = Tok.getKind();
4136
1.95M
      ConsumeToken();
4137
4138
      // These are attributes following class specifiers.
4139
      // To produce better diagnostic, we parse them when
4140
      // parsing class specifier.
4141
1.95M
      ParsedAttributes Attributes(AttrFactory);
4142
1.95M
      ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
4143
1.95M
                          EnteringContext, DSContext, Attributes);
4144
4145
      // If there are attributes following class specifier,
4146
      // take them over and handle them here.
4147
1.95M
      if (!Attributes.empty()) {
4148
0
        AttrsLastTime = true;
4149
0
        attrs.takeAllFrom(Attributes);
4150
0
      }
4151
1.95M
      continue;
4152
1.90M
    }
4153
4154
    // enum-specifier:
4155
876k
    case tok::kw_enum:
4156
876k
      ConsumeToken();
4157
876k
      ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
4158
876k
      continue;
4159
4160
    // cv-qualifier:
4161
4.92M
    case tok::kw_const:
4162
4.92M
      isInvalid = DS.SetTypeQual(DeclSpec::TQ_const, Loc, PrevSpec, DiagID,
4163
4.92M
                                 getLangOpts());
4164
4.92M
      break;
4165
105k
    case tok::kw_volatile:
4166
105k
      isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID,
4167
105k
                                 getLangOpts());
4168
105k
      break;
4169
291
    case tok::kw_restrict:
4170
291
      isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID,
4171
291
                                 getLangOpts());
4172
291
      break;
4173
4174
    // C++ typename-specifier:
4175
495k
    case tok::kw_typename:
4176
495k
      if (TryAnnotateTypeOrScopeToken()) {
4177
4
        DS.SetTypeSpecError();
4178
4
        goto DoneWithDeclSpec;
4179
4
      }
4180
495k
      if (!Tok.is(tok::kw_typename))
4181
495k
        continue;
4182
0
      break;
4183
4184
    // GNU typeof support.
4185
2.95k
    case tok::kw_typeof:
4186
2.95k
      ParseTypeofSpecifier(DS);
4187
2.95k
      continue;
4188
4189
46.0k
    case tok::annot_decltype:
4190
46.0k
      ParseDecltypeSpecifier(DS);
4191
46.0k
      continue;
4192
4193
1
    case tok::annot_pragma_pack:
4194
1
      HandlePragmaPack();
4195
1
      continue;
4196
4197
0
    case tok::annot_pragma_ms_pragma:
4198
0
      HandlePragmaMSPragma();
4199
0
      continue;
4200
4201
0
    case tok::annot_pragma_ms_vtordisp:
4202
0
      HandlePragmaMSVtorDisp();
4203
0
      continue;
4204
4205
0
    case tok::annot_pragma_ms_pointers_to_members:
4206
0
      HandlePragmaMSPointersToMembers();
4207
0
      continue;
4208
4209
551
    case tok::kw___underlying_type:
4210
551
      ParseUnderlyingTypeSpecifier(DS);
4211
551
      continue;
4212
4213
3.12k
    case tok::kw__Atomic:
4214
      // C11 6.7.2.4/4:
4215
      //   If the _Atomic keyword is immediately followed by a left parenthesis,
4216
      //   it is interpreted as a type specifier (with a type name), not as a
4217
      //   type qualifier.
4218
3.12k
      if (!getLangOpts().C11)
4219
1.50k
        Diag(Tok, diag::ext_c11_feature) << Tok.getName();
4220
4221
3.12k
      if (NextToken().is(tok::l_paren)) {
4222
2.96k
        ParseAtomicSpecifier(DS);
4223
2.96k
        continue;
4224
2.96k
      }
4225
156
      isInvalid = DS.SetTypeQual(DeclSpec::TQ_atomic, Loc, PrevSpec, DiagID,
4226
156
                                 getLangOpts());
4227
156
      break;
4228
4229
    // OpenCL address space qualifiers:
4230
1.91k
    case tok::kw___generic:
4231
      // generic address space is introduced only in OpenCL v2.0
4232
      // see OpenCL C Spec v2.0 s6.5.5
4233
      // OpenCL v3.0 introduces __opencl_c_generic_address_space
4234
      // feature macro to indicate if generic address space is supported
4235
1.91k
      if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
4236
26
        DiagID = diag::err_opencl_unknown_type_specifier;
4237
26
        PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4238
26
        isInvalid = true;
4239
26
        break;
4240
26
      }
4241
1.91k
      
LLVM_FALLTHROUGH1.89k
;1.89k
4242
1.93k
    case tok::kw_private:
4243
      // It's fine (but redundant) to check this for __generic on the
4244
      // fallthrough path; we only form the __generic token in OpenCL mode.
4245
1.93k
      if (!getLangOpts().OpenCL)
4246
3
        goto DoneWithDeclSpec;
4247
1.93k
      
LLVM_FALLTHROUGH1.93k
;1.93k
4248
5.57k
    case tok::kw___private:
4249
19.6k
    case tok::kw___global:
4250
31.7k
    case tok::kw___local:
4251
33.9k
    case tok::kw___constant:
4252
    // OpenCL access qualifiers:
4253
37.7k
    case tok::kw___read_only:
4254
39.9k
    case tok::kw___write_only:
4255
42.1k
    case tok::kw___read_write:
4256
42.1k
      ParseOpenCLQualifiers(DS.getAttributes());
4257
42.1k
      break;
4258
4259
19
    case tok::less:
4260
      // GCC ObjC supports types like "<SomeProtocol>" as a synonym for
4261
      // "id<SomeProtocol>".  This is hopelessly old fashioned and dangerous,
4262
      // but we support it.
4263
19
      if (DS.hasTypeSpecifier() || 
!getLangOpts().ObjC9
)
4264
12
        goto DoneWithDeclSpec;
4265
4266
7
      SourceLocation StartLoc = Tok.getLocation();
4267
7
      SourceLocation EndLoc;
4268
7
      TypeResult Type = parseObjCProtocolQualifierType(EndLoc);
4269
7
      if (Type.isUsable()) {
4270
7
        if (DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, StartLoc,
4271
7
                               PrevSpec, DiagID, Type.get(),
4272
7
                               Actions.getASTContext().getPrintingPolicy()))
4273
0
          Diag(StartLoc, DiagID) << PrevSpec;
4274
4275
7
        DS.SetRangeEnd(EndLoc);
4276
7
      } else {
4277
0
        DS.SetTypeSpecError();
4278
0
      }
4279
4280
      // Need to support trailing type qualifiers (e.g. "id<p> const").
4281
      // If a type specifier follows, it will be diagnosed elsewhere.
4282
7
      continue;
4283
302M
    }
4284
4285
62.2M
    DS.SetRangeEnd(ConsumedEnd.isValid() ? 
ConsumedEnd89.9k
:
Tok.getLocation()62.1M
);
4286
4287
    // If the specifier wasn't legal, issue a diagnostic.
4288
62.2M
    if (isInvalid) {
4289
232
      assert(PrevSpec && "Method did not return previous specifier!");
4290
0
      assert(DiagID);
4291
4292
232
      if (DiagID == diag::ext_duplicate_declspec ||
4293
232
          DiagID == diag::ext_warn_duplicate_declspec ||
4294
232
          
DiagID == diag::err_duplicate_declspec188
)
4295
46
        Diag(Loc, DiagID) << PrevSpec
4296
46
                          << FixItHint::CreateRemoval(
4297
46
                                 SourceRange(Loc, DS.getEndLoc()));
4298
186
      else if (DiagID == diag::err_opencl_unknown_type_specifier) {
4299
45
        Diag(Loc, DiagID) << getLangOpts().getOpenCLVersionString() << PrevSpec
4300
45
                          << isStorageClass;
4301
45
      } else
4302
141
        Diag(Loc, DiagID) << PrevSpec;
4303
232
    }
4304
4305
62.2M
    if (DiagID != diag::err_bool_redeclaration && 
ConsumedEnd.isInvalid()62.2M
)
4306
      // After an error the next token can be an annotation token.
4307
62.1M
      ConsumeAnyToken();
4308
4309
62.2M
    AttrsLastTime = false;
4310
62.2M
  }
4311
112M
}
4312
4313
/// ParseStructDeclaration - Parse a struct declaration without the terminating
4314
/// semicolon.
4315
///
4316
/// Note that a struct declaration refers to a declaration in a struct,
4317
/// not to the declaration of a struct.
4318
///
4319
///       struct-declaration:
4320
/// [C2x]   attributes-specifier-seq[opt]
4321
///           specifier-qualifier-list struct-declarator-list
4322
/// [GNU]   __extension__ struct-declaration
4323
/// [GNU]   specifier-qualifier-list
4324
///       struct-declarator-list:
4325
///         struct-declarator
4326
///         struct-declarator-list ',' struct-declarator
4327
/// [GNU]   struct-declarator-list ',' attributes[opt] struct-declarator
4328
///       struct-declarator:
4329
///         declarator
4330
/// [GNU]   declarator attributes[opt]
4331
///         declarator[opt] ':' constant-expression
4332
/// [GNU]   declarator[opt] ':' constant-expression attributes[opt]
4333
///
4334
void Parser::ParseStructDeclaration(
4335
    ParsingDeclSpec &DS,
4336
2.31M
    llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback) {
4337
4338
2.31M
  if (Tok.is(tok::kw___extension__)) {
4339
    // __extension__ silences extension warnings in the subexpression.
4340
4
    ExtensionRAIIObject O(Diags);  // Use RAII to do this.
4341
4
    ConsumeToken();
4342
4
    return ParseStructDeclaration(DS, FieldsCallback);
4343
4
  }
4344
4345
  // Parse leading attributes.
4346
2.31M
  ParsedAttributes Attrs(AttrFactory);
4347
2.31M
  MaybeParseCXX11Attributes(Attrs);
4348
4349
  // Parse the common specifier-qualifiers-list piece.
4350
2.31M
  ParseSpecifierQualifierList(DS);
4351
4352
  // If there are no declarators, this is a free-standing declaration
4353
  // specifier. Let the actions module cope with it.
4354
2.31M
  if (Tok.is(tok::semi)) {
4355
    // C2x 6.7.2.1p9 : "The optional attribute specifier sequence in a
4356
    // member declaration appertains to each of the members declared by the
4357
    // member declarator list; it shall not appear if the optional member
4358
    // declarator list is omitted."
4359
339
    ProhibitAttributes(Attrs);
4360
339
    RecordDecl *AnonRecord = nullptr;
4361
339
    Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
4362
339
        getCurScope(), AS_none, DS, ParsedAttributesView::none(), AnonRecord);
4363
339
    assert(!AnonRecord && "Did not expect anonymous struct or union here");
4364
0
    DS.complete(TheDecl);
4365
339
    return;
4366
339
  }
4367
4368
  // Read struct-declarators until we find the semicolon.
4369
2.31M
  bool FirstDeclarator = true;
4370
2.31M
  SourceLocation CommaLoc;
4371
2.32M
  while (true) {
4372
2.32M
    ParsingFieldDeclarator DeclaratorInfo(*this, DS, Attrs);
4373
2.32M
    DeclaratorInfo.D.setCommaLoc(CommaLoc);
4374
4375
    // Attributes are only allowed here on successive declarators.
4376
2.32M
    if (!FirstDeclarator) {
4377
      // However, this does not apply for [[]] attributes (which could show up
4378
      // before or after the __attribute__ attributes).
4379
12.6k
      DiagnoseAndSkipCXX11Attributes();
4380
12.6k
      MaybeParseGNUAttributes(DeclaratorInfo.D);
4381
12.6k
      DiagnoseAndSkipCXX11Attributes();
4382
12.6k
    }
4383
4384
    /// struct-declarator: declarator
4385
    /// struct-declarator: declarator[opt] ':' constant-expression
4386
2.32M
    if (Tok.isNot(tok::colon)) {
4387
      // Don't parse FOO:BAR as if it were a typo for FOO::BAR.
4388
2.32M
      ColonProtectionRAIIObject X(*this);
4389
2.32M
      ParseDeclarator(DeclaratorInfo.D);
4390
2.32M
    } else
4391
1.71k
      DeclaratorInfo.D.SetIdentifier(nullptr, Tok.getLocation());
4392
4393
2.32M
    if (TryConsumeToken(tok::colon)) {
4394
30.3k
      ExprResult Res(ParseConstantExpression());
4395
30.3k
      if (Res.isInvalid())
4396
1
        SkipUntil(tok::semi, StopBeforeMatch);
4397
30.3k
      else
4398
30.3k
        DeclaratorInfo.BitfieldSize = Res.get();
4399
30.3k
    }
4400
4401
    // If attributes exist after the declarator, parse them.
4402
2.32M
    MaybeParseGNUAttributes(DeclaratorInfo.D);
4403
4404
    // We're done with this declarator;  invoke the callback.
4405
2.32M
    FieldsCallback(DeclaratorInfo);
4406
4407
    // If we don't have a comma, it is either the end of the list (a ';')
4408
    // or an error, bail out.
4409
2.32M
    if (!TryConsumeToken(tok::comma, CommaLoc))
4410
2.31M
      return;
4411
4412
12.6k
    FirstDeclarator = false;
4413
12.6k
  }
4414
2.31M
}
4415
4416
/// ParseStructUnionBody
4417
///       struct-contents:
4418
///         struct-declaration-list
4419
/// [EXT]   empty
4420
/// [GNU]   "struct-declaration-list" without terminating ';'
4421
///       struct-declaration-list:
4422
///         struct-declaration
4423
///         struct-declaration-list struct-declaration
4424
/// [OBC]   '@' 'defs' '(' class-name ')'
4425
///
4426
void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
4427
402k
                                  DeclSpec::TST TagType, RecordDecl *TagDecl) {
4428
402k
  PrettyDeclStackTraceEntry CrashInfo(Actions.Context, TagDecl, RecordLoc,
4429
402k
                                      "parsing struct/union body");
4430
402k
  assert(!getLangOpts().CPlusPlus && "C++ declarations not supported");
4431
4432
0
  BalancedDelimiterTracker T(*this, tok::l_brace);
4433
402k
  if (T.consumeOpen())
4434
0
    return;
4435
4436
402k
  ParseScope StructScope(this, Scope::ClassScope|Scope::DeclScope);
4437
402k
  Actions.ActOnTagStartDefinition(getCurScope(), TagDecl);
4438
4439
  // While we still have something to read, read the declarations in the struct.
4440
2.22M
  while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
4441
2.22M
         
Tok.isNot(tok::eof)1.82M
) {
4442
    // Each iteration of this loop reads one struct-declaration.
4443
4444
    // Check for extraneous top-level semicolon.
4445
1.82M
    if (Tok.is(tok::semi)) {
4446
5
      ConsumeExtraSemi(InsideStruct, TagType);
4447
5
      continue;
4448
5
    }
4449
4450
    // Parse _Static_assert declaration.
4451
1.82M
    if (Tok.isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
4452
44
      SourceLocation DeclEnd;
4453
44
      ParseStaticAssertDeclaration(DeclEnd);
4454
44
      continue;
4455
44
    }
4456
4457
1.82M
    if (Tok.is(tok::annot_pragma_pack)) {
4458
6
      HandlePragmaPack();
4459
6
      continue;
4460
6
    }
4461
4462
1.82M
    if (Tok.is(tok::annot_pragma_align)) {
4463
2
      HandlePragmaAlign();
4464
2
      continue;
4465
2
    }
4466
4467
1.82M
    if (Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
4468
      // Result can be ignored, because it must be always empty.
4469
21
      AccessSpecifier AS = AS_none;
4470
21
      ParsedAttributes Attrs(AttrFactory);
4471
21
      (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
4472
21
      continue;
4473
21
    }
4474
4475
1.82M
    if (tok::isPragmaAnnotation(Tok.getKind())) {
4476
2
      Diag(Tok.getLocation(), diag::err_pragma_misplaced_in_decl)
4477
2
          << DeclSpec::getSpecifierName(
4478
2
                 TagType, Actions.getASTContext().getPrintingPolicy());
4479
2
      ConsumeAnnotationToken();
4480
2
      continue;
4481
2
    }
4482
4483
1.82M
    if (!Tok.is(tok::at)) {
4484
1.83M
      auto CFieldCallback = [&](ParsingFieldDeclarator &FD) {
4485
        // Install the declarator into the current TagDecl.
4486
1.83M
        Decl *Field =
4487
1.83M
            Actions.ActOnField(getCurScope(), TagDecl,
4488
1.83M
                               FD.D.getDeclSpec().getSourceRange().getBegin(),
4489
1.83M
                               FD.D, FD.BitfieldSize);
4490
1.83M
        FD.complete(Field);
4491
1.83M
      };
4492
4493
      // Parse all the comma separated declarators.
4494
1.82M
      ParsingDeclSpec DS(*this);
4495
1.82M
      ParseStructDeclaration(DS, CFieldCallback);
4496
1.82M
    } else { // Handle @defs
4497
8
      ConsumeToken();
4498
8
      if (!Tok.isObjCAtKeyword(tok::objc_defs)) {
4499
4
        Diag(Tok, diag::err_unexpected_at);
4500
4
        SkipUntil(tok::semi);
4501
4
        continue;
4502
4
      }
4503
4
      ConsumeToken();
4504
4
      ExpectAndConsume(tok::l_paren);
4505
4
      if (!Tok.is(tok::identifier)) {
4506
0
        Diag(Tok, diag::err_expected) << tok::identifier;
4507
0
        SkipUntil(tok::semi);
4508
0
        continue;
4509
0
      }
4510
4
      SmallVector<Decl *, 16> Fields;
4511
4
      Actions.ActOnDefs(getCurScope(), TagDecl, Tok.getLocation(),
4512
4
                        Tok.getIdentifierInfo(), Fields);
4513
4
      ConsumeToken();
4514
4
      ExpectAndConsume(tok::r_paren);
4515
4
    }
4516
4517
1.82M
    if (TryConsumeToken(tok::semi))
4518
1.82M
      continue;
4519
4520
22
    if (Tok.is(tok::r_brace)) {
4521
10
      ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
4522
10
      break;
4523
10
    }
4524
4525
12
    ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
4526
    // Skip to end of block or statement to avoid ext-warning on extra ';'.
4527
12
    SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
4528
    // If we stopped at a ';', eat it.
4529
12
    TryConsumeToken(tok::semi);
4530
12
  }
4531
4532
402k
  T.consumeClose();
4533
4534
402k
  ParsedAttributes attrs(AttrFactory);
4535
  // If attributes exist after struct contents, parse them.
4536
402k
  MaybeParseGNUAttributes(attrs);
4537
4538
402k
  SmallVector<Decl *, 32> FieldDecls(TagDecl->fields());
4539
4540
402k
  Actions.ActOnFields(getCurScope(), RecordLoc, TagDecl, FieldDecls,
4541
402k
                      T.getOpenLocation(), T.getCloseLocation(), attrs);
4542
402k
  StructScope.Exit();
4543
402k
  Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, T.getRange());
4544
402k
}
4545
4546
/// ParseEnumSpecifier
4547
///       enum-specifier: [C99 6.7.2.2]
4548
///         'enum' identifier[opt] '{' enumerator-list '}'
4549
///[C99/C++]'enum' identifier[opt] '{' enumerator-list ',' '}'
4550
/// [GNU]   'enum' attributes[opt] identifier[opt] '{' enumerator-list ',' [opt]
4551
///                                                 '}' attributes[opt]
4552
/// [MS]    'enum' __declspec[opt] identifier[opt] '{' enumerator-list ',' [opt]
4553
///                                                 '}'
4554
///         'enum' identifier
4555
/// [GNU]   'enum' attributes[opt] identifier
4556
///
4557
/// [C++11] enum-head '{' enumerator-list[opt] '}'
4558
/// [C++11] enum-head '{' enumerator-list ','  '}'
4559
///
4560
///       enum-head: [C++11]
4561
///         enum-key attribute-specifier-seq[opt] identifier[opt] enum-base[opt]
4562
///         enum-key attribute-specifier-seq[opt] nested-name-specifier
4563
///             identifier enum-base[opt]
4564
///
4565
///       enum-key: [C++11]
4566
///         'enum'
4567
///         'enum' 'class'
4568
///         'enum' 'struct'
4569
///
4570
///       enum-base: [C++11]
4571
///         ':' type-specifier-seq
4572
///
4573
/// [C++] elaborated-type-specifier:
4574
/// [C++]   'enum' nested-name-specifier[opt] identifier
4575
///
4576
void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
4577
                                const ParsedTemplateInfo &TemplateInfo,
4578
876k
                                AccessSpecifier AS, DeclSpecContext DSC) {
4579
  // Parse the tag portion of this.
4580
876k
  if (Tok.is(tok::code_completion)) {
4581
    // Code completion for an enum name.
4582
2
    cutOffParsing();
4583
2
    Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
4584
2
    return;
4585
2
  }
4586
4587
  // If attributes exist after tag, parse them.
4588
876k
  ParsedAttributes attrs(AttrFactory);
4589
876k
  MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
4590
4591
876k
  SourceLocation ScopedEnumKWLoc;
4592
876k
  bool IsScopedUsingClassTag = false;
4593
4594
  // In C++11, recognize 'enum class' and 'enum struct'.
4595
876k
  if (Tok.isOneOf(tok::kw_class, tok::kw_struct) && 
getLangOpts().CPlusPlus2.72k
) {
4596
2.72k
    Diag(Tok, getLangOpts().CPlusPlus11 ? 
diag::warn_cxx98_compat_scoped_enum2.65k
4597
2.72k
                                        : 
diag::ext_scoped_enum70
);
4598
2.72k
    IsScopedUsingClassTag = Tok.is(tok::kw_class);
4599
2.72k
    ScopedEnumKWLoc = ConsumeToken();
4600
4601
    // Attributes are not allowed between these keywords.  Diagnose,
4602
    // but then just treat them like they appeared in the right place.
4603
2.72k
    ProhibitAttributes(attrs);
4604
4605
    // They are allowed afterwards, though.
4606
2.72k
    MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
4607
2.72k
  }
4608
4609
  // C++11 [temp.explicit]p12:
4610
  //   The usual access controls do not apply to names used to specify
4611
  //   explicit instantiations.
4612
  // We extend this to also cover explicit specializations.  Note that
4613
  // we don't suppress if this turns out to be an elaborated type
4614
  // specifier.
4615
876k
  bool shouldDelayDiagsInTag =
4616
876k
    (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
4617
876k
     
TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization876k
);
4618
876k
  SuppressAccessChecks diagsFromTag(*this, shouldDelayDiagsInTag);
4619
4620
  // Determine whether this declaration is permitted to have an enum-base.
4621
876k
  AllowDefiningTypeSpec AllowEnumSpecifier =
4622
876k
      isDefiningTypeSpecifierContext(DSC, getLangOpts().CPlusPlus);
4623
876k
  bool CanBeOpaqueEnumDeclaration =
4624
876k
      DS.isEmpty() && 
isOpaqueEnumDeclarationContext(DSC)793k
;
4625
876k
  bool CanHaveEnumBase = (getLangOpts().CPlusPlus11 || 
getLangOpts().ObjC643k
||
4626
876k
                          
getLangOpts().MicrosoftExt189k
) &&
4627
876k
                         
(687k
AllowEnumSpecifier == AllowDefiningTypeSpec::Yes687k
||
4628
687k
                          
CanBeOpaqueEnumDeclaration94
);
4629
4630
876k
  CXXScopeSpec &SS = DS.getTypeSpecScope();
4631
876k
  if (getLangOpts().CPlusPlus) {
4632
    // "enum foo : bar;" is not a potential typo for "enum foo::bar;".
4633
233k
    ColonProtectionRAIIObject X(*this);
4634
4635
233k
    CXXScopeSpec Spec;
4636
233k
    if (ParseOptionalCXXScopeSpecifier(Spec, /*ObjectType=*/nullptr,
4637
233k
                                       /*ObjectHasErrors=*/false,
4638
233k
                                       /*EnteringContext=*/true))
4639
0
      return;
4640
4641
233k
    if (Spec.isSet() && 
Tok.isNot(tok::identifier)231
) {
4642
8
      Diag(Tok, diag::err_expected) << tok::identifier;
4643
8
      if (Tok.isNot(tok::l_brace)) {
4644
        // Has no name and is not a definition.
4645
        // Skip the rest of this declarator, up until the comma or semicolon.
4646
8
        SkipUntil(tok::comma, StopAtSemi);
4647
8
        return;
4648
8
      }
4649
8
    }
4650
4651
233k
    SS = Spec;
4652
233k
  }
4653
4654
  // Must have either 'enum name' or 'enum {...}' or (rarely) 'enum : T { ... }'.
4655
876k
  if (Tok.isNot(tok::identifier) && 
Tok.isNot(tok::l_brace)382k
&&
4656
876k
      
Tok.isNot(tok::colon)30.4k
) {
4657
4
    Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
4658
4659
    // Skip the rest of this declarator, up until the comma or semicolon.
4660
4
    SkipUntil(tok::comma, StopAtSemi);
4661
4
    return;
4662
4
  }
4663
4664
  // If an identifier is present, consume and remember it.
4665
876k
  IdentifierInfo *Name = nullptr;
4666
876k
  SourceLocation NameLoc;
4667
876k
  if (Tok.is(tok::identifier)) {
4668
494k
    Name = Tok.getIdentifierInfo();
4669
494k
    NameLoc = ConsumeToken();
4670
494k
  }
4671
4672
876k
  if (!Name && 
ScopedEnumKWLoc.isValid()382k
) {
4673
    // C++0x 7.2p2: The optional identifier shall not be omitted in the
4674
    // declaration of a scoped enumeration.
4675
8
    Diag(Tok, diag::err_scoped_enum_missing_identifier);
4676
8
    ScopedEnumKWLoc = SourceLocation();
4677
8
    IsScopedUsingClassTag = false;
4678
8
  }
4679
4680
  // Okay, end the suppression area.  We'll decide whether to emit the
4681
  // diagnostics in a second.
4682
876k
  if (shouldDelayDiagsInTag)
4683
70
    diagsFromTag.done();
4684
4685
876k
  TypeResult BaseType;
4686
876k
  SourceRange BaseRange;
4687
4688
876k
  bool CanBeBitfield =
4689
876k
      getCurScope()->isClassScope() && 
ScopedEnumKWLoc.isInvalid()13.4k
&&
Name13.2k
;
4690
4691
  // Parse the fixed underlying type.
4692
876k
  if (Tok.is(tok::colon)) {
4693
    // This might be an enum-base or part of some unrelated enclosing context.
4694
    //
4695
    // 'enum E : base' is permitted in two circumstances:
4696
    //
4697
    // 1) As a defining-type-specifier, when followed by '{'.
4698
    // 2) As the sole constituent of a complete declaration -- when DS is empty
4699
    //    and the next token is ';'.
4700
    //
4701
    // The restriction to defining-type-specifiers is important to allow parsing
4702
    //   a ? new enum E : int{}
4703
    //   _Generic(a, enum E : int{})
4704
    // properly.
4705
    //
4706
    // One additional consideration applies:
4707
    //
4708
    // C++ [dcl.enum]p1:
4709
    //   A ':' following "enum nested-name-specifier[opt] identifier" within
4710
    //   the decl-specifier-seq of a member-declaration is parsed as part of
4711
    //   an enum-base.
4712
    //
4713
    // Other language modes supporting enumerations with fixed underlying types
4714
    // do not have clear rules on this, so we disambiguate to determine whether
4715
    // the tokens form a bit-field width or an enum-base.
4716
4717
171k
    if (CanBeBitfield && 
!isEnumBase(CanBeOpaqueEnumDeclaration)191
) {
4718
      // Outside C++11, do not interpret the tokens as an enum-base if they do
4719
      // not make sense as one. In C++11, it's an error if this happens.
4720
19
      if (getLangOpts().CPlusPlus11)
4721
13
        Diag(Tok.getLocation(), diag::err_anonymous_enum_bitfield);
4722
171k
    } else if (CanHaveEnumBase || 
!ColonIsSacred74
) {
4723
171k
      SourceLocation ColonLoc = ConsumeToken();
4724
4725
      // Parse a type-specifier-seq as a type. We can't just ParseTypeName here,
4726
      // because under -fms-extensions,
4727
      //   enum E : int *p;
4728
      // declares 'enum E : int; E *p;' not 'enum E : int*; E p;'.
4729
171k
      DeclSpec DS(AttrFactory);
4730
171k
      ParseSpecifierQualifierList(DS, AS, DeclSpecContext::DSC_type_specifier);
4731
171k
      Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
4732
171k
                                DeclaratorContext::TypeName);
4733
171k
      BaseType = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
4734
4735
171k
      BaseRange = SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
4736
4737
171k
      if (!getLangOpts().ObjC) {
4738
3.92k
        if (getLangOpts().CPlusPlus11)
4739
3.86k
          Diag(ColonLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type)
4740
3.86k
              << BaseRange;
4741
59
        else if (getLangOpts().CPlusPlus)
4742
16
          Diag(ColonLoc, diag::ext_cxx11_enum_fixed_underlying_type)
4743
16
              << BaseRange;
4744
43
        else if (getLangOpts().MicrosoftExt)
4745
7
          Diag(ColonLoc, diag::ext_ms_c_enum_fixed_underlying_type)
4746
7
              << BaseRange;
4747
36
        else
4748
36
          Diag(ColonLoc, diag::ext_clang_c_enum_fixed_underlying_type)
4749
36
              << BaseRange;
4750
3.92k
      }
4751
171k
    }
4752
171k
  }
4753
4754
  // There are four options here.  If we have 'friend enum foo;' then this is a
4755
  // friend declaration, and cannot have an accompanying definition. If we have
4756
  // 'enum foo;', then this is a forward declaration.  If we have
4757
  // 'enum foo {...' then this is a definition. Otherwise we have something
4758
  // like 'enum foo xyz', a reference.
4759
  //
4760
  // This is needed to handle stuff like this right (C99 6.7.2.3p11):
4761
  // enum foo {..};  void bar() { enum foo; }    <- new foo in bar.
4762
  // enum foo {..};  void bar() { enum foo x; }  <- use of old foo.
4763
  //
4764
876k
  Sema::TagUseKind TUK;
4765
876k
  if (AllowEnumSpecifier == AllowDefiningTypeSpec::No)
4766
55
    TUK = Sema::TUK_Reference;
4767
876k
  else if (Tok.is(tok::l_brace)) {
4768
472k
    if (DS.isFriendSpecified()) {
4769
7
      Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
4770
7
        << SourceRange(DS.getFriendSpecLoc());
4771
7
      ConsumeBrace();
4772
7
      SkipUntil(tok::r_brace, StopAtSemi);
4773
      // Discard any other definition-only pieces.
4774
7
      attrs.clear();
4775
7
      ScopedEnumKWLoc = SourceLocation();
4776
7
      IsScopedUsingClassTag = false;
4777
7
      BaseType = TypeResult();
4778
7
      TUK = Sema::TUK_Friend;
4779
472k
    } else {
4780
472k
      TUK = Sema::TUK_Definition;
4781
472k
    }
4782
472k
  } else 
if (404k
!isTypeSpecifier(DSC)404k
&&
4783
404k
             
(404k
Tok.is(tok::semi)404k
||
4784
404k
              
(403k
Tok.isAtStartOfLine()403k
&&
4785
403k
               
!isValidAfterTypeSpecifier(CanBeBitfield)35
))) {
4786
    // An opaque-enum-declaration is required to be standalone (no preceding or
4787
    // following tokens in the declaration). Sema enforces this separately by
4788
    // diagnosing anything else in the DeclSpec.
4789
469
    TUK = DS.isFriendSpecified() ? 
Sema::TUK_Friend22
:
Sema::TUK_Declaration447
;
4790
469
    if (Tok.isNot(tok::semi)) {
4791
      // A semicolon was missing after this declaration. Diagnose and recover.
4792
2
      ExpectAndConsume(tok::semi, diag::err_expected_after, "enum");
4793
2
      PP.EnterToken(Tok, /*IsReinject=*/true);
4794
2
      Tok.setKind(tok::semi);
4795
2
    }
4796
404k
  } else {
4797
404k
    TUK = Sema::TUK_Reference;
4798
404k
  }
4799
4800
876k
  bool IsElaboratedTypeSpecifier =
4801
876k
      TUK == Sema::TUK_Reference || 
TUK == Sema::TUK_Friend472k
;
4802
4803
  // If this is an elaborated type specifier nested in a larger declaration,
4804
  // and we delayed diagnostics before, just merge them into the current pool.
4805
876k
  if (TUK == Sema::TUK_Reference && 
shouldDelayDiagsInTag404k
) {
4806
0
    diagsFromTag.redelay();
4807
0
  }
4808
4809
876k
  MultiTemplateParamsArg TParams;
4810
876k
  if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
4811
876k
      
TUK != Sema::TUK_Reference111
) {
4812
110
    if (!getLangOpts().CPlusPlus11 || !SS.isSet()) {
4813
      // Skip the rest of this declarator, up until the comma or semicolon.
4814
1
      Diag(Tok, diag::err_enum_template);
4815
1
      SkipUntil(tok::comma, StopAtSemi);
4816
1
      return;
4817
1
    }
4818
4819
109
    if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
4820
      // Enumerations can't be explicitly instantiated.
4821
5
      DS.SetTypeSpecError();
4822
5
      Diag(StartLoc, diag::err_explicit_instantiation_enum);
4823
5
      return;
4824
5
    }
4825
4826
104
    assert(TemplateInfo.TemplateParams && "no template parameters");
4827
0
    TParams = MultiTemplateParamsArg(TemplateInfo.TemplateParams->data(),
4828
104
                                     TemplateInfo.TemplateParams->size());
4829
104
  }
4830
4831
876k
  if (!Name && 
TUK != Sema::TUK_Definition382k
) {
4832
3
    Diag(Tok, diag::err_enumerator_unnamed_no_def);
4833
4834
    // Skip the rest of this declarator, up until the comma or semicolon.
4835
3
    SkipUntil(tok::comma, StopAtSemi);
4836
3
    return;
4837
3
  }
4838
4839
  // An elaborated-type-specifier has a much more constrained grammar:
4840
  //
4841
  //   'enum' nested-name-specifier[opt] identifier
4842
  //
4843
  // If we parsed any other bits, reject them now.
4844
  //
4845
  // MSVC and (for now at least) Objective-C permit a full enum-specifier
4846
  // or opaque-enum-declaration anywhere.
4847
876k
  if (IsElaboratedTypeSpecifier && 
!getLangOpts().MicrosoftExt404k
&&
4848
876k
      
!getLangOpts().ObjC404k
) {
4849
331k
    ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
4850
331k
                            /*DiagnoseEmptyAttrs=*/true);
4851
331k
    if (BaseType.isUsable())
4852
440
      Diag(BaseRange.getBegin(), diag::ext_enum_base_in_type_specifier)
4853
440
          << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
4854
330k
    else if (ScopedEnumKWLoc.isValid())
4855
26
      Diag(ScopedEnumKWLoc, diag::ext_elaborated_enum_class)
4856
26
        << FixItHint::CreateRemoval(ScopedEnumKWLoc) << IsScopedUsingClassTag;
4857
331k
  }
4858
4859
876k
  stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
4860
4861
876k
  Sema::SkipBodyInfo SkipBody;
4862
876k
  if (!Name && 
TUK == Sema::TUK_Definition382k
&&
Tok.is(tok::l_brace)382k
&&
4863
876k
      
NextToken().is(tok::identifier)382k
)
4864
382k
    SkipBody = Actions.shouldSkipAnonEnumBody(getCurScope(),
4865
382k
                                              NextToken().getIdentifierInfo(),
4866
382k
                                              NextToken().getLocation());
4867
4868
876k
  bool Owned = false;
4869
876k
  bool IsDependent = false;
4870
876k
  const char *PrevSpec = nullptr;
4871
876k
  unsigned DiagID;
4872
876k
  Decl *TagDecl = Actions.ActOnTag(
4873
876k
      getCurScope(), DeclSpec::TST_enum, TUK, StartLoc, SS, Name, NameLoc,
4874
876k
      attrs, AS, DS.getModulePrivateSpecLoc(), TParams, Owned, IsDependent,
4875
876k
      ScopedEnumKWLoc, IsScopedUsingClassTag, BaseType,
4876
876k
      DSC == DeclSpecContext::DSC_type_specifier,
4877
876k
      DSC == DeclSpecContext::DSC_template_param ||
4878
876k
          
DSC == DeclSpecContext::DSC_template_type_arg876k
,
4879
876k
      &SkipBody);
4880
4881
876k
  if (SkipBody.ShouldSkip) {
4882
18
    assert(TUK == Sema::TUK_Definition && "can only skip a definition");
4883
4884
0
    BalancedDelimiterTracker T(*this, tok::l_brace);
4885
18
    T.consumeOpen();
4886
18
    T.skipToEnd();
4887
4888
18
    if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc,
4889
18
                           NameLoc.isValid() ? 
NameLoc13
:
StartLoc5
,
4890
18
                           PrevSpec, DiagID, TagDecl, Owned,
4891
18
                           Actions.getASTContext().getPrintingPolicy()))
4892
0
      Diag(StartLoc, DiagID) << PrevSpec;
4893
18
    return;
4894
18
  }
4895
4896
876k
  if (IsDependent) {
4897
    // This enum has a dependent nested-name-specifier. Handle it as a
4898
    // dependent tag.
4899
14
    if (!Name) {
4900
0
      DS.SetTypeSpecError();
4901
0
      Diag(Tok, diag::err_expected_type_name_after_typename);
4902
0
      return;
4903
0
    }
4904
4905
14
    TypeResult Type = Actions.ActOnDependentTag(
4906
14
        getCurScope(), DeclSpec::TST_enum, TUK, SS, Name, StartLoc, NameLoc);
4907
14
    if (Type.isInvalid()) {
4908
0
      DS.SetTypeSpecError();
4909
0
      return;
4910
0
    }
4911
4912
14
    if (DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc,
4913
14
                           NameLoc.isValid() ? NameLoc : 
StartLoc0
,
4914
14
                           PrevSpec, DiagID, Type.get(),
4915
14
                           Actions.getASTContext().getPrintingPolicy()))
4916
0
      Diag(StartLoc, DiagID) << PrevSpec;
4917
4918
14
    return;
4919
14
  }
4920
4921
876k
  if (!TagDecl) {
4922
    // The action failed to produce an enumeration tag. If this is a
4923
    // definition, consume the entire definition.
4924
89
    if (Tok.is(tok::l_brace) && 
TUK != Sema::TUK_Reference60
) {
4925
60
      ConsumeBrace();
4926
60
      SkipUntil(tok::r_brace, StopAtSemi);
4927
60
    }
4928
4929
89
    DS.SetTypeSpecError();
4930
89
    return;
4931
89
  }
4932
4933
876k
  if (Tok.is(tok::l_brace) && 
TUK == Sema::TUK_Definition472k
) {
4934
472k
    Decl *D = SkipBody.CheckSameAsPrevious ? 
SkipBody.New4
:
TagDecl472k
;
4935
472k
    ParseEnumBody(StartLoc, D);
4936
472k
    if (SkipBody.CheckSameAsPrevious &&
4937
472k
        
!Actions.ActOnDuplicateDefinition(TagDecl, SkipBody)4
) {
4938
2
      DS.SetTypeSpecError();
4939
2
      return;
4940
2
    }
4941
472k
  }
4942
4943
876k
  if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc,
4944
876k
                         NameLoc.isValid() ? 
NameLoc493k
:
StartLoc382k
,
4945
876k
                         PrevSpec, DiagID, TagDecl, Owned,
4946
876k
                         Actions.getASTContext().getPrintingPolicy()))
4947
0
    Diag(StartLoc, DiagID) << PrevSpec;
4948
876k
}
4949
4950
/// ParseEnumBody - Parse a {} enclosed enumerator-list.
4951
///       enumerator-list:
4952
///         enumerator
4953
///         enumerator-list ',' enumerator
4954
///       enumerator:
4955
///         enumeration-constant attributes[opt]
4956
///         enumeration-constant attributes[opt] '=' constant-expression
4957
///       enumeration-constant:
4958
///         identifier
4959
///
4960
472k
void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) {
4961
  // Enter the scope of the enum body and start the definition.
4962
472k
  ParseScope EnumScope(this, Scope::DeclScope | Scope::EnumScope);
4963
472k
  Actions.ActOnTagStartDefinition(getCurScope(), EnumDecl);
4964
4965
472k
  BalancedDelimiterTracker T(*this, tok::l_brace);
4966
472k
  T.consumeOpen();
4967
4968
  // C does not allow an empty enumerator-list, C++ does [dcl.enum].
4969
472k
  if (Tok.is(tok::r_brace) && 
!getLangOpts().CPlusPlus1.67k
)
4970
1
    Diag(Tok, diag::err_empty_enum);
4971
4972
472k
  SmallVector<Decl *, 32> EnumConstantDecls;
4973
472k
  SmallVector<SuppressAccessChecks, 32> EnumAvailabilityDiags;
4974
4975
472k
  Decl *LastEnumConstDecl = nullptr;
4976
4977
  // Parse the enumerator-list.
4978
4.27M
  while (Tok.isNot(tok::r_brace)) {
4979
    // Parse enumerator. If failed, try skipping till the start of the next
4980
    // enumerator definition.
4981
3.84M
    if (Tok.isNot(tok::identifier)) {
4982
9
      Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
4983
9
      if (SkipUntil(tok::comma, tok::r_brace, StopBeforeMatch) &&
4984
9
          TryConsumeToken(tok::comma))
4985
2
        continue;
4986
7
      break;
4987
9
    }
4988
3.84M
    IdentifierInfo *Ident = Tok.getIdentifierInfo();
4989
3.84M
    SourceLocation IdentLoc = ConsumeToken();
4990
4991
    // If attributes exist after the enumerator, parse them.
4992
3.84M
    ParsedAttributes attrs(AttrFactory);
4993
3.84M
    MaybeParseGNUAttributes(attrs);
4994
3.84M
    if (standardAttributesAllowed() && 
isCXX11AttributeSpecifier()569k
) {
4995
16
      if (getLangOpts().CPlusPlus)
4996
9
        Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
4997
9
                                    ? 
diag::warn_cxx14_compat_ns_enum_attribute7
4998
9
                                    : 
diag::ext_ns_enum_attribute2
)
4999
9
            << 1 /*enumerator*/;
5000
16
      ParseCXX11Attributes(attrs);
5001
16
    }
5002
5003
3.84M
    SourceLocation EqualLoc;
5004
3.84M
    ExprResult AssignedVal;
5005
3.84M
    EnumAvailabilityDiags.emplace_back(*this);
5006
5007
3.84M
    EnterExpressionEvaluationContext ConstantEvaluated(
5008
3.84M
        Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5009
3.84M
    if (TryConsumeToken(tok::equal, EqualLoc)) {
5010
3.66M
      AssignedVal = ParseConstantExpressionInExprEvalContext();
5011
3.66M
      if (AssignedVal.isInvalid())
5012
12
        SkipUntil(tok::comma, tok::r_brace, StopBeforeMatch);
5013
3.66M
    }
5014
5015
    // Install the enumerator constant into EnumDecl.
5016
3.84M
    Decl *EnumConstDecl = Actions.ActOnEnumConstant(
5017
3.84M
        getCurScope(), EnumDecl, LastEnumConstDecl, IdentLoc, Ident, attrs,
5018
3.84M
        EqualLoc, AssignedVal.get());
5019
3.84M
    EnumAvailabilityDiags.back().done();
5020
5021
3.84M
    EnumConstantDecls.push_back(EnumConstDecl);
5022
3.84M
    LastEnumConstDecl = EnumConstDecl;
5023
5024
3.84M
    if (Tok.is(tok::identifier)) {
5025
      // We're missing a comma between enumerators.
5026
4
      SourceLocation Loc = getEndOfPreviousToken();
5027
4
      Diag(Loc, diag::err_enumerator_list_missing_comma)
5028
4
        << FixItHint::CreateInsertion(Loc, ", ");
5029
4
      continue;
5030
4
    }
5031
5032
    // Emumerator definition must be finished, only comma or r_brace are
5033
    // allowed here.
5034
3.84M
    SourceLocation CommaLoc;
5035
3.84M
    if (Tok.isNot(tok::r_brace) && 
!TryConsumeToken(tok::comma, CommaLoc)3.41M
) {
5036
7
      if (EqualLoc.isValid())
5037
5
        Diag(Tok.getLocation(), diag::err_expected_either) << tok::r_brace
5038
5
                                                           << tok::comma;
5039
2
      else
5040
2
        Diag(Tok.getLocation(), diag::err_expected_end_of_enumerator);
5041
7
      if (SkipUntil(tok::comma, tok::r_brace, StopBeforeMatch)) {
5042
7
        if (TryConsumeToken(tok::comma, CommaLoc))
5043
2
          continue;
5044
7
      } else {
5045
0
        break;
5046
0
      }
5047
7
    }
5048
5049
    // If comma is followed by r_brace, emit appropriate warning.
5050
3.84M
    if (Tok.is(tok::r_brace) && 
CommaLoc.isValid()470k
) {
5051
42.8k
      if (!getLangOpts().C99 && 
!getLangOpts().CPlusPlus117.45k
)
5052
8
        Diag(CommaLoc, getLangOpts().CPlusPlus ?
5053
7
               diag::ext_enumerator_list_comma_cxx :
5054
8
               
diag::ext_enumerator_list_comma_c1
)
5055
8
          << FixItHint::CreateRemoval(CommaLoc);
5056
42.8k
      else if (getLangOpts().CPlusPlus11)
5057
7.44k
        Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma)
5058
7.44k
          << FixItHint::CreateRemoval(CommaLoc);
5059
42.8k
      break;
5060
42.8k
    }
5061
3.84M
  }
5062
5063
  // Eat the }.
5064
472k
  T.consumeClose();
5065
5066
  // If attributes exist after the identifier list, parse them.
5067
472k
  ParsedAttributes attrs(AttrFactory);
5068
472k
  MaybeParseGNUAttributes(attrs);
5069
5070
472k
  Actions.ActOnEnumBody(StartLoc, T.getRange(), EnumDecl, EnumConstantDecls,
5071
472k
                        getCurScope(), attrs);
5072
5073
  // Now handle enum constant availability diagnostics.
5074
472k
  assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
5075
4.31M
  for (size_t i = 0, e = EnumConstantDecls.size(); i != e; 
++i3.84M
) {
5076
3.84M
    ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent);
5077
3.84M
    EnumAvailabilityDiags[i].redelay();
5078
3.84M
    PD.complete(EnumConstantDecls[i]);
5079
3.84M
  }
5080
5081
472k
  EnumScope.Exit();
5082
472k
  Actions.ActOnTagFinishDefinition(getCurScope(), EnumDecl, T.getRange());
5083
5084
  // The next token must be valid after an enum definition. If not, a ';'
5085
  // was probably forgotten.
5086
472k
  bool CanBeBitfield = getCurScope()->isClassScope();
5087
472k
  if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
5088
6
    ExpectAndConsume(tok::semi, diag::err_expected_after, "enum");
5089
    // Push this token back into the preprocessor and change our current token
5090
    // to ';' so that the rest of the code recovers as though there were an
5091
    // ';' after the definition.
5092
6
    PP.EnterToken(Tok, /*IsReinject=*/true);
5093
6
    Tok.setKind(tok::semi);
5094
6
  }
5095
472k
}
5096
5097
/// isKnownToBeTypeSpecifier - Return true if we know that the specified token
5098
/// is definitely a type-specifier.  Return false if it isn't part of a type
5099
/// specifier or if we're not sure.
5100
94.3k
bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const {
5101
94.3k
  switch (Tok.getKind()) {
5102
94.3k
  default: return false;
5103
    // type-specifiers
5104
0
  case tok::kw_short:
5105
0
  case tok::kw_long:
5106
0
  case tok::kw___int64:
5107
0
  case tok::kw___int128:
5108
0
  case tok::kw_signed:
5109
0
  case tok::kw_unsigned:
5110
0
  case tok::kw__Complex:
5111
0
  case tok::kw__Imaginary:
5112
7
  case tok::kw_void:
5113
7
  case tok::kw_char:
5114
7
  case tok::kw_wchar_t:
5115
7
  case tok::kw_char8_t:
5116
7
  case tok::kw_char16_t:
5117
7
  case tok::kw_char32_t:
5118
37
  case tok::kw_int:
5119
37
  case tok::kw__ExtInt:
5120
37
  case tok::kw__BitInt:
5121
37
  case tok::kw___bf16:
5122
37
  case tok::kw_half:
5123
37
  case tok::kw_float:
5124
38
  case tok::kw_double:
5125
38
  case tok::kw__Accum:
5126
38
  case tok::kw__Fract:
5127
38
  case tok::kw__Float16:
5128
38
  case tok::kw___float128:
5129
38
  case tok::kw___ibm128:
5130
38
  case tok::kw_bool:
5131
38
  case tok::kw__Bool:
5132
38
  case tok::kw__Decimal32:
5133
38
  case tok::kw__Decimal64:
5134
38
  case tok::kw__Decimal128:
5135
38
  case tok::kw___vector:
5136
456
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5137
456
#include 
"clang/Basic/OpenCLImageTypes.def"38
5138
5139
    // struct-or-union-specifier (C99) or class-specifier (C++)
5140
456
  case tok::kw_class:
5141
38
  case tok::kw_struct:
5142
38
  case tok::kw___interface:
5143
38
  case tok::kw_union:
5144
    // enum-specifier
5145
38
  case tok::kw_enum:
5146
5147
    // typedef-name
5148
38
  case tok::annot_typename:
5149
38
    return true;
5150
94.3k
  }
5151
94.3k
}
5152
5153
/// isTypeSpecifierQualifier - Return true if the current token could be the
5154
/// start of a specifier-qualifier-list.
5155
11.4M
bool Parser::isTypeSpecifierQualifier() {
5156
11.4M
  switch (Tok.getKind()) {
5157
339k
  default: return false;
5158
5159
5.50M
  case tok::identifier:   // foo::bar
5160
5.50M
    if (TryAltiVecVectorToken())
5161
6.00k
      return true;
5162
5.50M
    
LLVM_FALLTHROUGH5.49M
;5.49M
5163
5.49M
  case tok::kw_typename:  // typename T::type
5164
    // Annotate typenames and C++ scope specifiers.  If we get one, just
5165
    // recurse to handle whatever we get.
5166
5.49M
    if (TryAnnotateTypeOrScopeToken())
5167
0
      return true;
5168
5.49M
    if (Tok.is(tok::identifier))
5169
342k
      return false;
5170
5.15M
    return isTypeSpecifierQualifier();
5171
5172
0
  case tok::coloncolon:   // ::foo::bar
5173
0
    if (NextToken().is(tok::kw_new) ||    // ::new
5174
0
        NextToken().is(tok::kw_delete))   // ::delete
5175
0
      return false;
5176
5177
0
    if (TryAnnotateTypeOrScopeToken())
5178
0
      return true;
5179
0
    return isTypeSpecifierQualifier();
5180
5181
    // GNU attributes support.
5182
1.10k
  case tok::kw___attribute:
5183
    // GNU typeof support.
5184
1.20k
  case tok::kw_typeof:
5185
5186
    // type-specifiers
5187
4.04k
  case tok::kw_short:
5188
13.1k
  case tok::kw_long:
5189
13.1k
  case tok::kw___int64:
5190
13.1k
  case tok::kw___int128:
5191
13.5k