Coverage Report

Created: 2019-07-24 05:18

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