Coverage Report

Created: 2020-02-18 08:44

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