Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Parse/ParseExpr.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- ParseExpr.cpp - Expression Parsing -------------------------------===//
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
/// \file
10
/// Provides the Expression parsing implementation.
11
///
12
/// Expressions in C99 basically consist of a bunch of binary operators with
13
/// unary operators and other random stuff at the leaves.
14
///
15
/// In the C99 grammar, these unary operators bind tightest and are represented
16
/// as the 'cast-expression' production.  Everything else is either a binary
17
/// operator (e.g. '/') or a ternary operator ("?:").  The unary leaves are
18
/// handled by ParseCastExpression, the higher level pieces are handled by
19
/// ParseBinaryExpression.
20
///
21
//===----------------------------------------------------------------------===//
22
23
#include "clang/Parse/Parser.h"
24
#include "clang/AST/ASTContext.h"
25
#include "clang/Basic/PrettyStackTrace.h"
26
#include "clang/Parse/RAIIObjectsForParser.h"
27
#include "clang/Sema/DeclSpec.h"
28
#include "clang/Sema/ParsedTemplate.h"
29
#include "clang/Sema/Scope.h"
30
#include "clang/Sema/TypoCorrection.h"
31
#include "llvm/ADT/SmallVector.h"
32
using namespace clang;
33
34
/// Simple precedence-based parser for binary/ternary operators.
35
///
36
/// Note: we diverge from the C99 grammar when parsing the assignment-expression
37
/// production.  C99 specifies that the LHS of an assignment operator should be
38
/// parsed as a unary-expression, but consistency dictates that it be a
39
/// conditional-expession.  In practice, the important thing here is that the
40
/// LHS of an assignment has to be an l-value, which productions between
41
/// unary-expression and conditional-expression don't produce.  Because we want
42
/// consistency, we parse the LHS as a conditional-expression, then check for
43
/// l-value-ness in semantic analysis stages.
44
///
45
/// \verbatim
46
///       pm-expression: [C++ 5.5]
47
///         cast-expression
48
///         pm-expression '.*' cast-expression
49
///         pm-expression '->*' cast-expression
50
///
51
///       multiplicative-expression: [C99 6.5.5]
52
///     Note: in C++, apply pm-expression instead of cast-expression
53
///         cast-expression
54
///         multiplicative-expression '*' cast-expression
55
///         multiplicative-expression '/' cast-expression
56
///         multiplicative-expression '%' cast-expression
57
///
58
///       additive-expression: [C99 6.5.6]
59
///         multiplicative-expression
60
///         additive-expression '+' multiplicative-expression
61
///         additive-expression '-' multiplicative-expression
62
///
63
///       shift-expression: [C99 6.5.7]
64
///         additive-expression
65
///         shift-expression '<<' additive-expression
66
///         shift-expression '>>' additive-expression
67
///
68
///       compare-expression: [C++20 expr.spaceship]
69
///         shift-expression
70
///         compare-expression '<=>' shift-expression
71
///
72
///       relational-expression: [C99 6.5.8]
73
///         compare-expression
74
///         relational-expression '<' compare-expression
75
///         relational-expression '>' compare-expression
76
///         relational-expression '<=' compare-expression
77
///         relational-expression '>=' compare-expression
78
///
79
///       equality-expression: [C99 6.5.9]
80
///         relational-expression
81
///         equality-expression '==' relational-expression
82
///         equality-expression '!=' relational-expression
83
///
84
///       AND-expression: [C99 6.5.10]
85
///         equality-expression
86
///         AND-expression '&' equality-expression
87
///
88
///       exclusive-OR-expression: [C99 6.5.11]
89
///         AND-expression
90
///         exclusive-OR-expression '^' AND-expression
91
///
92
///       inclusive-OR-expression: [C99 6.5.12]
93
///         exclusive-OR-expression
94
///         inclusive-OR-expression '|' exclusive-OR-expression
95
///
96
///       logical-AND-expression: [C99 6.5.13]
97
///         inclusive-OR-expression
98
///         logical-AND-expression '&&' inclusive-OR-expression
99
///
100
///       logical-OR-expression: [C99 6.5.14]
101
///         logical-AND-expression
102
///         logical-OR-expression '||' logical-AND-expression
103
///
104
///       conditional-expression: [C99 6.5.15]
105
///         logical-OR-expression
106
///         logical-OR-expression '?' expression ':' conditional-expression
107
/// [GNU]   logical-OR-expression '?' ':' conditional-expression
108
/// [C++] the third operand is an assignment-expression
109
///
110
///       assignment-expression: [C99 6.5.16]
111
///         conditional-expression
112
///         unary-expression assignment-operator assignment-expression
113
/// [C++]   throw-expression [C++ 15]
114
///
115
///       assignment-operator: one of
116
///         = *= /= %= += -= <<= >>= &= ^= |=
117
///
118
///       expression: [C99 6.5.17]
119
///         assignment-expression ...[opt]
120
///         expression ',' assignment-expression ...[opt]
121
/// \endverbatim
122
9.95M
ExprResult Parser::ParseExpression(TypeCastState isTypeCast) {
123
9.95M
  ExprResult LHS(ParseAssignmentExpression(isTypeCast));
124
9.95M
  return ParseRHSOfBinaryExpression(LHS, prec::Comma);
125
9.95M
}
126
127
/// This routine is called when the '@' is seen and consumed.
128
/// Current token is an Identifier and is not a 'try'. This
129
/// routine is necessary to disambiguate \@try-statement from,
130
/// for example, \@encode-expression.
131
///
132
ExprResult
133
252
Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
134
252
  ExprResult LHS(ParseObjCAtExpression(AtLoc));
135
252
  return ParseRHSOfBinaryExpression(LHS, prec::Comma);
136
252
}
137
138
/// This routine is called when a leading '__extension__' is seen and
139
/// consumed.  This is necessary because the token gets consumed in the
140
/// process of disambiguating between an expression and a declaration.
141
ExprResult
142
1.17k
Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) {
143
1.17k
  ExprResult LHS(true);
144
1.17k
  {
145
1.17k
    // Silence extension warnings in the sub-expression
146
1.17k
    ExtensionRAIIObject O(Diags);
147
1.17k
148
1.17k
    LHS = ParseCastExpression(false);
149
1.17k
  }
150
1.17k
151
1.17k
  if (!LHS.isInvalid())
152
1.16k
    LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__,
153
1.16k
                               LHS.get());
154
1.17k
155
1.17k
  return ParseRHSOfBinaryExpression(LHS, prec::Comma);
156
1.17k
}
157
158
/// Parse an expr that doesn't include (top-level) commas.
159
27.8M
ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) {
160
27.8M
  if (Tok.is(tok::code_completion)) {
161
188
    Actions.CodeCompleteExpression(getCurScope(),
162
188
                                   PreferredType.get(Tok.getLocation()));
163
188
    cutOffParsing();
164
188
    return ExprError();
165
188
  }
166
27.8M
167
27.8M
  if (Tok.is(tok::kw_throw))
168
10.1k
    return ParseThrowExpression();
169
27.8M
  if (Tok.is(tok::kw_co_yield))
170
63
    return ParseCoyieldExpression();
171
27.8M
172
27.8M
  ExprResult LHS = ParseCastExpression(/*isUnaryExpression=*/false,
173
27.8M
                                       /*isAddressOfOperand=*/false,
174
27.8M
                                       isTypeCast);
175
27.8M
  return ParseRHSOfBinaryExpression(LHS, prec::Assignment);
176
27.8M
}
177
178
/// Parse an assignment expression where part of an Objective-C message
179
/// send has already been parsed.
180
///
181
/// In this case \p LBracLoc indicates the location of the '[' of the message
182
/// send, and either \p ReceiverName or \p ReceiverExpr is non-null indicating
183
/// the receiver of the message.
184
///
185
/// Since this handles full assignment-expression's, it handles postfix
186
/// expressions and other binary operators for these expressions as well.
187
ExprResult
188
Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
189
                                                    SourceLocation SuperLoc,
190
                                                    ParsedType ReceiverType,
191
68
                                                    Expr *ReceiverExpr) {
192
68
  ExprResult R
193
68
    = ParseObjCMessageExpressionBody(LBracLoc, SuperLoc,
194
68
                                     ReceiverType, ReceiverExpr);
195
68
  R = ParsePostfixExpressionSuffix(R);
196
68
  return ParseRHSOfBinaryExpression(R, prec::Assignment);
197
68
}
198
199
ExprResult
200
1.20M
Parser::ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast) {
201
1.20M
  assert(Actions.ExprEvalContexts.back().Context ==
202
1.20M
             Sema::ExpressionEvaluationContext::ConstantEvaluated &&
203
1.20M
         "Call this function only if your ExpressionEvaluationContext is "
204
1.20M
         "already ConstantEvaluated");
205
1.20M
  ExprResult LHS(ParseCastExpression(false, false, isTypeCast));
206
1.20M
  ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
207
1.20M
  return Actions.ActOnConstantExpression(Res);
208
1.20M
}
209
210
378k
ExprResult Parser::ParseConstantExpression(TypeCastState isTypeCast) {
211
378k
  // C++03 [basic.def.odr]p2:
212
378k
  //   An expression is potentially evaluated unless it appears where an
213
378k
  //   integral constant expression is required (see 5.19) [...].
214
378k
  // C++98 and C++11 have no such rule, but this is only a defect in C++98.
215
378k
  EnterExpressionEvaluationContext ConstantEvaluated(
216
378k
      Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
217
378k
  return ParseConstantExpressionInExprEvalContext(isTypeCast);
218
378k
}
219
220
62.7k
ExprResult Parser::ParseCaseExpression(SourceLocation CaseLoc) {
221
62.7k
  EnterExpressionEvaluationContext ConstantEvaluated(
222
62.7k
      Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
223
62.7k
  ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
224
62.7k
  ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
225
62.7k
  return Actions.ActOnCaseExpr(CaseLoc, Res);
226
62.7k
}
227
228
/// Parse a constraint-expression.
229
///
230
/// \verbatim
231
///       constraint-expression: [Concepts TS temp.constr.decl p1]
232
///         logical-or-expression
233
/// \endverbatim
234
57
ExprResult Parser::ParseConstraintExpression() {
235
57
  // FIXME: this may erroneously consume a function-body as the braced
236
57
  // initializer list of a compound literal
237
57
  //
238
57
  // FIXME: this may erroneously consume a parenthesized rvalue reference
239
57
  // declarator as a parenthesized address-of-label expression
240
57
  ExprResult LHS(ParseCastExpression(/*isUnaryExpression=*/false));
241
57
  ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::LogicalOr));
242
57
243
57
  return Res;
244
57
}
245
246
53.1k
bool Parser::isNotExpressionStart() {
247
53.1k
  tok::TokenKind K = Tok.getKind();
248
53.1k
  if (K == tok::l_brace || 
K == tok::r_brace53.1k
||
249
53.1k
      
K == tok::kw_for53.1k
||
K == tok::kw_while53.1k
||
250
53.1k
      
K == tok::kw_if53.1k
||
K == tok::kw_else53.1k
||
251
53.1k
      
K == tok::kw_goto53.1k
||
K == tok::kw_try53.1k
)
252
5
    return true;
253
53.1k
  // If this is a decl-specifier, we can't be at the start of an expression.
254
53.1k
  return isKnownToBeDeclarationSpecifier();
255
53.1k
}
256
257
7.57M
bool Parser::isFoldOperator(prec::Level Level) const {
258
7.57M
  return Level > prec::Unknown && 
Level != prec::Conditional5.34M
&&
259
7.57M
         
Level != prec::Spaceship5.21M
;
260
7.57M
}
261
262
2.22M
bool Parser::isFoldOperator(tok::TokenKind Kind) const {
263
2.22M
  return isFoldOperator(getBinOpPrecedence(Kind, GreaterThanIsOperator, true));
264
2.22M
}
265
266
/// Parse a binary expression that starts with \p LHS and has a
267
/// precedence of at least \p MinPrec.
268
ExprResult
269
39.3M
Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
270
39.3M
  prec::Level NextTokPrec = getBinOpPrecedence(Tok.getKind(),
271
39.3M
                                               GreaterThanIsOperator,
272
39.3M
                                               getLangOpts().CPlusPlus11);
273
39.3M
  SourceLocation ColonLoc;
274
39.3M
275
39.3M
  auto SavedType = PreferredType;
276
44.7M
  while (1) {
277
44.7M
    // Every iteration may rely on a preferred type for the whole expression.
278
44.7M
    PreferredType = SavedType;
279
44.7M
    // If this token has a lower precedence than we are allowed to parse (e.g.
280
44.7M
    // because we are called recursively, or because the token is not a binop),
281
44.7M
    // then we are done!
282
44.7M
    if (NextTokPrec < MinPrec)
283
39.3M
      return LHS;
284
5.34M
285
5.34M
    // Consume the operator, saving the operator token for error reporting.
286
5.34M
    Token OpToken = Tok;
287
5.34M
    ConsumeToken();
288
5.34M
289
5.34M
    if (OpToken.is(tok::caretcaret)) {
290
1
      return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or));
291
1
    }
292
5.34M
293
5.34M
    // If we're potentially in a template-id, we may now be able to determine
294
5.34M
    // whether we're actually in one or not.
295
5.34M
    if (OpToken.isOneOf(tok::comma, tok::greater, tok::greatergreater,
296
5.34M
                        tok::greatergreatergreater) &&
297
5.34M
        
checkPotentialAngleBracketDelimiter(OpToken)311k
)
298
18
      return ExprError();
299
5.34M
300
5.34M
    // Bail out when encountering a comma followed by a token which can't
301
5.34M
    // possibly be the start of an expression. For instance:
302
5.34M
    //   int f() { return 1, }
303
5.34M
    // We can't do this before consuming the comma, because
304
5.34M
    // isNotExpressionStart() looks at the token stream.
305
5.34M
    if (OpToken.is(tok::comma) && 
isNotExpressionStart()53.1k
) {
306
8
      PP.EnterToken(Tok, /*IsReinject*/true);
307
8
      Tok = OpToken;
308
8
      return LHS;
309
8
    }
310
5.34M
311
5.34M
    // If the next token is an ellipsis, then this is a fold-expression. Leave
312
5.34M
    // it alone so we can handle it in the paren expression.
313
5.34M
    if (isFoldOperator(NextTokPrec) && 
Tok.is(tok::ellipsis)5.21M
) {
314
202
      // FIXME: We can't check this via lookahead before we consume the token
315
202
      // because that tickles a lexer bug.
316
202
      PP.EnterToken(Tok, /*IsReinject*/true);
317
202
      Tok = OpToken;
318
202
      return LHS;
319
202
    }
320
5.34M
321
5.34M
    // In Objective-C++, alternative operator tokens can be used as keyword args
322
5.34M
    // in message expressions. Unconsume the token so that it can reinterpreted
323
5.34M
    // as an identifier in ParseObjCMessageExpressionBody. i.e., we support:
324
5.34M
    //   [foo meth:0 and:0];
325
5.34M
    //   [foo not_eq];
326
5.34M
    if (getLangOpts().ObjC && 
getLangOpts().CPlusPlus28.1k
&&
327
5.34M
        
Tok.isOneOf(tok::colon, tok::r_square)7.37k
&&
328
5.34M
        
OpToken.getIdentifierInfo() != nullptr25
) {
329
16
      PP.EnterToken(Tok, /*IsReinject*/true);
330
16
      Tok = OpToken;
331
16
      return LHS;
332
16
    }
333
5.34M
334
5.34M
    // Special case handling for the ternary operator.
335
5.34M
    ExprResult TernaryMiddle(true);
336
5.34M
    if (NextTokPrec == prec::Conditional) {
337
131k
      if (getLangOpts().CPlusPlus11 && 
Tok.is(tok::l_brace)82.5k
) {
338
1
        // Parse a braced-init-list here for error recovery purposes.
339
1
        SourceLocation BraceLoc = Tok.getLocation();
340
1
        TernaryMiddle = ParseBraceInitializer();
341
1
        if (!TernaryMiddle.isInvalid()) {
342
1
          Diag(BraceLoc, diag::err_init_list_bin_op)
343
1
              << /*RHS*/ 1 << PP.getSpelling(OpToken)
344
1
              << Actions.getExprRange(TernaryMiddle.get());
345
1
          TernaryMiddle = ExprError();
346
1
        }
347
131k
      } else if (Tok.isNot(tok::colon)) {
348
131k
        // Don't parse FOO:BAR as if it were a typo for FOO::BAR.
349
131k
        ColonProtectionRAIIObject X(*this);
350
131k
351
131k
        // Handle this production specially:
352
131k
        //   logical-OR-expression '?' expression ':' conditional-expression
353
131k
        // In particular, the RHS of the '?' is 'expression', not
354
131k
        // 'logical-OR-expression' as we might expect.
355
131k
        TernaryMiddle = ParseExpression();
356
131k
      } else {
357
212
        // Special case handling of "X ? Y : Z" where Y is empty:
358
212
        //   logical-OR-expression '?' ':' conditional-expression   [GNU]
359
212
        TernaryMiddle = nullptr;
360
212
        Diag(Tok, diag::ext_gnu_conditional_expr);
361
212
      }
362
131k
363
131k
      if (TernaryMiddle.isInvalid()) {
364
37
        Actions.CorrectDelayedTyposInExpr(LHS);
365
37
        LHS = ExprError();
366
37
        TernaryMiddle = nullptr;
367
37
      }
368
131k
369
131k
      if (!TryConsumeToken(tok::colon, ColonLoc)) {
370
7
        // Otherwise, we're missing a ':'.  Assume that this was a typo that
371
7
        // the user forgot. If we're not in a macro expansion, we can suggest
372
7
        // a fixit hint. If there were two spaces before the current token,
373
7
        // suggest inserting the colon in between them, otherwise insert ": ".
374
7
        SourceLocation FILoc = Tok.getLocation();
375
7
        const char *FIText = ": ";
376
7
        const SourceManager &SM = PP.getSourceManager();
377
7
        if (FILoc.isFileID() || 
PP.isAtStartOfMacroExpansion(FILoc, &FILoc)2
) {
378
7
          assert(FILoc.isFileID());
379
7
          bool IsInvalid = false;
380
7
          const char *SourcePtr =
381
7
            SM.getCharacterData(FILoc.getLocWithOffset(-1), &IsInvalid);
382
7
          if (!IsInvalid && *SourcePtr == ' ') {
383
7
            SourcePtr =
384
7
              SM.getCharacterData(FILoc.getLocWithOffset(-2), &IsInvalid);
385
7
            if (!IsInvalid && *SourcePtr == ' ') {
386
0
              FILoc = FILoc.getLocWithOffset(-1);
387
0
              FIText = ":";
388
0
            }
389
7
          }
390
7
        }
391
7
392
7
        Diag(Tok, diag::err_expected)
393
7
            << tok::colon << FixItHint::CreateInsertion(FILoc, FIText);
394
7
        Diag(OpToken, diag::note_matching) << tok::question;
395
7
        ColonLoc = Tok.getLocation();
396
7
      }
397
131k
    }
398
5.34M
399
5.34M
    PreferredType.enterBinary(Actions, Tok.getLocation(), LHS.get(),
400
5.34M
                              OpToken.getKind());
401
5.34M
    // Parse another leaf here for the RHS of the operator.
402
5.34M
    // ParseCastExpression works here because all RHS expressions in C have it
403
5.34M
    // as a prefix, at least. However, in C++, an assignment-expression could
404
5.34M
    // be a throw-expression, which is not a valid cast-expression.
405
5.34M
    // Therefore we need some special-casing here.
406
5.34M
    // Also note that the third operand of the conditional operator is
407
5.34M
    // an assignment-expression in C++, and in C++11, we can have a
408
5.34M
    // braced-init-list on the RHS of an assignment. For better diagnostics,
409
5.34M
    // parse as if we were allowed braced-init-lists everywhere, and check that
410
5.34M
    // they only appear on the RHS of assignments later.
411
5.34M
    ExprResult RHS;
412
5.34M
    bool RHSIsInitList = false;
413
5.34M
    if (getLangOpts().CPlusPlus11 && 
Tok.is(tok::l_brace)3.68M
) {
414
82
      RHS = ParseBraceInitializer();
415
82
      RHSIsInitList = true;
416
5.34M
    } else if (getLangOpts().CPlusPlus && 
NextTokPrec <= prec::Conditional3.92M
)
417
1.11M
      RHS = ParseAssignmentExpression();
418
4.22M
    else
419
4.22M
      RHS = ParseCastExpression(false);
420
5.34M
421
5.34M
    if (RHS.isInvalid()) {
422
3.07k
      // FIXME: Errors generated by the delayed typo correction should be
423
3.07k
      // printed before errors from parsing the RHS, not after.
424
3.07k
      Actions.CorrectDelayedTyposInExpr(LHS);
425
3.07k
      if (TernaryMiddle.isUsable())
426
5
        TernaryMiddle = Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
427
3.07k
      LHS = ExprError();
428
3.07k
    }
429
5.34M
430
5.34M
    // Remember the precedence of this operator and get the precedence of the
431
5.34M
    // operator immediately to the right of the RHS.
432
5.34M
    prec::Level ThisPrec = NextTokPrec;
433
5.34M
    NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
434
5.34M
                                     getLangOpts().CPlusPlus11);
435
5.34M
436
5.34M
    // Assignment and conditional expressions are right-associative.
437
5.34M
    bool isRightAssoc = ThisPrec == prec::Conditional ||
438
5.34M
                        
ThisPrec == prec::Assignment5.21M
;
439
5.34M
440
5.34M
    // Get the precedence of the operator to the right of the RHS.  If it binds
441
5.34M
    // more tightly with RHS than we do, evaluate it completely first.
442
5.34M
    if (ThisPrec < NextTokPrec ||
443
5.34M
        
(5.04M
ThisPrec == NextTokPrec5.04M
&&
isRightAssoc194k
)) {
444
308k
      if (!RHS.isInvalid() && 
RHSIsInitList308k
) {
445
4
        Diag(Tok, diag::err_init_list_bin_op)
446
4
          << /*LHS*/0 << PP.getSpelling(Tok) << Actions.getExprRange(RHS.get());
447
4
        RHS = ExprError();
448
4
      }
449
308k
      // If this is left-associative, only parse things on the RHS that bind
450
308k
      // more tightly than the current operator.  If it is left-associative, it
451
308k
      // is okay, to bind exactly as tightly.  For example, compile A=B=C=D as
452
308k
      // A=(B=(C=D)), where each paren is a level of recursion here.
453
308k
      // The function takes ownership of the RHS.
454
308k
      RHS = ParseRHSOfBinaryExpression(RHS,
455
308k
                            static_cast<prec::Level>(ThisPrec + !isRightAssoc));
456
308k
      RHSIsInitList = false;
457
308k
458
308k
      if (RHS.isInvalid()) {
459
324
        // FIXME: Errors generated by the delayed typo correction should be
460
324
        // printed before errors from ParseRHSOfBinaryExpression, not after.
461
324
        Actions.CorrectDelayedTyposInExpr(LHS);
462
324
        if (TernaryMiddle.isUsable())
463
0
          TernaryMiddle = Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
464
324
        LHS = ExprError();
465
324
      }
466
308k
467
308k
      NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
468
308k
                                       getLangOpts().CPlusPlus11);
469
308k
    }
470
5.34M
471
5.34M
    if (!RHS.isInvalid() && 
RHSIsInitList5.34M
) {
472
78
      if (ThisPrec == prec::Assignment) {
473
75
        Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists)
474
75
          << Actions.getExprRange(RHS.get());
475
75
      } else 
if (3
ColonLoc.isValid()3
) {
476
1
        Diag(ColonLoc, diag::err_init_list_bin_op)
477
1
          << /*RHS*/1 << ":"
478
1
          << Actions.getExprRange(RHS.get());
479
1
        LHS = ExprError();
480
2
      } else {
481
2
        Diag(OpToken, diag::err_init_list_bin_op)
482
2
          << /*RHS*/1 << PP.getSpelling(OpToken)
483
2
          << Actions.getExprRange(RHS.get());
484
2
        LHS = ExprError();
485
2
      }
486
78
    }
487
5.34M
488
5.34M
    ExprResult OrigLHS = LHS;
489
5.34M
    if (!LHS.isInvalid()) {
490
5.34M
      // Combine the LHS and RHS into the LHS (e.g. build AST).
491
5.34M
      if (TernaryMiddle.isInvalid()) {
492
5.21M
        // If we're using '>>' as an operator within a template
493
5.21M
        // argument list (in C++98), suggest the addition of
494
5.21M
        // parentheses so that the code remains well-formed in C++0x.
495
5.21M
        if (!GreaterThanIsOperator && 
OpToken.is(tok::greatergreater)127k
)
496
4
          SuggestParentheses(OpToken.getLocation(),
497
4
                             diag::warn_cxx11_right_shift_in_template_arg,
498
4
                         SourceRange(Actions.getExprRange(LHS.get()).getBegin(),
499
4
                                     Actions.getExprRange(RHS.get()).getEnd()));
500
5.21M
501
5.21M
        LHS = Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(),
502
5.21M
                                 OpToken.getKind(), LHS.get(), RHS.get());
503
5.21M
504
5.21M
      } else {
505
131k
        LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc,
506
131k
                                         LHS.get(), TernaryMiddle.get(),
507
131k
                                         RHS.get());
508
131k
      }
509
5.34M
      // In this case, ActOnBinOp or ActOnConditionalOp performed the
510
5.34M
      // CorrectDelayedTyposInExpr check.
511
5.34M
      if (!getLangOpts().CPlusPlus)
512
1.42M
        continue;
513
3.92M
    }
514
3.92M
515
3.92M
    // Ensure potential typos aren't left undiagnosed.
516
3.92M
    if (LHS.isInvalid()) {
517
5.40k
      Actions.CorrectDelayedTyposInExpr(OrigLHS);
518
5.40k
      Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
519
5.40k
      Actions.CorrectDelayedTyposInExpr(RHS);
520
5.40k
    }
521
3.92M
  }
522
39.3M
}
523
524
/// Parse a cast-expression, or, if \p isUnaryExpression is true,
525
/// parse a unary-expression.
526
///
527
/// \p isAddressOfOperand exists because an id-expression that is the
528
/// operand of address-of gets special treatment due to member pointers.
529
///
530
ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
531
                                       bool isAddressOfOperand,
532
                                       TypeCastState isTypeCast,
533
40.3M
                                       bool isVectorLiteral) {
534
40.3M
  bool NotCastExpr;
535
40.3M
  ExprResult Res = ParseCastExpression(isUnaryExpression,
536
40.3M
                                       isAddressOfOperand,
537
40.3M
                                       NotCastExpr,
538
40.3M
                                       isTypeCast,
539
40.3M
                                       isVectorLiteral);
540
40.3M
  if (NotCastExpr)
541
8.35k
    Diag(Tok, diag::err_expected_expression);
542
40.3M
  return Res;
543
40.3M
}
544
545
namespace {
546
class CastExpressionIdValidator final : public CorrectionCandidateCallback {
547
 public:
548
  CastExpressionIdValidator(Token Next, bool AllowTypes, bool AllowNonTypes)
549
14.5M
      : NextToken(Next), AllowNonTypes(AllowNonTypes) {
550
14.5M
    WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes;
551
14.5M
  }
552
553
372
  bool ValidateCandidate(const TypoCorrection &candidate) override {
554
372
    NamedDecl *ND = candidate.getCorrectionDecl();
555
372
    if (!ND)
556
11
      return candidate.isKeyword();
557
361
558
361
    if (isa<TypeDecl>(ND))
559
22
      return WantTypeSpecifiers;
560
339
561
339
    if (!AllowNonTypes || 
!CorrectionCandidateCallback::ValidateCandidate(candidate)331
)
562
8
      return false;
563
331
564
331
    if (!NextToken.isOneOf(tok::equal, tok::arrow, tok::period))
565
257
      return true;
566
74
567
74
    for (auto *C : candidate) {
568
74
      NamedDecl *ND = C->getUnderlyingDecl();
569
74
      if (isa<ValueDecl>(ND) && 
!isa<FunctionDecl>(ND)71
)
570
65
        return true;
571
74
    }
572
74
    
return false9
;
573
74
  }
574
575
1.32k
  std::unique_ptr<CorrectionCandidateCallback> clone() override {
576
1.32k
    return llvm::make_unique<CastExpressionIdValidator>(*this);
577
1.32k
  }
578
579
 private:
580
  Token NextToken;
581
  bool AllowNonTypes;
582
};
583
}
584
585
/// Parse a cast-expression, or, if \pisUnaryExpression is true, parse
586
/// a unary-expression.
587
///
588
/// \p isAddressOfOperand exists because an id-expression that is the operand
589
/// of address-of gets special treatment due to member pointers. NotCastExpr
590
/// is set to true if the token is not the start of a cast-expression, and no
591
/// diagnostic is emitted in this case and no tokens are consumed.
592
///
593
/// \verbatim
594
///       cast-expression: [C99 6.5.4]
595
///         unary-expression
596
///         '(' type-name ')' cast-expression
597
///
598
///       unary-expression:  [C99 6.5.3]
599
///         postfix-expression
600
///         '++' unary-expression
601
///         '--' unary-expression
602
/// [Coro]  'co_await' cast-expression
603
///         unary-operator cast-expression
604
///         'sizeof' unary-expression
605
///         'sizeof' '(' type-name ')'
606
/// [C++11] 'sizeof' '...' '(' identifier ')'
607
/// [GNU]   '__alignof' unary-expression
608
/// [GNU]   '__alignof' '(' type-name ')'
609
/// [C11]   '_Alignof' '(' type-name ')'
610
/// [C++11] 'alignof' '(' type-id ')'
611
/// [GNU]   '&&' identifier
612
/// [C++11] 'noexcept' '(' expression ')' [C++11 5.3.7]
613
/// [C++]   new-expression
614
/// [C++]   delete-expression
615
///
616
///       unary-operator: one of
617
///         '&'  '*'  '+'  '-'  '~'  '!'
618
/// [GNU]   '__extension__'  '__real'  '__imag'
619
///
620
///       primary-expression: [C99 6.5.1]
621
/// [C99]   identifier
622
/// [C++]   id-expression
623
///         constant
624
///         string-literal
625
/// [C++]   boolean-literal  [C++ 2.13.5]
626
/// [C++11] 'nullptr'        [C++11 2.14.7]
627
/// [C++11] user-defined-literal
628
///         '(' expression ')'
629
/// [C11]   generic-selection
630
///         '__func__'        [C99 6.4.2.2]
631
/// [GNU]   '__FUNCTION__'
632
/// [MS]    '__FUNCDNAME__'
633
/// [MS]    'L__FUNCTION__'
634
/// [MS]    '__FUNCSIG__'
635
/// [MS]    'L__FUNCSIG__'
636
/// [GNU]   '__PRETTY_FUNCTION__'
637
/// [GNU]   '(' compound-statement ')'
638
/// [GNU]   '__builtin_va_arg' '(' assignment-expression ',' type-name ')'
639
/// [GNU]   '__builtin_offsetof' '(' type-name ',' offsetof-member-designator')'
640
/// [GNU]   '__builtin_choose_expr' '(' assign-expr ',' assign-expr ','
641
///                                     assign-expr ')'
642
/// [GNU]   '__builtin_FILE' '(' ')'
643
/// [GNU]   '__builtin_FUNCTION' '(' ')'
644
/// [GNU]   '__builtin_LINE' '(' ')'
645
/// [CLANG] '__builtin_COLUMN' '(' ')'
646
/// [GNU]   '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
647
/// [GNU]   '__null'
648
/// [OBJC]  '[' objc-message-expr ']'
649
/// [OBJC]  '\@selector' '(' objc-selector-arg ')'
650
/// [OBJC]  '\@protocol' '(' identifier ')'
651
/// [OBJC]  '\@encode' '(' type-name ')'
652
/// [OBJC]  objc-string-literal
653
/// [C++]   simple-type-specifier '(' expression-list[opt] ')'      [C++ 5.2.3]
654
/// [C++11] simple-type-specifier braced-init-list                  [C++11 5.2.3]
655
/// [C++]   typename-specifier '(' expression-list[opt] ')'         [C++ 5.2.3]
656
/// [C++11] typename-specifier braced-init-list                     [C++11 5.2.3]
657
/// [C++]   'const_cast' '<' type-name '>' '(' expression ')'       [C++ 5.2p1]
658
/// [C++]   'dynamic_cast' '<' type-name '>' '(' expression ')'     [C++ 5.2p1]
659
/// [C++]   'reinterpret_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
660
/// [C++]   'static_cast' '<' type-name '>' '(' expression ')'      [C++ 5.2p1]
661
/// [C++]   'typeid' '(' expression ')'                             [C++ 5.2p1]
662
/// [C++]   'typeid' '(' type-id ')'                                [C++ 5.2p1]
663
/// [C++]   'this'          [C++ 9.3.2]
664
/// [G++]   unary-type-trait '(' type-id ')'
665
/// [G++]   binary-type-trait '(' type-id ',' type-id ')'           [TODO]
666
/// [EMBT]  array-type-trait '(' type-id ',' integer ')'
667
/// [clang] '^' block-literal
668
///
669
///       constant: [C99 6.4.4]
670
///         integer-constant
671
///         floating-constant
672
///         enumeration-constant -> identifier
673
///         character-constant
674
///
675
///       id-expression: [C++ 5.1]
676
///                   unqualified-id
677
///                   qualified-id
678
///
679
///       unqualified-id: [C++ 5.1]
680
///                   identifier
681
///                   operator-function-id
682
///                   conversion-function-id
683
///                   '~' class-name
684
///                   template-id
685
///
686
///       new-expression: [C++ 5.3.4]
687
///                   '::'[opt] 'new' new-placement[opt] new-type-id
688
///                                     new-initializer[opt]
689
///                   '::'[opt] 'new' new-placement[opt] '(' type-id ')'
690
///                                     new-initializer[opt]
691
///
692
///       delete-expression: [C++ 5.3.5]
693
///                   '::'[opt] 'delete' cast-expression
694
///                   '::'[opt] 'delete' '[' ']' cast-expression
695
///
696
/// [GNU/Embarcadero] unary-type-trait:
697
///                   '__is_arithmetic'
698
///                   '__is_floating_point'
699
///                   '__is_integral'
700
///                   '__is_lvalue_expr'
701
///                   '__is_rvalue_expr'
702
///                   '__is_complete_type'
703
///                   '__is_void'
704
///                   '__is_array'
705
///                   '__is_function'
706
///                   '__is_reference'
707
///                   '__is_lvalue_reference'
708
///                   '__is_rvalue_reference'
709
///                   '__is_fundamental'
710
///                   '__is_object'
711
///                   '__is_scalar'
712
///                   '__is_compound'
713
///                   '__is_pointer'
714
///                   '__is_member_object_pointer'
715
///                   '__is_member_function_pointer'
716
///                   '__is_member_pointer'
717
///                   '__is_const'
718
///                   '__is_volatile'
719
///                   '__is_trivial'
720
///                   '__is_standard_layout'
721
///                   '__is_signed'
722
///                   '__is_unsigned'
723
///
724
/// [GNU] unary-type-trait:
725
///                   '__has_nothrow_assign'
726
///                   '__has_nothrow_copy'
727
///                   '__has_nothrow_constructor'
728
///                   '__has_trivial_assign'                  [TODO]
729
///                   '__has_trivial_copy'                    [TODO]
730
///                   '__has_trivial_constructor'
731
///                   '__has_trivial_destructor'
732
///                   '__has_virtual_destructor'
733
///                   '__is_abstract'                         [TODO]
734
///                   '__is_class'
735
///                   '__is_empty'                            [TODO]
736
///                   '__is_enum'
737
///                   '__is_final'
738
///                   '__is_pod'
739
///                   '__is_polymorphic'
740
///                   '__is_sealed'                           [MS]
741
///                   '__is_trivial'
742
///                   '__is_union'
743
///                   '__has_unique_object_representations'
744
///
745
/// [Clang] unary-type-trait:
746
///                   '__is_aggregate'
747
///                   '__trivially_copyable'
748
///
749
///       binary-type-trait:
750
/// [GNU]             '__is_base_of'
751
/// [MS]              '__is_convertible_to'
752
///                   '__is_convertible'
753
///                   '__is_same'
754
///
755
/// [Embarcadero] array-type-trait:
756
///                   '__array_rank'
757
///                   '__array_extent'
758
///
759
/// [Embarcadero] expression-trait:
760
///                   '__is_lvalue_expr'
761
///                   '__is_rvalue_expr'
762
/// \endverbatim
763
///
764
ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
765
                                       bool isAddressOfOperand,
766
                                       bool &NotCastExpr,
767
                                       TypeCastState isTypeCast,
768
40.5M
                                       bool isVectorLiteral) {
769
40.5M
  ExprResult Res;
770
40.5M
  tok::TokenKind SavedKind = Tok.getKind();
771
40.5M
  auto SavedType = PreferredType;
772
40.5M
  NotCastExpr = false;
773
40.5M
774
40.5M
  // This handles all of cast-expression, unary-expression, postfix-expression,
775
40.5M
  // and primary-expression.  We handle them together like this for efficiency
776
40.5M
  // and to simplify handling of an expression starting with a '(' token: which
777
40.5M
  // may be one of a parenthesized expression, cast-expression, compound literal
778
40.5M
  // expression, or statement expression.
779
40.5M
  //
780
40.5M
  // If the parsed tokens consist of a primary-expression, the cases below
781
40.5M
  // break out of the switch;  at the end we call ParsePostfixExpressionSuffix
782
40.5M
  // to handle the postfix expression suffixes.  Cases that cannot be followed
783
40.5M
  // by postfix exprs should return without invoking
784
40.5M
  // ParsePostfixExpressionSuffix.
785
40.5M
  switch (SavedKind) {
786
40.5M
  case tok::l_paren: {
787
5.87M
    // If this expression is limited to being a unary-expression, the parent can
788
5.87M
    // not start a cast expression.
789
5.87M
    ParenParseOption ParenExprType =
790
5.87M
        (isUnaryExpression && 
!getLangOpts().CPlusPlus302
) ?
CompoundLiteral302
791
5.87M
                                                        : 
CastExpr5.86M
;
792
5.87M
    ParsedType CastTy;
793
5.87M
    SourceLocation RParenLoc;
794
5.87M
    Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
795
5.87M
                               isTypeCast == IsTypeCast, CastTy, RParenLoc);
796
5.87M
797
5.87M
    if (isVectorLiteral)
798
150
        return Res;
799
5.87M
800
5.87M
    switch (ParenExprType) {
801
5.87M
    
case SimpleExpr: break2.17M
; // Nothing else to do.
802
5.87M
    
case CompoundStmt: break11.2k
; // Nothing else to do.
803
5.87M
    case CompoundLiteral:
804
29.8k
      // We parsed '(' type-name ')' '{' ... '}'.  If any suffixes of
805
29.8k
      // postfix-expression exist, parse them now.
806
29.8k
      break;
807
5.87M
    case CastExpr:
808
3.64M
      // We have parsed the cast-expression and no postfix-expr pieces are
809
3.64M
      // following.
810
3.64M
      return Res;
811
5.87M
    case FoldExpr:
812
116
      // We only parsed a fold-expression. There might be postfix-expr pieces
813
116
      // afterwards; parse them now.
814
116
      break;
815
2.22M
    }
816
2.22M
817
2.22M
    break;
818
2.22M
  }
819
2.22M
820
2.22M
    // primary-expression
821
6.18M
  case tok::numeric_constant:
822
6.18M
    // constant: integer-constant
823
6.18M
    // constant: floating-constant
824
6.18M
825
6.18M
    Res = Actions.ActOnNumericConstant(Tok, /*UDLScope*/getCurScope());
826
6.18M
    ConsumeToken();
827
6.18M
    break;
828
2.22M
829
2.22M
  case tok::kw_true:
830
575k
  case tok::kw_false:
831
575k
    Res = ParseCXXBoolLiteral();
832
575k
    break;
833
575k
834
575k
  case tok::kw___objc_yes:
835
164
  case tok::kw___objc_no:
836
164
      return ParseObjCBoolLiteral();
837
164
838
134k
  case tok::kw_nullptr:
839
134k
    Diag(Tok, diag::warn_cxx98_compat_nullptr);
840
134k
    return Actions.ActOnCXXNullPtrLiteral(ConsumeToken());
841
164
842
4.24M
  case tok::annot_primary_expr:
843
4.24M
    assert(Res.get() == nullptr && "Stray primary-expression annotation?");
844
4.24M
    Res = getExprAnnotation(Tok);
845
4.24M
    ConsumeAnnotationToken();
846
4.24M
    if (!Res.isInvalid() && 
Tok.is(tok::less)4.24M
)
847
76
      checkPotentialAngleBracket(Res);
848
4.24M
    break;
849
164
850
1.42k
  case tok::kw___super:
851
1.42k
  case tok::kw_decltype:
852
1.42k
    // Annotate the token and tail recurse.
853
1.42k
    if (TryAnnotateTypeOrScopeToken())
854
0
      return ExprError();
855
1.42k
    assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super));
856
1.42k
    return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
857
1.42k
858
15.8M
  case tok::identifier: {      // primary-expression: identifier
859
15.8M
                               // unqualified-id: identifier
860
15.8M
                               // constant: enumeration-constant
861
15.8M
    // Turn a potentially qualified name into a annot_typename or
862
15.8M
    // annot_cxxscope if it would be valid.  This handles things like x::y, etc.
863
15.8M
    if (getLangOpts().CPlusPlus) {
864
10.0M
      // Avoid the unnecessary parse-time lookup in the common case
865
10.0M
      // where the syntax forbids a type.
866
10.0M
      const Token &Next = NextToken();
867
10.0M
868
10.0M
      // If this identifier was reverted from a token ID, and the next token
869
10.0M
      // is a parenthesis, this is likely to be a use of a type trait. Check
870
10.0M
      // those tokens.
871
10.0M
      if (Next.is(tok::l_paren) &&
872
10.0M
          
Tok.is(tok::identifier)1.23M
&&
873
10.0M
          
Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()1.23M
) {
874
104
        IdentifierInfo *II = Tok.getIdentifierInfo();
875
104
        // Build up the mapping of revertible type traits, for future use.
876
104
        if (RevertibleTypeTraits.empty()) {
877
153
#define RTT_JOIN(X,Y) X##Y
878
3
#define REVERTIBLE_TYPE_TRAIT(Name)                         \
879
153
          RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] \
880
153
            = RTT_JOIN(tok::kw_,Name)
881
3
882
3
          REVERTIBLE_TYPE_TRAIT(__is_abstract);
883
3
          REVERTIBLE_TYPE_TRAIT(__is_aggregate);
884
3
          REVERTIBLE_TYPE_TRAIT(__is_arithmetic);
885
3
          REVERTIBLE_TYPE_TRAIT(__is_array);
886
3
          REVERTIBLE_TYPE_TRAIT(__is_assignable);
887
3
          REVERTIBLE_TYPE_TRAIT(__is_base_of);
888
3
          REVERTIBLE_TYPE_TRAIT(__is_class);
889
3
          REVERTIBLE_TYPE_TRAIT(__is_complete_type);
890
3
          REVERTIBLE_TYPE_TRAIT(__is_compound);
891
3
          REVERTIBLE_TYPE_TRAIT(__is_const);
892
3
          REVERTIBLE_TYPE_TRAIT(__is_constructible);
893
3
          REVERTIBLE_TYPE_TRAIT(__is_convertible);
894
3
          REVERTIBLE_TYPE_TRAIT(__is_convertible_to);
895
3
          REVERTIBLE_TYPE_TRAIT(__is_destructible);
896
3
          REVERTIBLE_TYPE_TRAIT(__is_empty);
897
3
          REVERTIBLE_TYPE_TRAIT(__is_enum);
898
3
          REVERTIBLE_TYPE_TRAIT(__is_floating_point);
899
3
          REVERTIBLE_TYPE_TRAIT(__is_final);
900
3
          REVERTIBLE_TYPE_TRAIT(__is_function);
901
3
          REVERTIBLE_TYPE_TRAIT(__is_fundamental);
902
3
          REVERTIBLE_TYPE_TRAIT(__is_integral);
903
3
          REVERTIBLE_TYPE_TRAIT(__is_interface_class);
904
3
          REVERTIBLE_TYPE_TRAIT(__is_literal);
905
3
          REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr);
906
3
          REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference);
907
3
          REVERTIBLE_TYPE_TRAIT(__is_member_function_pointer);
908
3
          REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer);
909
3
          REVERTIBLE_TYPE_TRAIT(__is_member_pointer);
910
3
          REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
911
3
          REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
912
3
          REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
913
3
          REVERTIBLE_TYPE_TRAIT(__is_object);
914
3
          REVERTIBLE_TYPE_TRAIT(__is_pod);
915
3
          REVERTIBLE_TYPE_TRAIT(__is_pointer);
916
3
          REVERTIBLE_TYPE_TRAIT(__is_polymorphic);
917
3
          REVERTIBLE_TYPE_TRAIT(__is_reference);
918
3
          REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr);
919
3
          REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference);
920
3
          REVERTIBLE_TYPE_TRAIT(__is_same);
921
3
          REVERTIBLE_TYPE_TRAIT(__is_scalar);
922
3
          REVERTIBLE_TYPE_TRAIT(__is_sealed);
923
3
          REVERTIBLE_TYPE_TRAIT(__is_signed);
924
3
          REVERTIBLE_TYPE_TRAIT(__is_standard_layout);
925
3
          REVERTIBLE_TYPE_TRAIT(__is_trivial);
926
3
          REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable);
927
3
          REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible);
928
3
          REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable);
929
3
          REVERTIBLE_TYPE_TRAIT(__is_union);
930
3
          REVERTIBLE_TYPE_TRAIT(__is_unsigned);
931
3
          REVERTIBLE_TYPE_TRAIT(__is_void);
932
3
          REVERTIBLE_TYPE_TRAIT(__is_volatile);
933
3
#undef REVERTIBLE_TYPE_TRAIT
934
3
#undef RTT_JOIN
935
3
        }
936
104
937
104
        // If we find that this is in fact the name of a type trait,
938
104
        // update the token kind in place and parse again to treat it as
939
104
        // the appropriate kind of type trait.
940
104
        llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known
941
104
          = RevertibleTypeTraits.find(II);
942
104
        if (Known != RevertibleTypeTraits.end()) {
943
104
          Tok.setKind(Known->second);
944
104
          return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
945
104
                                     NotCastExpr, isTypeCast);
946
104
        }
947
10.0M
      }
948
10.0M
949
10.0M
      if ((!ColonIsSacred && 
Next.is(tok::colon)9.68M
) ||
950
10.0M
          Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
951
10.0M
                       tok::l_brace)) {
952
2.55M
        // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
953
2.55M
        if (TryAnnotateTypeOrScopeToken())
954
22
          return ExprError();
955
2.55M
        if (!Tok.is(tok::identifier))
956
1.32M
          return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
957
14.5M
      }
958
10.0M
    }
959
14.5M
960
14.5M
    // Consume the identifier so that we can see if it is followed by a '(' or
961
14.5M
    // '.'.
962
14.5M
    IdentifierInfo &II = *Tok.getIdentifierInfo();
963
14.5M
    SourceLocation ILoc = ConsumeToken();
964
14.5M
965
14.5M
    // Support 'Class.property' and 'super.property' notation.
966
14.5M
    if (getLangOpts().ObjC && 
Tok.is(tok::period)93.5k
&&
967
14.5M
        
(3.48k
Actions.getTypeName(II, ILoc, getCurScope())3.48k
||
968
3.48k
         // Allow the base to be 'super' if in an objc-method.
969
3.48k
         
(3.30k
&II == Ident_super3.30k
&&
getCurScope()->isInObjcMethodScope()79
))) {
970
256
      ConsumeToken();
971
256
972
256
      if (Tok.is(tok::code_completion) && 
&II != Ident_super4
) {
973
3
        Actions.CodeCompleteObjCClassPropertyRefExpr(
974
3
            getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc);
975
3
        cutOffParsing();
976
3
        return ExprError();
977
3
      }
978
253
      // Allow either an identifier or the keyword 'class' (in C++).
979
253
      if (Tok.isNot(tok::identifier) &&
980
253
          
!(2
getLangOpts().CPlusPlus2
&&
Tok.is(tok::kw_class)1
)) {
981
1
        Diag(Tok, diag::err_expected_property_name);
982
1
        return ExprError();
983
1
      }
984
252
      IdentifierInfo &PropertyName = *Tok.getIdentifierInfo();
985
252
      SourceLocation PropertyLoc = ConsumeToken();
986
252
987
252
      Res = Actions.ActOnClassPropertyRefExpr(II, PropertyName,
988
252
                                              ILoc, PropertyLoc);
989
252
      break;
990
252
    }
991
14.5M
992
14.5M
    // In an Objective-C method, if we have "super" followed by an identifier,
993
14.5M
    // the token sequence is ill-formed. However, if there's a ':' or ']' after
994
14.5M
    // that identifier, this is probably a message send with a missing open
995
14.5M
    // bracket. Treat it as such.
996
14.5M
    if (getLangOpts().ObjC && 
&II == Ident_super93.3k
&&
!InMessageExpression256
&&
997
14.5M
        
getCurScope()->isInObjcMethodScope()34
&&
998
14.5M
        
(31
(31
Tok.is(tok::identifier)31
&&
999
31
         
(28
NextToken().is(tok::colon)28
||
NextToken().is(tok::r_square)2
)) ||
1000
31
         
Tok.is(tok::code_completion)3
)) {
1001
29
      Res = ParseObjCMessageExpressionBody(SourceLocation(), ILoc, nullptr,
1002
29
                                           nullptr);
1003
29
      break;
1004
29
    }
1005
14.5M
1006
14.5M
    // If we have an Objective-C class name followed by an identifier
1007
14.5M
    // and either ':' or ']', this is an Objective-C class message
1008
14.5M
    // send that's missing the opening '['. Recovery
1009
14.5M
    // appropriately. Also take this path if we're performing code
1010
14.5M
    // completion after an Objective-C class name.
1011
14.5M
    if (getLangOpts().ObjC &&
1012
14.5M
        
(93.3k
(93.3k
Tok.is(tok::identifier)93.3k
&&
!InMessageExpression5.85k
) ||
1013
93.3k
         
Tok.is(tok::code_completion)93.1k
)) {
1014
159
      const Token& Next = NextToken();
1015
159
      if (Tok.is(tok::code_completion) ||
1016
159
          
Next.is(tok::colon)117
||
Next.is(tok::r_square)114
)
1017
117
        if (ParsedType Typ = Actions.getTypeName(II, ILoc, getCurScope()))
1018
74
          if (Typ.get()->isObjCObjectOrInterfaceType()) {
1019
74
            // Fake up a Declarator to use with ActOnTypeName.
1020
74
            DeclSpec DS(AttrFactory);
1021
74
            DS.SetRangeStart(ILoc);
1022
74
            DS.SetRangeEnd(ILoc);
1023
74
            const char *PrevSpec = nullptr;
1024
74
            unsigned DiagID;
1025
74
            DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ,
1026
74
                               Actions.getASTContext().getPrintingPolicy());
1027
74
1028
74
            Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext);
1029
74
            TypeResult Ty = Actions.ActOnTypeName(getCurScope(),
1030
74
                                                  DeclaratorInfo);
1031
74
            if (Ty.isInvalid())
1032
0
              break;
1033
74
1034
74
            Res = ParseObjCMessageExpressionBody(SourceLocation(),
1035
74
                                                 SourceLocation(),
1036
74
                                                 Ty.get(), nullptr);
1037
74
            break;
1038
74
          }
1039
159
    }
1040
14.5M
1041
14.5M
    // Make sure to pass down the right value for isAddressOfOperand.
1042
14.5M
    if (isAddressOfOperand && 
isPostfixExpressionSuffixStart()249k
)
1043
75.4k
      isAddressOfOperand = false;
1044
14.5M
1045
14.5M
    // Function designators are allowed to be undeclared (C99 6.5.1p2), so we
1046
14.5M
    // need to know whether or not this identifier is a function designator or
1047
14.5M
    // not.
1048
14.5M
    UnqualifiedId Name;
1049
14.5M
    CXXScopeSpec ScopeSpec;
1050
14.5M
    SourceLocation TemplateKWLoc;
1051
14.5M
    Token Replacement;
1052
14.5M
    CastExpressionIdValidator Validator(
1053
14.5M
        /*Next=*/Tok,
1054
14.5M
        /*AllowTypes=*/isTypeCast != NotTypeCast,
1055
14.5M
        /*AllowNonTypes=*/isTypeCast != IsTypeCast);
1056
14.5M
    Validator.IsAddressOfOperand = isAddressOfOperand;
1057
14.5M
    if (Tok.isOneOf(tok::periodstar, tok::arrowstar)) {
1058
105
      Validator.WantExpressionKeywords = false;
1059
105
      Validator.WantRemainingKeywords = false;
1060
14.5M
    } else {
1061
14.5M
      Validator.WantRemainingKeywords = Tok.isNot(tok::r_paren);
1062
14.5M
    }
1063
14.5M
    Name.setIdentifier(&II, ILoc);
1064
14.5M
    Res = Actions.ActOnIdExpression(
1065
14.5M
        getCurScope(), ScopeSpec, TemplateKWLoc, Name, Tok.is(tok::l_paren),
1066
14.5M
        isAddressOfOperand, &Validator,
1067
14.5M
        /*IsInlineAsmIdentifier=*/false,
1068
14.5M
        Tok.is(tok::r_paren) ? 
nullptr3.77M
:
&Replacement10.7M
);
1069
14.5M
    if (!Res.isInvalid() && 
Res.isUnset()14.5M
) {
1070
1
      UnconsumeToken(Replacement);
1071
1
      return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
1072
1
                                 NotCastExpr, isTypeCast);
1073
1
    }
1074
14.5M
    if (!Res.isInvalid() && 
Tok.is(tok::less)14.5M
)
1075
260k
      checkPotentialAngleBracket(Res);
1076
14.5M
    break;
1077
14.5M
  }
1078
14.5M
  case tok::char_constant:     // constant: character-constant
1079
77.9k
  case tok::wide_char_constant:
1080
77.9k
  case tok::utf8_char_constant:
1081
77.9k
  case tok::utf16_char_constant:
1082
77.9k
  case tok::utf32_char_constant:
1083
77.9k
    Res = Actions.ActOnCharacterConstant(Tok, /*UDLScope*/getCurScope());
1084
77.9k
    ConsumeToken();
1085
77.9k
    break;
1086
77.9k
  case tok::kw___func__:       // primary-expression: __func__ [C99 6.4.2.2]
1087
2.27k
  case tok::kw___FUNCTION__:   // primary-expression: __FUNCTION__ [GNU]
1088
2.27k
  case tok::kw___FUNCDNAME__:   // primary-expression: __FUNCDNAME__ [MS]
1089
2.27k
  case tok::kw___FUNCSIG__:     // primary-expression: __FUNCSIG__ [MS]
1090
2.27k
  case tok::kw_L__FUNCTION__:   // primary-expression: L__FUNCTION__ [MS]
1091
2.27k
  case tok::kw_L__FUNCSIG__:    // primary-expression: L__FUNCSIG__ [MS]
1092
2.27k
  case tok::kw___PRETTY_FUNCTION__:  // primary-expression: __P..Y_F..N__ [GNU]
1093
2.27k
    Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind);
1094
2.27k
    ConsumeToken();
1095
2.27k
    break;
1096
2.63M
  case tok::string_literal:    // primary-expression: string-literal
1097
2.63M
  case tok::wide_string_literal:
1098
2.63M
  case tok::utf8_string_literal:
1099
2.63M
  case tok::utf16_string_literal:
1100
2.63M
  case tok::utf32_string_literal:
1101
2.63M
    Res = ParseStringLiteralExpression(true);
1102
2.63M
    break;
1103
2.63M
  case tok::kw__Generic:   // primary-expression: generic-selection [C11 6.5.1]
1104
237
    Res = ParseGenericSelectionExpression();
1105
237
    break;
1106
2.63M
  case tok::kw___builtin_available:
1107
12
    return ParseAvailabilityCheckExpr(Tok.getLocation());
1108
2.63M
  case tok::kw___builtin_va_arg:
1109
19.6k
  case tok::kw___builtin_offsetof:
1110
19.6k
  case tok::kw___builtin_choose_expr:
1111
19.6k
  case tok::kw___builtin_astype: // primary-expression: [OCL] as_type()
1112
19.6k
  case tok::kw___builtin_convertvector:
1113
19.6k
  case tok::kw___builtin_COLUMN:
1114
19.6k
  case tok::kw___builtin_FILE:
1115
19.6k
  case tok::kw___builtin_FUNCTION:
1116
19.6k
  case tok::kw___builtin_LINE:
1117
19.6k
    return ParseBuiltinPrimaryExpression();
1118
19.6k
  case tok::kw___null:
1119
6.96k
    return Actions.ActOnGNUNullExpr(ConsumeToken());
1120
19.6k
1121
278k
  case tok::plusplus:      // unary-expression: '++' unary-expression [C99]
1122
278k
  case tok::minusminus: {  // unary-expression: '--' unary-expression [C99]
1123
278k
    // C++ [expr.unary] has:
1124
278k
    //   unary-expression:
1125
278k
    //     ++ cast-expression
1126
278k
    //     -- cast-expression
1127
278k
    Token SavedTok = Tok;
1128
278k
    ConsumeToken();
1129
278k
1130
278k
    PreferredType.enterUnary(Actions, Tok.getLocation(), SavedTok.getKind(),
1131
278k
                             SavedTok.getLocation());
1132
278k
    // One special case is implicitly handled here: if the preceding tokens are
1133
278k
    // an ambiguous cast expression, such as "(T())++", then we recurse to
1134
278k
    // determine whether the '++' is prefix or postfix.
1135
278k
    Res = ParseCastExpression(!getLangOpts().CPlusPlus,
1136
278k
                              /*isAddressOfOperand*/false, NotCastExpr,
1137
278k
                              NotTypeCast);
1138
278k
    if (NotCastExpr) {
1139
7
      // If we return with NotCastExpr = true, we must not consume any tokens,
1140
7
      // so put the token back where we found it.
1141
7
      assert(Res.isInvalid());
1142
7
      UnconsumeToken(SavedTok);
1143
7
      return ExprError();
1144
7
    }
1145
278k
    if (!Res.isInvalid())
1146
278k
      Res = Actions.ActOnUnaryOp(getCurScope(), SavedTok.getLocation(),
1147
278k
                                 SavedKind, Res.get());
1148
278k
    return Res;
1149
278k
  }
1150
278k
  case tok::amp: {         // unary-expression: '&' cast-expression
1151
263k
    // Special treatment because of member pointers
1152
263k
    SourceLocation SavedLoc = ConsumeToken();
1153
263k
    PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc);
1154
263k
    Res = ParseCastExpression(false, true);
1155
263k
    if (!Res.isInvalid())
1156
263k
      Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
1157
263k
    return Res;
1158
278k
  }
1159
278k
1160
1.57M
  case tok::star:          // unary-expression: '*' cast-expression
1161
1.57M
  case tok::plus:          // unary-expression: '+' cast-expression
1162
1.57M
  case tok::minus:         // unary-expression: '-' cast-expression
1163
1.57M
  case tok::tilde:         // unary-expression: '~' cast-expression
1164
1.57M
  case tok::exclaim:       // unary-expression: '!' cast-expression
1165
1.57M
  case tok::kw___real:     // unary-expression: '__real' cast-expression [GNU]
1166
1.57M
  case tok::kw___imag: {   // unary-expression: '__imag' cast-expression [GNU]
1167
1.57M
    SourceLocation SavedLoc = ConsumeToken();
1168
1.57M
    PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc);
1169
1.57M
    Res = ParseCastExpression(false);
1170
1.57M
    if (!Res.isInvalid())
1171
1.57M
      Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
1172
1.57M
    return Res;
1173
1.57M
  }
1174
1.57M
1175
1.57M
  case tok::kw_co_await: {  // unary-expression: 'co_await' cast-expression
1176
110
    SourceLocation CoawaitLoc = ConsumeToken();
1177
110
    Res = ParseCastExpression(false);
1178
110
    if (!Res.isInvalid())
1179
110
      Res = Actions.ActOnCoawaitExpr(getCurScope(), CoawaitLoc, Res.get());
1180
110
    return Res;
1181
1.57M
  }
1182
1.57M
1183
1.57M
  case tok::kw___extension__:{//unary-expression:'__extension__' cast-expr [GNU]
1184
23.1k
    // __extension__ silences extension warnings in the subexpression.
1185
23.1k
    ExtensionRAIIObject O(Diags);  // Use RAII to do this.
1186
23.1k
    SourceLocation SavedLoc = ConsumeToken();
1187
23.1k
    Res = ParseCastExpression(false);
1188
23.1k
    if (!Res.isInvalid())
1189
23.1k
      Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get());
1190
23.1k
    return Res;
1191
1.57M
  }
1192
1.57M
  case tok::kw__Alignof:   // unary-expression: '_Alignof' '(' type-name ')'
1193
204
    if (!getLangOpts().C11)
1194
140
      Diag(Tok, diag::ext_c11_alignment) << Tok.getName();
1195
204
    LLVM_FALLTHROUGH;
1196
217k
  case tok::kw_alignof:    // unary-expression: 'alignof' '(' type-id ')'
1197
217k
  case tok::kw___alignof:  // unary-expression: '__alignof' unary-expression
1198
217k
                           // unary-expression: '__alignof' '(' type-name ')'
1199
217k
  case tok::kw_sizeof:     // unary-expression: 'sizeof' unary-expression
1200
217k
                           // unary-expression: 'sizeof' '(' type-name ')'
1201
217k
  case tok::kw_vec_step:   // unary-expression: OpenCL 'vec_step' expression
1202
217k
  // unary-expression: '__builtin_omp_required_simd_align' '(' type-name ')'
1203
217k
  case tok::kw___builtin_omp_required_simd_align:
1204
217k
    return ParseUnaryExprOrTypeTraitExpression();
1205
217k
  case tok::ampamp: {      // unary-expression: '&&' identifier
1206
274
    SourceLocation AmpAmpLoc = ConsumeToken();
1207
274
    if (Tok.isNot(tok::identifier))
1208
0
      return ExprError(Diag(Tok, diag::err_expected) << tok::identifier);
1209
274
1210
274
    if (getCurScope()->getFnParent() == nullptr)
1211
1
      return ExprError(Diag(Tok, diag::err_address_of_label_outside_fn));
1212
273
1213
273
    Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
1214
273
    LabelDecl *LD = Actions.LookupOrCreateLabel(Tok.getIdentifierInfo(),
1215
273
                                                Tok.getLocation());
1216
273
    Res = Actions.ActOnAddrLabel(AmpAmpLoc, Tok.getLocation(), LD);
1217
273
    ConsumeToken();
1218
273
    return Res;
1219
273
  }
1220
206k
  case tok::kw_const_cast:
1221
206k
  case tok::kw_dynamic_cast:
1222
206k
  case tok::kw_reinterpret_cast:
1223
206k
  case tok::kw_static_cast:
1224
206k
    Res = ParseCXXCasts();
1225
206k
    break;
1226
206k
  case tok::kw___builtin_bit_cast:
1227
90
    Res = ParseBuiltinBitCast();
1228
90
    break;
1229
206k
  case tok::kw_typeid:
1230
3.33k
    Res = ParseCXXTypeid();
1231
3.33k
    break;
1232
206k
  case tok::kw___uuidof:
1233
143
    Res = ParseCXXUuidof();
1234
143
    break;
1235
310k
  case tok::kw_this:
1236
310k
    Res = ParseCXXThis();
1237
310k
    break;
1238
206k
1239
328k
  case tok::annot_typename:
1240
328k
    if (isStartOfObjCClassMessageMissingOpenBracket()) {
1241
81
      ParsedType Type = getTypeAnnotation(Tok);
1242
81
1243
81
      // Fake up a Declarator to use with ActOnTypeName.
1244
81
      DeclSpec DS(AttrFactory);
1245
81
      DS.SetRangeStart(Tok.getLocation());
1246
81
      DS.SetRangeEnd(Tok.getLastLoc());
1247
81
1248
81
      const char *PrevSpec = nullptr;
1249
81
      unsigned DiagID;
1250
81
      DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(),
1251
81
                         PrevSpec, DiagID, Type,
1252
81
                         Actions.getASTContext().getPrintingPolicy());
1253
81
1254
81
      Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext);
1255
81
      TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
1256
81
      if (Ty.isInvalid())
1257
0
        break;
1258
81
1259
81
      ConsumeAnnotationToken();
1260
81
      Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
1261
81
                                           Ty.get(), nullptr);
1262
81
      break;
1263
81
    }
1264
328k
    LLVM_FALLTHROUGH;
1265
328k
1266
350k
  case tok::annot_decltype:
1267
350k
  case tok::kw_char:
1268
350k
  case tok::kw_wchar_t:
1269
350k
  case tok::kw_char8_t:
1270
350k
  case tok::kw_char16_t:
1271
350k
  case tok::kw_char32_t:
1272
350k
  case tok::kw_bool:
1273
350k
  case tok::kw_short:
1274
350k
  case tok::kw_int:
1275
350k
  case tok::kw_long:
1276
350k
  case tok::kw___int64:
1277
350k
  case tok::kw___int128:
1278
350k
  case tok::kw_signed:
1279
350k
  case tok::kw_unsigned:
1280
350k
  case tok::kw_half:
1281
350k
  case tok::kw_float:
1282
350k
  case tok::kw_double:
1283
350k
  case tok::kw__Float16:
1284
350k
  case tok::kw___float128:
1285
350k
  case tok::kw_void:
1286
350k
  case tok::kw_typename:
1287
350k
  case tok::kw_typeof:
1288
350k
  case tok::kw___vector:
1289
4.20M
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1290
4.20M
#include 
"clang/Basic/OpenCLImageTypes.def"350k
1291
4.20M
  {
1292
4.20M
    if (
!getLangOpts().CPlusPlus350k
) {
1293
129
      Diag(Tok, diag::err_expected_expression);
1294
129
      return ExprError();
1295
129
    }
1296
350k
1297
350k
    if (SavedKind == tok::kw_typename) {
1298
18.2k
      // postfix-expression: typename-specifier '(' expression-list[opt] ')'
1299
18.2k
      //                     typename-specifier braced-init-list
1300
18.2k
      if (TryAnnotateTypeOrScopeToken())
1301
6
        return ExprError();
1302
18.2k
1303
18.2k
      if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
1304
0
        // We are trying to parse a simple-type-specifier but might not get such
1305
0
        // a token after error recovery.
1306
0
        return ExprError();
1307
350k
    }
1308
350k
1309
350k
    // postfix-expression: simple-type-specifier '(' expression-list[opt] ')'
1310
350k
    //                     simple-type-specifier braced-init-list
1311
350k
    //
1312
350k
    DeclSpec DS(AttrFactory);
1313
350k
1314
350k
    ParseCXXSimpleTypeSpecifier(DS);
1315
350k
    if (Tok.isNot(tok::l_paren) &&
1316
350k
        
(4.43k
!getLangOpts().CPlusPlus114.43k
||
Tok.isNot(tok::l_brace)4.43k
))
1317
32
      return ExprError(Diag(Tok, diag::err_expected_lparen_after_type)
1318
32
                         << DS.getSourceRange());
1319
350k
1320
350k
    if (Tok.is(tok::l_brace))
1321
4.40k
      Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1322
350k
1323
350k
    Res = ParseCXXTypeConstructExpression(DS);
1324
350k
    break;
1325
350k
  }
1326
350k
1327
1.41M
  case tok::annot_cxxscope: { // [C++] id-expression: qualified-id
1328
1.41M
    // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
1329
1.41M
    // (We can end up in this situation after tentative parsing.)
1330
1.41M
    if (TryAnnotateTypeOrScopeToken())
1331
0
      return ExprError();
1332
1.41M
    if (!Tok.is(tok::annot_cxxscope))
1333
4
      return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
1334
4
                                 NotCastExpr, isTypeCast);
1335
1.41M
1336
1.41M
    Token Next = NextToken();
1337
1.41M
    if (Next.is(tok::annot_template_id)) {
1338
154k
      TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Next);
1339
154k
      if (TemplateId->Kind == TNK_Type_template) {
1340
0
        // We have a qualified template-id that we know refers to a
1341
0
        // type, translate it into a type and continue parsing as a
1342
0
        // cast expression.
1343
0
        CXXScopeSpec SS;
1344
0
        ParseOptionalCXXScopeSpecifier(SS, nullptr,
1345
0
                                       /*EnteringContext=*/false);
1346
0
        AnnotateTemplateIdTokenAsType();
1347
0
        return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
1348
0
                                   NotCastExpr, isTypeCast);
1349
0
      }
1350
1.41M
    }
1351
1.41M
1352
1.41M
    // Parse as an id-expression.
1353
1.41M
    Res = ParseCXXIdExpression(isAddressOfOperand);
1354
1.41M
    break;
1355
1.41M
  }
1356
1.41M
1357
1.41M
  case tok::annot_template_id: { // [C++]          template-id
1358
96.2k
    TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1359
96.2k
    if (TemplateId->Kind == TNK_Type_template) {
1360
40
      // We have a template-id that we know refers to a type,
1361
40
      // translate it into a type and continue parsing as a cast
1362
40
      // expression.
1363
40
      AnnotateTemplateIdTokenAsType();
1364
40
      return ParseCastExpression(isUnaryExpression, isAddressOfOperand,
1365
40
                                 NotCastExpr, isTypeCast);
1366
40
    }
1367
96.1k
1368
96.1k
    // Fall through to treat the template-id as an id-expression.
1369
96.1k
    LLVM_FALLTHROUGH;
1370
96.1k
  }
1371
96.1k
1372
99.6k
  case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id
1373
99.6k
    Res = ParseCXXIdExpression(isAddressOfOperand);
1374
99.6k
    break;
1375
96.1k
1376
148k
  case tok::coloncolon: {
1377
148k
    // ::foo::bar -> global qualified name etc.   If TryAnnotateTypeOrScopeToken
1378
148k
    // annotates the token, tail recurse.
1379
148k
    if (TryAnnotateTypeOrScopeToken())
1380
4
      return ExprError();
1381
148k
    if (!Tok.is(tok::coloncolon))
1382
137k
      return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
1383
11.8k
1384
11.8k
    // ::new -> [C++] new-expression
1385
11.8k
    // ::delete -> [C++] delete-expression
1386
11.8k
    SourceLocation CCLoc = ConsumeToken();
1387
11.8k
    if (Tok.is(tok::kw_new))
1388
11.8k
      return ParseCXXNewExpression(true, CCLoc);
1389
45
    if (Tok.is(tok::kw_delete))
1390
45
      return ParseCXXDeleteExpression(true, CCLoc);
1391
0
1392
0
    // This is not a type name or scope specifier, it is an invalid expression.
1393
0
    Diag(CCLoc, diag::err_expected_expression);
1394
0
    return ExprError();
1395
0
  }
1396
0
1397
11.0k
  case tok::kw_new: // [C++] new-expression
1398
11.0k
    return ParseCXXNewExpression(false, Tok.getLocation());
1399
0
1400
5.37k
  case tok::kw_delete: // [C++] delete-expression
1401
5.37k
    return ParseCXXDeleteExpression(false, Tok.getLocation());
1402
0
1403
18.3k
  case tok::kw_noexcept: { // [C++0x] 'noexcept' '(' expression ')'
1404
18.3k
    Diag(Tok, diag::warn_cxx98_compat_noexcept_expr);
1405
18.3k
    SourceLocation KeyLoc = ConsumeToken();
1406
18.3k
    BalancedDelimiterTracker T(*this, tok::l_paren);
1407
18.3k
1408
18.3k
    if (T.expectAndConsume(diag::err_expected_lparen_after, "noexcept"))
1409
0
      return ExprError();
1410
18.3k
    // C++11 [expr.unary.noexcept]p1:
1411
18.3k
    //   The noexcept operator determines whether the evaluation of its operand,
1412
18.3k
    //   which is an unevaluated operand, can throw an exception.
1413
18.3k
    EnterExpressionEvaluationContext Unevaluated(
1414
18.3k
        Actions, Sema::ExpressionEvaluationContext::Unevaluated);
1415
18.3k
    ExprResult Result = ParseExpression();
1416
18.3k
1417
18.3k
    T.consumeClose();
1418
18.3k
1419
18.3k
    if (!Result.isInvalid())
1420
18.3k
      Result = Actions.ActOnNoexceptExpr(KeyLoc, T.getOpenLocation(),
1421
18.3k
                                         Result.get(), T.getCloseLocation());
1422
18.3k
    return Result;
1423
18.3k
  }
1424
18.3k
1425
18.3k
#define TYPE_TRAIT(N,Spelling,K) \
1426
1.56M
  case tok::kw_##Spelling:
1427
24.5k
#include 
"clang/Basic/TokenKinds.def"18.3k
1428
24.5k
    return ParseTypeTrait();
1429
1.54M
1430
1.54M
  case tok::kw___array_rank:
1431
17
  case tok::kw___array_extent:
1432
17
    return ParseArrayTypeTrait();
1433
17
1434
432
  case tok::kw___is_lvalue_expr:
1435
432
  case tok::kw___is_rvalue_expr:
1436
432
    return ParseExpressionTrait();
1437
432
1438
2.56k
  case tok::at: {
1439
2.56k
    SourceLocation AtLoc = ConsumeToken();
1440
2.56k
    return ParseObjCAtExpression(AtLoc);
1441
432
  }
1442
2.71k
  case tok::caret:
1443
2.71k
    Res = ParseBlockLiteralExpression();
1444
2.71k
    break;
1445
432
  case tok::code_completion: {
1446
85
    Actions.CodeCompleteExpression(getCurScope(),
1447
85
                                   PreferredType.get(Tok.getLocation()));
1448
85
    cutOffParsing();
1449
85
    return ExprError();
1450
432
  }
1451
16.3k
  case tok::l_square:
1452
16.3k
    if (getLangOpts().CPlusPlus11) {
1453
7.13k
      if (getLangOpts().ObjC) {
1454
2.03k
        // C++11 lambda expressions and Objective-C message sends both start with a
1455
2.03k
        // square bracket.  There are three possibilities here:
1456
2.03k
        // we have a valid lambda expression, we have an invalid lambda
1457
2.03k
        // expression, or we have something that doesn't appear to be a lambda.
1458
2.03k
        // If we're in the last case, we fall back to ParseObjCMessageExpression.
1459
2.03k
        Res = TryParseLambdaExpression();
1460
2.03k
        if (!Res.isInvalid() && 
!Res.get()2.01k
)
1461
1.86k
          Res = ParseObjCMessageExpression();
1462
2.03k
        break;
1463
2.03k
      }
1464
5.10k
      Res = ParseLambdaExpression();
1465
5.10k
      break;
1466
5.10k
    }
1467
9.20k
    if (getLangOpts().ObjC) {
1468
9.19k
      Res = ParseObjCMessageExpression();
1469
9.19k
      break;
1470
9.19k
    }
1471
9
    LLVM_FALLTHROUGH;
1472
8.46k
  default:
1473
8.46k
    NotCastExpr = true;
1474
8.46k
    return ExprError();
1475
32.8M
  }
1476
32.8M
1477
32.8M
  // Check to see whether Res is a function designator only. If it is and we
1478
32.8M
  // are compiling for OpenCL, we need to return an error as this implies
1479
32.8M
  // that the address of the function is being taken, which is illegal in CL.
1480
32.8M
1481
32.8M
  // These can be followed by postfix-expr pieces.
1482
32.8M
  PreferredType = SavedType;
1483
32.8M
  Res = ParsePostfixExpressionSuffix(Res);
1484
32.8M
  if (getLangOpts().OpenCL)
1485
17.2k
    if (Expr *PostfixExpr = Res.get()) {
1486
16.8k
      QualType Ty = PostfixExpr->getType();
1487
16.8k
      if (!Ty.isNull() && 
Ty->isFunctionType()16.7k
) {
1488
6
        Diag(PostfixExpr->getExprLoc(),
1489
6
             diag::err_opencl_taking_function_address_parser);
1490
6
        return ExprError();
1491
6
      }
1492
32.8M
    }
1493
32.8M
1494
32.8M
  return Res;
1495
32.8M
}
1496
1497
/// Once the leading part of a postfix-expression is parsed, this
1498
/// method parses any suffixes that apply.
1499
///
1500
/// \verbatim
1501
///       postfix-expression: [C99 6.5.2]
1502
///         primary-expression
1503
///         postfix-expression '[' expression ']'
1504
///         postfix-expression '[' braced-init-list ']'
1505
///         postfix-expression '(' argument-expression-list[opt] ')'
1506
///         postfix-expression '.' identifier
1507
///         postfix-expression '->' identifier
1508
///         postfix-expression '++'
1509
///         postfix-expression '--'
1510
///         '(' type-name ')' '{' initializer-list '}'
1511
///         '(' type-name ')' '{' initializer-list ',' '}'
1512
///
1513
///       argument-expression-list: [C99 6.5.2]
1514
///         argument-expression ...[opt]
1515
///         argument-expression-list ',' assignment-expression ...[opt]
1516
/// \endverbatim
1517
ExprResult
1518
32.9M
Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1519
32.9M
  // Now that the primary-expression piece of the postfix-expression has been
1520
32.9M
  // parsed, see if there are any postfix-expression pieces here.
1521
32.9M
  SourceLocation Loc;
1522
32.9M
  auto SavedType = PreferredType;
1523
41.4M
  while (1) {
1524
41.4M
    // Each iteration relies on preferred type for the whole expression.
1525
41.4M
    PreferredType = SavedType;
1526
41.4M
    switch (Tok.getKind()) {
1527
41.4M
    case tok::code_completion:
1528
66
      if (InMessageExpression)
1529
57
        return LHS;
1530
9
1531
9
      Actions.CodeCompletePostfixExpression(
1532
9
          getCurScope(), LHS, PreferredType.get(Tok.getLocation()));
1533
9
      cutOffParsing();
1534
9
      return ExprError();
1535
9
1536
10.5k
    case tok::identifier:
1537
10.5k
      // If we see identifier: after an expression, and we're not already in a
1538
10.5k
      // message send, then this is probably a message send with a missing
1539
10.5k
      // opening bracket '['.
1540
10.5k
      if (getLangOpts().ObjC && 
!InMessageExpression9.54k
&&
1541
10.5k
          
(283
NextToken().is(tok::colon)283
||
NextToken().is(tok::r_square)197
)) {
1542
173
        LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(),
1543
173
                                             nullptr, LHS.get());
1544
173
        break;
1545
173
      }
1546
10.3k
      // Fall through; this isn't a message send.
1547
10.3k
      LLVM_FALLTHROUGH;
1548
10.3k
1549
32.9M
    default:  // Not a postfix-expression suffix.
1550
32.9M
      return LHS;
1551
674k
    case tok::l_square: {  // postfix-expression: p-e '[' expression ']'
1552
674k
      // If we have a array postfix expression that starts on a new line and
1553
674k
      // Objective-C is enabled, it is highly likely that the user forgot a
1554
674k
      // semicolon after the base expression and that the array postfix-expr is
1555
674k
      // actually another message send.  In this case, do some look-ahead to see
1556
674k
      // if the contents of the square brackets are obviously not a valid
1557
674k
      // expression and recover by pretending there is no suffix.
1558
674k
      if (getLangOpts().ObjC && 
Tok.isAtStartOfLine()2.07k
&&
1559
674k
          
isSimpleObjCMessageExpression()5
)
1560
4
        return LHS;
1561
674k
1562
674k
      // Reject array indices starting with a lambda-expression. '[[' is
1563
674k
      // reserved for attributes.
1564
674k
      if (CheckProhibitedCXX11Attribute()) {
1565
2
        (void)Actions.CorrectDelayedTyposInExpr(LHS);
1566
2
        return ExprError();
1567
2
      }
1568
674k
1569
674k
      BalancedDelimiterTracker T(*this, tok::l_square);
1570
674k
      T.consumeOpen();
1571
674k
      Loc = T.getOpenLocation();
1572
674k
      ExprResult Idx, Length;
1573
674k
      SourceLocation ColonLoc;
1574
674k
      PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.get());
1575
674k
      if (getLangOpts().CPlusPlus11 && 
Tok.is(tok::l_brace)295k
) {
1576
2
        Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1577
2
        Idx = ParseBraceInitializer();
1578
674k
      } else if (getLangOpts().OpenMP) {
1579
69.3k
        ColonProtectionRAIIObject RAII(*this);
1580
69.3k
        // Parse [: or [ expr or [ expr :
1581
69.3k
        if (!Tok.is(tok::colon)) {
1582
67.4k
          // [ expr
1583
67.4k
          Idx = ParseExpression();
1584
67.4k
        }
1585
69.3k
        if (Tok.is(tok::colon)) {
1586
3.46k
          // Consume ':'
1587
3.46k
          ColonLoc = ConsumeToken();
1588
3.46k
          if (Tok.isNot(tok::r_square))
1589
2.67k
            Length = ParseExpression();
1590
3.46k
        }
1591
69.3k
      } else
1592
605k
        Idx = ParseExpression();
1593
674k
1594
674k
      SourceLocation RLoc = Tok.getLocation();
1595
674k
1596
674k
      LHS = Actions.CorrectDelayedTyposInExpr(LHS);
1597
674k
      Idx = Actions.CorrectDelayedTyposInExpr(Idx);
1598
674k
      Length = Actions.CorrectDelayedTyposInExpr(Length);
1599
674k
      if (!LHS.isInvalid() && 
!Idx.isInvalid()674k
&&
!Length.isInvalid()674k
&&
1600
674k
          
Tok.is(tok::r_square)674k
) {
1601
674k
        if (ColonLoc.isValid()) {
1602
3.30k
          LHS = Actions.ActOnOMPArraySectionExpr(LHS.get(), Loc, Idx.get(),
1603
3.30k
                                                 ColonLoc, Length.get(), RLoc);
1604
671k
        } else {
1605
671k
          LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc,
1606
671k
                                                Idx.get(), RLoc);
1607
671k
        }
1608
674k
      } else {
1609
262
        LHS = ExprError();
1610
262
        Idx = ExprError();
1611
262
      }
1612
674k
1613
674k
      // Match the ']'.
1614
674k
      T.consumeClose();
1615
674k
      break;
1616
674k
    }
1617
674k
1618
5.49M
    case tok::l_paren:         // p-e: p-e '(' argument-expression-list[opt] ')'
1619
5.49M
    case tok::lesslessless: {  // p-e: p-e '<<<' argument-expression-list '>>>'
1620
5.49M
                               //   '(' argument-expression-list[opt] ')'
1621
5.49M
      tok::TokenKind OpKind = Tok.getKind();
1622
5.49M
      InMessageExpressionRAIIObject InMessage(*this, false);
1623
5.49M
1624
5.49M
      Expr *ExecConfig = nullptr;
1625
5.49M
1626
5.49M
      BalancedDelimiterTracker PT(*this, tok::l_paren);
1627
5.49M
1628
5.49M
      if (OpKind == tok::lesslessless) {
1629
52
        ExprVector ExecConfigExprs;
1630
52
        CommaLocsTy ExecConfigCommaLocs;
1631
52
        SourceLocation OpenLoc = ConsumeToken();
1632
52
1633
52
        if (ParseSimpleExpressionList(ExecConfigExprs, ExecConfigCommaLocs)) {
1634
1
          (void)Actions.CorrectDelayedTyposInExpr(LHS);
1635
1
          LHS = ExprError();
1636
1
        }
1637
52
1638
52
        SourceLocation CloseLoc;
1639
52
        if (TryConsumeToken(tok::greatergreatergreater, CloseLoc)) {
1640
51
        } else 
if (1
LHS.isInvalid()1
) {
1641
0
          SkipUntil(tok::greatergreatergreater, StopAtSemi);
1642
1
        } else {
1643
1
          // There was an error closing the brackets
1644
1
          Diag(Tok, diag::err_expected) << tok::greatergreatergreater;
1645
1
          Diag(OpenLoc, diag::note_matching) << tok::lesslessless;
1646
1
          SkipUntil(tok::greatergreatergreater, StopAtSemi);
1647
1
          LHS = ExprError();
1648
1
        }
1649
52
1650
52
        if (!LHS.isInvalid()) {
1651
43
          if (ExpectAndConsume(tok::l_paren))
1652
1
            LHS = ExprError();
1653
42
          else
1654
42
            Loc = PrevTokLocation;
1655
43
        }
1656
52
1657
52
        if (!LHS.isInvalid()) {
1658
42
          ExprResult ECResult = Actions.ActOnCUDAExecConfigExpr(getCurScope(),
1659
42
                                    OpenLoc,
1660
42
                                    ExecConfigExprs,
1661
42
                                    CloseLoc);
1662
42
          if (ECResult.isInvalid())
1663
2
            LHS = ExprError();
1664
40
          else
1665
40
            ExecConfig = ECResult.get();
1666
42
        }
1667
5.49M
      } else {
1668
5.49M
        PT.consumeOpen();
1669
5.49M
        Loc = PT.getOpenLocation();
1670
5.49M
      }
1671
5.49M
1672
5.49M
      ExprVector ArgExprs;
1673
5.49M
      CommaLocsTy CommaLocs;
1674
5.49M
      auto RunSignatureHelp = [&]() -> QualType {
1675
163
        QualType PreferredType = Actions.ProduceCallSignatureHelp(
1676
163
            getCurScope(), LHS.get(), ArgExprs, PT.getOpenLocation());
1677
163
        CalledSignatureHelp = true;
1678
163
        return PreferredType;
1679
163
      };
1680
5.49M
      if (OpKind == tok::l_paren || 
!LHS.isInvalid()52
) {
1681
5.49M
        if (Tok.isNot(tok::r_paren)) {
1682
9.38M
          if (
ParseExpressionList(ArgExprs, CommaLocs, [&] 3.97M
{
1683
9.38M
                PreferredType.enterFunctionArgument(Tok.getLocation(),
1684
9.38M
                                                    RunSignatureHelp);
1685
9.38M
              })) {
1686
3.87k
            (void)Actions.CorrectDelayedTyposInExpr(LHS);
1687
3.87k
            // If we got an error when parsing expression list, we don't call
1688
3.87k
            // the CodeCompleteCall handler inside the parser. So call it here
1689
3.87k
            // to make sure we get overload suggestions even when we are in the
1690
3.87k
            // middle of a parameter.
1691
3.87k
            if (PP.isCodeCompletionReached() && 
!CalledSignatureHelp163
)
1692
3
              RunSignatureHelp();
1693
3.87k
            LHS = ExprError();
1694
3.97M
          } else if (LHS.isInvalid()) {
1695
121
            for (auto &E : ArgExprs)
1696
138
              Actions.CorrectDelayedTyposInExpr(E);
1697
121
          }
1698
3.97M
        }
1699
5.49M
      }
1700
5.49M
1701
5.49M
      // Match the ')'.
1702
5.49M
      if (LHS.isInvalid()) {
1703
4.27k
        SkipUntil(tok::r_paren, StopAtSemi);
1704
5.49M
      } else if (Tok.isNot(tok::r_paren)) {
1705
745
        bool HadDelayedTypo = false;
1706
745
        if (Actions.CorrectDelayedTyposInExpr(LHS).get() != LHS.get())
1707
0
          HadDelayedTypo = true;
1708
745
        for (auto &E : ArgExprs)
1709
745
          if (Actions.CorrectDelayedTyposInExpr(E).get() != E)
1710
11
            HadDelayedTypo = true;
1711
745
        // If there were delayed typos in the LHS or ArgExprs, call SkipUntil
1712
745
        // instead of PT.consumeClose() to avoid emitting extra diagnostics for
1713
745
        // the unmatched l_paren.
1714
745
        if (HadDelayedTypo)
1715
11
          SkipUntil(tok::r_paren, StopAtSemi);
1716
734
        else
1717
734
          PT.consumeClose();
1718
745
        LHS = ExprError();
1719
5.49M
      } else {
1720
5.49M
        assert((ArgExprs.size() == 0 ||
1721
5.49M
                ArgExprs.size()-1 == CommaLocs.size())&&
1722
5.49M
               "Unexpected number of commas!");
1723
5.49M
        LHS = Actions.ActOnCallExpr(getCurScope(), LHS.get(), Loc,
1724
5.49M
                                    ArgExprs, Tok.getLocation(),
1725
5.49M
                                    ExecConfig);
1726
5.49M
        PT.consumeClose();
1727
5.49M
      }
1728
5.49M
1729
5.49M
      break;
1730
5.49M
    }
1731
5.49M
    case tok::arrow:
1732
2.21M
    case tok::period: {
1733
2.21M
      // postfix-expression: p-e '->' template[opt] id-expression
1734
2.21M
      // postfix-expression: p-e '.' template[opt] id-expression
1735
2.21M
      tok::TokenKind OpKind = Tok.getKind();
1736
2.21M
      SourceLocation OpLoc = ConsumeToken();  // Eat the "." or "->" token.
1737
2.21M
1738
2.21M
      CXXScopeSpec SS;
1739
2.21M
      ParsedType ObjectType;
1740
2.21M
      bool MayBePseudoDestructor = false;
1741
2.21M
      Expr* OrigLHS = !LHS.isInvalid() ? 
LHS.get()2.21M
:
nullptr113
;
1742
2.21M
1743
2.21M
      PreferredType.enterMemAccess(Actions, Tok.getLocation(), OrigLHS);
1744
2.21M
1745
2.21M
      if (getLangOpts().CPlusPlus && 
!LHS.isInvalid()1.86M
) {
1746
1.86M
        Expr *Base = OrigLHS;
1747
1.86M
        const Type* BaseType = Base->getType().getTypePtrOrNull();
1748
1.86M
        if (BaseType && 
Tok.is(tok::l_paren)1.86M
&&
1749
1.86M
            
(13
BaseType->isFunctionType()13
||
1750
13
             
BaseType->isSpecificPlaceholderType(BuiltinType::BoundMember)8
)) {
1751
10
          Diag(OpLoc, diag::err_function_is_not_record)
1752
10
              << OpKind << Base->getSourceRange()
1753
10
              << FixItHint::CreateRemoval(OpLoc);
1754
10
          return ParsePostfixExpressionSuffix(Base);
1755
10
        }
1756
1.86M
1757
1.86M
        LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base,
1758
1.86M
                                                   OpLoc, OpKind, ObjectType,
1759
1.86M
                                                   MayBePseudoDestructor);
1760
1.86M
        if (LHS.isInvalid())
1761
76
          break;
1762
1.86M
1763
1.86M
        ParseOptionalCXXScopeSpecifier(SS, ObjectType,
1764
1.86M
                                       /*EnteringContext=*/false,
1765
1.86M
                                       &MayBePseudoDestructor);
1766
1.86M
        if (SS.isNotEmpty())
1767
585
          ObjectType = nullptr;
1768
1.86M
      }
1769
2.21M
1770
2.21M
      
if (2.21M
Tok.is(tok::code_completion)2.21M
) {
1771
118
        tok::TokenKind CorrectedOpKind =
1772
118
            OpKind == tok::arrow ? 
tok::period35
:
tok::arrow83
;
1773
118
        ExprResult CorrectedLHS(/*Invalid=*/true);
1774
118
        if (getLangOpts().CPlusPlus && 
OrigLHS72
) {
1775
71
          const bool DiagsAreSuppressed = Diags.getSuppressAllDiagnostics();
1776
71
          Diags.setSuppressAllDiagnostics(true);
1777
71
          CorrectedLHS = Actions.ActOnStartCXXMemberReference(
1778
71
              getCurScope(), OrigLHS, OpLoc, CorrectedOpKind, ObjectType,
1779
71
              MayBePseudoDestructor);
1780
71
          Diags.setSuppressAllDiagnostics(DiagsAreSuppressed);
1781
71
        }
1782
118
1783
118
        Expr *Base = LHS.get();
1784
118
        Expr *CorrectedBase = CorrectedLHS.get();
1785
118
        if (!CorrectedBase && 
!getLangOpts().CPlusPlus47
)
1786
46
          CorrectedBase = Base;
1787
118
1788
118
        // Code completion for a member access expression.
1789
118
        Actions.CodeCompleteMemberReferenceExpr(
1790
118
            getCurScope(), Base, CorrectedBase, OpLoc, OpKind == tok::arrow,
1791
118
            Base && 
ExprStatementTokLoc == Base->getBeginLoc()117
,
1792
118
            PreferredType.get(Tok.getLocation()));
1793
118
1794
118
        cutOffParsing();
1795
118
        return ExprError();
1796
118
      }
1797
2.21M
1798
2.21M
      if (MayBePseudoDestructor && 
!LHS.isInvalid()6.02k
) {
1799
6.02k
        LHS = ParseCXXPseudoDestructor(LHS.get(), OpLoc, OpKind, SS,
1800
6.02k
                                       ObjectType);
1801
6.02k
        break;
1802
6.02k
      }
1803
2.20M
1804
2.20M
      // Either the action has told us that this cannot be a
1805
2.20M
      // pseudo-destructor expression (based on the type of base
1806
2.20M
      // expression), or we didn't see a '~' in the right place. We
1807
2.20M
      // can still parse a destructor name here, but in that case it
1808
2.20M
      // names a real destructor.
1809
2.20M
      // Allow explicit constructor calls in Microsoft mode.
1810
2.20M
      // FIXME: Add support for explicit call of template constructor.
1811
2.20M
      SourceLocation TemplateKWLoc;
1812
2.20M
      UnqualifiedId Name;
1813
2.20M
      if (getLangOpts().ObjC && 
OpKind == tok::period8.39k
&&
1814
2.20M
          
Tok.is(tok::kw_class)6.17k
) {
1815
2
        // Objective-C++:
1816
2
        //   After a '.' in a member access expression, treat the keyword
1817
2
        //   'class' as if it were an identifier.
1818
2
        //
1819
2
        // This hack allows property access to the 'class' method because it is
1820
2
        // such a common method name. For other C++ keywords that are
1821
2
        // Objective-C method names, one must use the message send syntax.
1822
2
        IdentifierInfo *Id = Tok.getIdentifierInfo();
1823
2
        SourceLocation Loc = ConsumeToken();
1824
2
        Name.setIdentifier(Id, Loc);
1825
2.20M
      } else if (ParseUnqualifiedId(SS,
1826
2.20M
                                    /*EnteringContext=*/false,
1827
2.20M
                                    /*AllowDestructorName=*/true,
1828
2.20M
                                    /*AllowConstructorName=*/
1829
2.20M
                                    getLangOpts().MicrosoftExt &&
1830
2.20M
                                        
SS.isNotEmpty()2.01k
,
1831
2.20M
                                    /*AllowDeductionGuide=*/false,
1832
2.20M
                                    ObjectType, &TemplateKWLoc, Name)) {
1833
291
        (void)Actions.CorrectDelayedTyposInExpr(LHS);
1834
291
        LHS = ExprError();
1835
291
      }
1836
2.20M
1837
2.20M
      if (!LHS.isInvalid())
1838
2.20M
        LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.get(), OpLoc,
1839
2.20M
                                            OpKind, SS, TemplateKWLoc, Name,
1840
2.20M
                                 CurParsedObjCImpl ? 
CurParsedObjCImpl->Dcl1.51k
1841
2.20M
                                                   : 
nullptr2.20M
);
1842
2.20M
      if (!LHS.isInvalid() && 
Tok.is(tok::less)2.20M
)
1843
6.82k
        checkPotentialAngleBracket(LHS);
1844
2.20M
      break;
1845
2.20M
    }
1846
2.20M
    case tok::plusplus:    // postfix-expression: postfix-expression '++'
1847
149k
    case tok::minusminus:  // postfix-expression: postfix-expression '--'
1848
149k
      if (!LHS.isInvalid()) {
1849
149k
        LHS = Actions.ActOnPostfixUnaryOp(getCurScope(), Tok.getLocation(),
1850
149k
                                          Tok.getKind(), LHS.get());
1851
149k
      }
1852
149k
      ConsumeToken();
1853
149k
      break;
1854
41.4M
    }
1855
41.4M
  }
1856
32.9M
}
1857
1858
/// ParseExprAfterUnaryExprOrTypeTrait - We parsed a typeof/sizeof/alignof/
1859
/// vec_step and we are at the start of an expression or a parenthesized
1860
/// type-id. OpTok is the operand token (typeof/sizeof/alignof). Returns the
1861
/// expression (isCastExpr == false) or the type (isCastExpr == true).
1862
///
1863
/// \verbatim
1864
///       unary-expression:  [C99 6.5.3]
1865
///         'sizeof' unary-expression
1866
///         'sizeof' '(' type-name ')'
1867
/// [GNU]   '__alignof' unary-expression
1868
/// [GNU]   '__alignof' '(' type-name ')'
1869
/// [C11]   '_Alignof' '(' type-name ')'
1870
/// [C++0x] 'alignof' '(' type-id ')'
1871
///
1872
/// [GNU]   typeof-specifier:
1873
///           typeof ( expressions )
1874
///           typeof ( type-name )
1875
/// [GNU/C++] typeof unary-expression
1876
///
1877
/// [OpenCL 1.1 6.11.12] vec_step built-in function:
1878
///           vec_step ( expressions )
1879
///           vec_step ( type-name )
1880
/// \endverbatim
1881
ExprResult
1882
Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
1883
                                           bool &isCastExpr,
1884
                                           ParsedType &CastTy,
1885
183k
                                           SourceRange &CastRange) {
1886
183k
1887
183k
  assert(OpTok.isOneOf(tok::kw_typeof, tok::kw_sizeof, tok::kw___alignof,
1888
183k
                       tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step,
1889
183k
                       tok::kw___builtin_omp_required_simd_align) &&
1890
183k
         "Not a typeof/sizeof/alignof/vec_step expression!");
1891
183k
1892
183k
  ExprResult Operand;
1893
183k
1894
183k
  // If the operand doesn't start with an '(', it must be an expression.
1895
183k
  if (Tok.isNot(tok::l_paren)) {
1896
489
    // If construct allows a form without parenthesis, user may forget to put
1897
489
    // pathenthesis around type name.
1898
489
    if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
1899
489
                      tok::kw__Alignof)) {
1900
483
      if (isTypeIdUnambiguously()) {
1901
7
        DeclSpec DS(AttrFactory);
1902
7
        ParseSpecifierQualifierList(DS);
1903
7
        Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext);
1904
7
        ParseDeclarator(DeclaratorInfo);
1905
7
1906
7
        SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation());
1907
7
        SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation);
1908
7
        Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
1909
7
          << OpTok.getName()
1910
7
          << FixItHint::CreateInsertion(LParenLoc, "(")
1911
7
          << FixItHint::CreateInsertion(RParenLoc, ")");
1912
7
        isCastExpr = true;
1913
7
        return ExprEmpty();
1914
7
      }
1915
482
    }
1916
482
1917
482
    isCastExpr = false;
1918
482
    if (OpTok.is(tok::kw_typeof) && 
!getLangOpts().CPlusPlus6
) {
1919
0
      Diag(Tok, diag::err_expected_after) << OpTok.getIdentifierInfo()
1920
0
                                          << tok::l_paren;
1921
0
      return ExprError();
1922
0
    }
1923
482
1924
482
    Operand = ParseCastExpression(true/*isUnaryExpression*/);
1925
183k
  } else {
1926
183k
    // If it starts with a '(', we know that it is either a parenthesized
1927
183k
    // type-name, or it is a unary-expression that starts with a compound
1928
183k
    // literal, or starts with a primary-expression that is a parenthesized
1929
183k
    // expression.
1930
183k
    ParenParseOption ExprType = CastExpr;
1931
183k
    SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
1932
183k
1933
183k
    Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/,
1934
183k
                                   false, CastTy, RParenLoc);
1935
183k
    CastRange = SourceRange(LParenLoc, RParenLoc);
1936
183k
1937
183k
    // If ParseParenExpression parsed a '(typename)' sequence only, then this is
1938
183k
    // a type.
1939
183k
    if (ExprType == CastExpr) {
1940
126k
      isCastExpr = true;
1941
126k
      return ExprEmpty();
1942
126k
    }
1943
56.2k
1944
56.2k
    if (getLangOpts().CPlusPlus || 
OpTok.isNot(tok::kw_typeof)3.34k
) {
1945
55.2k
      // GNU typeof in C requires the expression to be parenthesized. Not so for
1946
55.2k
      // sizeof/alignof or in C++. Therefore, the parenthesized expression is
1947
55.2k
      // the start of a unary-expression, but doesn't include any postfix
1948
55.2k
      // pieces. Parse these now if present.
1949
55.2k
      if (!Operand.isInvalid())
1950
55.2k
        Operand = ParsePostfixExpressionSuffix(Operand.get());
1951
55.2k
    }
1952
56.2k
  }
1953
183k
1954
183k
  // If we get here, the operand to the typeof/sizeof/alignof was an expression.
1955
183k
  isCastExpr = false;
1956
56.7k
  return Operand;
1957
183k
}
1958
1959
1960
/// Parse a sizeof or alignof expression.
1961
///
1962
/// \verbatim
1963
///       unary-expression:  [C99 6.5.3]
1964
///         'sizeof' unary-expression
1965
///         'sizeof' '(' type-name ')'
1966
/// [C++11] 'sizeof' '...' '(' identifier ')'
1967
/// [GNU]   '__alignof' unary-expression
1968
/// [GNU]   '__alignof' '(' type-name ')'
1969
/// [C11]   '_Alignof' '(' type-name ')'
1970
/// [C++11] 'alignof' '(' type-id ')'
1971
/// \endverbatim
1972
217k
ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
1973
217k
  assert(Tok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
1974
217k
                     tok::kw__Alignof, tok::kw_vec_step,
1975
217k
                     tok::kw___builtin_omp_required_simd_align) &&
1976
217k
         "Not a sizeof/alignof/vec_step expression!");
1977
217k
  Token OpTok = Tok;
1978
217k
  ConsumeToken();
1979
217k
1980
217k
  // [C++11] 'sizeof' '...' '(' identifier ')'
1981
217k
  if (Tok.is(tok::ellipsis) && 
OpTok.is(tok::kw_sizeof)36.6k
) {
1982
36.6k
    SourceLocation EllipsisLoc = ConsumeToken();
1983
36.6k
    SourceLocation LParenLoc, RParenLoc;
1984
36.6k
    IdentifierInfo *Name = nullptr;
1985
36.6k
    SourceLocation NameLoc;
1986
36.6k
    if (Tok.is(tok::l_paren)) {
1987
36.6k
      BalancedDelimiterTracker T(*this, tok::l_paren);
1988
36.6k
      T.consumeOpen();
1989
36.6k
      LParenLoc = T.getOpenLocation();
1990
36.6k
      if (Tok.is(tok::identifier)) {
1991
36.6k
        Name = Tok.getIdentifierInfo();
1992
36.6k
        NameLoc = ConsumeToken();
1993
36.6k
        T.consumeClose();
1994
36.6k
        RParenLoc = T.getCloseLocation();
1995
36.6k
        if (RParenLoc.isInvalid())
1996
0
          RParenLoc = PP.getLocForEndOfToken(NameLoc);
1997
36.6k
      } else {
1998
0
        Diag(Tok, diag::err_expected_parameter_pack);
1999
0
        SkipUntil(tok::r_paren, StopAtSemi);
2000
0
      }
2001
36.6k
    } else 
if (1
Tok.is(tok::identifier)1
) {
2002
1
      Name = Tok.getIdentifierInfo();
2003
1
      NameLoc = ConsumeToken();
2004
1
      LParenLoc = PP.getLocForEndOfToken(EllipsisLoc);
2005
1
      RParenLoc = PP.getLocForEndOfToken(NameLoc);
2006
1
      Diag(LParenLoc, diag::err_paren_sizeof_parameter_pack)
2007
1
        << Name
2008
1
        << FixItHint::CreateInsertion(LParenLoc, "(")
2009
1
        << FixItHint::CreateInsertion(RParenLoc, ")");
2010
1
    } else {
2011
0
      Diag(Tok, diag::err_sizeof_parameter_pack);
2012
0
    }
2013
36.6k
2014
36.6k
    if (!Name)
2015
0
      return ExprError();
2016
36.6k
2017
36.6k
    EnterExpressionEvaluationContext Unevaluated(
2018
36.6k
        Actions, Sema::ExpressionEvaluationContext::Unevaluated,
2019
36.6k
        Sema::ReuseLambdaContextDecl);
2020
36.6k
2021
36.6k
    return Actions.ActOnSizeofParameterPackExpr(getCurScope(),
2022
36.6k
                                                OpTok.getLocation(),
2023
36.6k
                                                *Name, NameLoc,
2024
36.6k
                                                RParenLoc);
2025
36.6k
  }
2026
180k
2027
180k
  if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
2028
4.29k
    Diag(OpTok, diag::warn_cxx98_compat_alignof);
2029
180k
2030
180k
  EnterExpressionEvaluationContext Unevaluated(
2031
180k
      Actions, Sema::ExpressionEvaluationContext::Unevaluated,
2032
180k
      Sema::ReuseLambdaContextDecl);
2033
180k
2034
180k
  bool isCastExpr;
2035
180k
  ParsedType CastTy;
2036
180k
  SourceRange CastRange;
2037
180k
  ExprResult Operand = ParseExprAfterUnaryExprOrTypeTrait(OpTok,
2038
180k
                                                          isCastExpr,
2039
180k
                                                          CastTy,
2040
180k
                                                          CastRange);
2041
180k
2042
180k
  UnaryExprOrTypeTrait ExprKind = UETT_SizeOf;
2043
180k
  if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
2044
4.29k
    ExprKind = UETT_AlignOf;
2045
176k
  else if (OpTok.is(tok::kw___alignof))
2046
3.29k
    ExprKind = UETT_PreferredAlignOf;
2047
173k
  else if (OpTok.is(tok::kw_vec_step))
2048
42
    ExprKind = UETT_VecStep;
2049
172k
  else if (OpTok.is(tok::kw___builtin_omp_required_simd_align))
2050
29
    ExprKind = UETT_OpenMPRequiredSimdAlign;
2051
180k
2052
180k
  if (isCastExpr)
2053
126k
    return Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
2054
126k
                                                 ExprKind,
2055
126k
                                                 /*IsType=*/true,
2056
126k
                                                 CastTy.getAsOpaquePtr(),
2057
126k
                                                 CastRange);
2058
53.8k
2059
53.8k
  if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
2060
23
    Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo();
2061
53.8k
2062
53.8k
  // If we get here, the operand to the sizeof/alignof was an expression.
2063
53.8k
  if (!Operand.isInvalid())
2064
53.8k
    Operand = Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
2065
53.8k
                                                    ExprKind,
2066
53.8k
                                                    /*IsType=*/false,
2067
53.8k
                                                    Operand.get(),
2068
53.8k
                                                    CastRange);
2069
53.8k
  return Operand;
2070
53.8k
}
2071
2072
/// ParseBuiltinPrimaryExpression
2073
///
2074
/// \verbatim
2075
///       primary-expression: [C99 6.5.1]
2076
/// [GNU]   '__builtin_va_arg' '(' assignment-expression ',' type-name ')'
2077
/// [GNU]   '__builtin_offsetof' '(' type-name ',' offsetof-member-designator')'
2078
/// [GNU]   '__builtin_choose_expr' '(' assign-expr ',' assign-expr ','
2079
///                                     assign-expr ')'
2080
/// [GNU]   '__builtin_types_compatible_p' '(' type-name ',' type-name ')'
2081
/// [GNU]   '__builtin_FILE' '(' ')'
2082
/// [GNU]   '__builtin_FUNCTION' '(' ')'
2083
/// [GNU]   '__builtin_LINE' '(' ')'
2084
/// [CLANG] '__builtin_COLUMN' '(' ')'
2085
/// [OCL]   '__builtin_astype' '(' assignment-expression ',' type-name ')'
2086
///
2087
/// [GNU] offsetof-member-designator:
2088
/// [GNU]   identifier
2089
/// [GNU]   offsetof-member-designator '.' identifier
2090
/// [GNU]   offsetof-member-designator '[' expression ']'
2091
/// \endverbatim
2092
19.6k
ExprResult Parser::ParseBuiltinPrimaryExpression() {
2093
19.6k
  ExprResult Res;
2094
19.6k
  const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo();
2095
19.6k
2096
19.6k
  tok::TokenKind T = Tok.getKind();
2097
19.6k
  SourceLocation StartLoc = ConsumeToken();   // Eat the builtin identifier.
2098
19.6k
2099
19.6k
  // All of these start with an open paren.
2100
19.6k
  if (Tok.isNot(tok::l_paren))
2101
0
    return ExprError(Diag(Tok, diag::err_expected_after) << BuiltinII
2102
0
                                                         << tok::l_paren);
2103
19.6k
2104
19.6k
  BalancedDelimiterTracker PT(*this, tok::l_paren);
2105
19.6k
  PT.consumeOpen();
2106
19.6k
2107
19.6k
  // TODO: Build AST.
2108
19.6k
2109
19.6k
  switch (T) {
2110
19.6k
  
default: 0
llvm_unreachable0
("Not a builtin primary expression!");
2111
19.6k
  case tok::kw___builtin_va_arg: {
2112
1.48k
    ExprResult Expr(ParseAssignmentExpression());
2113
1.48k
2114
1.48k
    if (ExpectAndConsume(tok::comma)) {
2115
0
      SkipUntil(tok::r_paren, StopAtSemi);
2116
0
      Expr = ExprError();
2117
0
    }
2118
1.48k
2119
1.48k
    TypeResult Ty = ParseTypeName();
2120
1.48k
2121
1.48k
    if (Tok.isNot(tok::r_paren)) {
2122
0
      Diag(Tok, diag::err_expected) << tok::r_paren;
2123
0
      Expr = ExprError();
2124
0
    }
2125
1.48k
2126
1.48k
    if (Expr.isInvalid() || Ty.isInvalid())
2127
0
      Res = ExprError();
2128
1.48k
    else
2129
1.48k
      Res = Actions.ActOnVAArg(StartLoc, Expr.get(), Ty.get(), ConsumeParen());
2130
1.48k
    break;
2131
19.6k
  }
2132
19.6k
  case tok::kw___builtin_offsetof: {
2133
3.83k
    SourceLocation TypeLoc = Tok.getLocation();
2134
3.83k
    TypeResult Ty = ParseTypeName();
2135
3.83k
    if (Ty.isInvalid()) {
2136
1
      SkipUntil(tok::r_paren, StopAtSemi);
2137
1
      return ExprError();
2138
1
    }
2139
3.83k
2140
3.83k
    if (ExpectAndConsume(tok::comma)) {
2141
0
      SkipUntil(tok::r_paren, StopAtSemi);
2142
0
      return ExprError();
2143
0
    }
2144
3.83k
2145
3.83k
    // We must have at least one identifier here.
2146
3.83k
    if (Tok.isNot(tok::identifier)) {
2147
0
      Diag(Tok, diag::err_expected) << tok::identifier;
2148
0
      SkipUntil(tok::r_paren, StopAtSemi);
2149
0
      return ExprError();
2150
0
    }
2151
3.83k
2152
3.83k
    // Keep track of the various subcomponents we see.
2153
3.83k
    SmallVector<Sema::OffsetOfComponent, 4> Comps;
2154
3.83k
2155
3.83k
    Comps.push_back(Sema::OffsetOfComponent());
2156
3.83k
    Comps.back().isBrackets = false;
2157
3.83k
    Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
2158
3.83k
    Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken();
2159
3.83k
2160
3.83k
    // FIXME: This loop leaks the index expressions on error.
2161
3.89k
    while (1) {
2162
3.89k
      if (Tok.is(tok::period)) {
2163
19
        // offsetof-member-designator: offsetof-member-designator '.' identifier
2164
19
        Comps.push_back(Sema::OffsetOfComponent());
2165
19
        Comps.back().isBrackets = false;
2166
19
        Comps.back().LocStart = ConsumeToken();
2167
19
2168
19
        if (Tok.isNot(tok::identifier)) {
2169
0
          Diag(Tok, diag::err_expected) << tok::identifier;
2170
0
          SkipUntil(tok::r_paren, StopAtSemi);
2171
0
          return ExprError();
2172
0
        }
2173
19
        Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
2174
19
        Comps.back().LocEnd = ConsumeToken();
2175
19
2176
3.87k
      } else if (Tok.is(tok::l_square)) {
2177
42
        if (CheckProhibitedCXX11Attribute())
2178
0
          return ExprError();
2179
42
2180
42
        // offsetof-member-designator: offsetof-member-design '[' expression ']'
2181
42
        Comps.push_back(Sema::OffsetOfComponent());
2182
42
        Comps.back().isBrackets = true;
2183
42
        BalancedDelimiterTracker ST(*this, tok::l_square);
2184
42
        ST.consumeOpen();
2185
42
        Comps.back().LocStart = ST.getOpenLocation();
2186
42
        Res = ParseExpression();
2187
42
        if (Res.isInvalid()) {
2188
0
          SkipUntil(tok::r_paren, StopAtSemi);
2189
0
          return Res;
2190
0
        }
2191
42
        Comps.back().U.E = Res.get();
2192
42
2193
42
        ST.consumeClose();
2194
42
        Comps.back().LocEnd = ST.getCloseLocation();
2195
3.83k
      } else {
2196
3.83k
        if (Tok.isNot(tok::r_paren)) {
2197
2
          PT.consumeClose();
2198
2
          Res = ExprError();
2199
3.83k
        } else if (Ty.isInvalid()) {
2200
0
          Res = ExprError();
2201
3.83k
        } else {
2202
3.83k
          PT.consumeClose();
2203
3.83k
          Res = Actions.ActOnBuiltinOffsetOf(getCurScope(), StartLoc, TypeLoc,
2204
3.83k
                                             Ty.get(), Comps,
2205
3.83k
                                             PT.getCloseLocation());
2206
3.83k
        }
2207
3.83k
        break;
2208
3.83k
      }
2209
3.89k
    }
2210
3.83k
    break;
2211
3.83k
  }
2212
3.83k
  case tok::kw___builtin_choose_expr: {
2213
48
    ExprResult Cond(ParseAssignmentExpression());
2214
48
    if (Cond.isInvalid()) {
2215
0
      SkipUntil(tok::r_paren, StopAtSemi);
2216
0
      return Cond;
2217
0
    }
2218
48
    if (ExpectAndConsume(tok::comma)) {
2219
0
      SkipUntil(tok::r_paren, StopAtSemi);
2220
0
      return ExprError();
2221
0
    }
2222
48
2223
48
    ExprResult Expr1(ParseAssignmentExpression());
2224
48
    if (Expr1.isInvalid()) {
2225
0
      SkipUntil(tok::r_paren, StopAtSemi);
2226
0
      return Expr1;
2227
0
    }
2228
48
    if (ExpectAndConsume(tok::comma)) {
2229
0
      SkipUntil(tok::r_paren, StopAtSemi);
2230
0
      return ExprError();
2231
0
    }
2232
48
2233
48
    ExprResult Expr2(ParseAssignmentExpression());
2234
48
    if (Expr2.isInvalid()) {
2235
0
      SkipUntil(tok::r_paren, StopAtSemi);
2236
0
      return Expr2;
2237
0
    }
2238
48
    if (Tok.isNot(tok::r_paren)) {
2239
0
      Diag(Tok, diag::err_expected) << tok::r_paren;
2240
0
      return ExprError();
2241
0
    }
2242
48
    Res = Actions.ActOnChooseExpr(StartLoc, Cond.get(), Expr1.get(),
2243
48
                                  Expr2.get(), ConsumeParen());
2244
48
    break;
2245
48
  }
2246
48
  case tok::kw___builtin_astype: {
2247
30
    // The first argument is an expression to be converted, followed by a comma.
2248
30
    ExprResult Expr(ParseAssignmentExpression());
2249
30
    if (Expr.isInvalid()) {
2250
0
      SkipUntil(tok::r_paren, StopAtSemi);
2251
0
      return ExprError();
2252
0
    }
2253
30
2254
30
    if (ExpectAndConsume(tok::comma)) {
2255
0
      SkipUntil(tok::r_paren, StopAtSemi);
2256
0
      return ExprError();
2257
0
    }
2258
30
2259
30
    // Second argument is the type to bitcast to.
2260
30
    TypeResult DestTy = ParseTypeName();
2261
30
    if (DestTy.isInvalid())
2262
0
      return ExprError();
2263
30
2264
30
    // Attempt to consume the r-paren.
2265
30
    if (Tok.isNot(tok::r_paren)) {
2266
0
      Diag(Tok, diag::err_expected) << tok::r_paren;
2267
0
      SkipUntil(tok::r_paren, StopAtSemi);
2268
0
      return ExprError();
2269
0
    }
2270
30
2271
30
    Res = Actions.ActOnAsTypeExpr(Expr.get(), DestTy.get(), StartLoc,
2272
30
                                  ConsumeParen());
2273
30
    break;
2274
30
  }
2275
14.1k
  case tok::kw___builtin_convertvector: {
2276
14.1k
    // The first argument is an expression to be converted, followed by a comma.
2277
14.1k
    ExprResult Expr(ParseAssignmentExpression());
2278
14.1k
    if (Expr.isInvalid()) {
2279
0
      SkipUntil(tok::r_paren, StopAtSemi);
2280
0
      return ExprError();
2281
0
    }
2282
14.1k
2283
14.1k
    if (ExpectAndConsume(tok::comma)) {
2284
0
      SkipUntil(tok::r_paren, StopAtSemi);
2285
0
      return ExprError();
2286
0
    }
2287
14.1k
2288
14.1k
    // Second argument is the type to bitcast to.
2289
14.1k
    TypeResult DestTy = ParseTypeName();
2290
14.1k
    if (DestTy.isInvalid())
2291
0
      return ExprError();
2292
14.1k
2293
14.1k
    // Attempt to consume the r-paren.
2294
14.1k
    if (Tok.isNot(tok::r_paren)) {
2295
0
      Diag(Tok, diag::err_expected) << tok::r_paren;
2296
0
      SkipUntil(tok::r_paren, StopAtSemi);
2297
0
      return ExprError();
2298
0
    }
2299
14.1k
2300
14.1k
    Res = Actions.ActOnConvertVectorExpr(Expr.get(), DestTy.get(), StartLoc,
2301
14.1k
                                         ConsumeParen());
2302
14.1k
    break;
2303
14.1k
  }
2304
14.1k
  case tok::kw___builtin_COLUMN:
2305
107
  case tok::kw___builtin_FILE:
2306
107
  case tok::kw___builtin_FUNCTION:
2307
107
  case tok::kw___builtin_LINE: {
2308
107
    // Attempt to consume the r-paren.
2309
107
    if (Tok.isNot(tok::r_paren)) {
2310
8
      Diag(Tok, diag::err_expected) << tok::r_paren;
2311
8
      SkipUntil(tok::r_paren, StopAtSemi);
2312
8
      return ExprError();
2313
8
    }
2314
99
    SourceLocExpr::IdentKind Kind = [&] {
2315
99
      switch (T) {
2316
99
      case tok::kw___builtin_FILE:
2317
17
        return SourceLocExpr::File;
2318
99
      case tok::kw___builtin_FUNCTION:
2319
19
        return SourceLocExpr::Function;
2320
99
      case tok::kw___builtin_LINE:
2321
50
        return SourceLocExpr::Line;
2322
99
      case tok::kw___builtin_COLUMN:
2323
13
        return SourceLocExpr::Column;
2324
99
      default:
2325
0
        llvm_unreachable("invalid keyword");
2326
99
      }
2327
99
    }();
2328
99
    Res = Actions.ActOnSourceLocExpr(Kind, StartLoc, ConsumeParen());
2329
99
    break;
2330
99
  }
2331
19.6k
  }
2332
19.6k
2333
19.6k
  if (Res.isInvalid())
2334
33
    return ExprError();
2335
19.5k
2336
19.5k
  // These can be followed by postfix-expr pieces because they are
2337
19.5k
  // primary-expressions.
2338
19.5k
  return ParsePostfixExpressionSuffix(Res.get());
2339
19.5k
}
2340
2341
/// ParseParenExpression - This parses the unit that starts with a '(' token,
2342
/// based on what is allowed by ExprType.  The actual thing parsed is returned
2343
/// in ExprType. If stopIfCastExpr is true, it will only return the parsed type,
2344
/// not the parsed cast-expression.
2345
///
2346
/// \verbatim
2347
///       primary-expression: [C99 6.5.1]
2348
///         '(' expression ')'
2349
/// [GNU]   '(' compound-statement ')'      (if !ParenExprOnly)
2350
///       postfix-expression: [C99 6.5.2]
2351
///         '(' type-name ')' '{' initializer-list '}'
2352
///         '(' type-name ')' '{' initializer-list ',' '}'
2353
///       cast-expression: [C99 6.5.4]
2354
///         '(' type-name ')' cast-expression
2355
/// [ARC]   bridged-cast-expression
2356
/// [ARC] bridged-cast-expression:
2357
///         (__bridge type-name) cast-expression
2358
///         (__bridge_transfer type-name) cast-expression
2359
///         (__bridge_retained type-name) cast-expression
2360
///       fold-expression: [C++1z]
2361
///         '(' cast-expression fold-operator '...' ')'
2362
///         '(' '...' fold-operator cast-expression ')'
2363
///         '(' cast-expression fold-operator '...'
2364
///                 fold-operator cast-expression ')'
2365
/// \endverbatim
2366
ExprResult
2367
Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
2368
                             bool isTypeCast, ParsedType &CastTy,
2369
6.05M
                             SourceLocation &RParenLoc) {
2370
6.05M
  assert(Tok.is(tok::l_paren) && "Not a paren expr!");
2371
6.05M
  ColonProtectionRAIIObject ColonProtection(*this, false);
2372
6.05M
  BalancedDelimiterTracker T(*this, tok::l_paren);
2373
6.05M
  if (T.consumeOpen())
2374
0
    return ExprError();
2375
6.05M
  SourceLocation OpenLoc = T.getOpenLocation();
2376
6.05M
2377
6.05M
  PreferredType.enterParenExpr(Tok.getLocation(), OpenLoc);
2378
6.05M
2379
6.05M
  ExprResult Result(true);
2380
6.05M
  bool isAmbiguousTypeId;
2381
6.05M
  CastTy = nullptr;
2382
6.05M
2383
6.05M
  if (Tok.is(tok::code_completion)) {
2384
30
    Actions.CodeCompleteExpression(
2385
30
        getCurScope(), PreferredType.get(Tok.getLocation()),
2386
30
        /*IsParenthesized=*/ExprType >= CompoundLiteral);
2387
30
    cutOffParsing();
2388
30
    return ExprError();
2389
30
  }
2390
6.05M
2391
6.05M
  // Diagnose use of bridge casts in non-arc mode.
2392
6.05M
  bool BridgeCast = (getLangOpts().ObjC &&
2393
6.05M
                     Tok.isOneOf(tok::kw___bridge,
2394
52.8k
                                 tok::kw___bridge_transfer,
2395
52.8k
                                 tok::kw___bridge_retained,
2396
52.8k
                                 tok::kw___bridge_retain));
2397
6.05M
  if (BridgeCast && 
!getLangOpts().ObjCAutoRefCount343
) {
2398
19
    if (!TryConsumeToken(tok::kw___bridge)) {
2399
8
      StringRef BridgeCastName = Tok.getName();
2400
8
      SourceLocation BridgeKeywordLoc = ConsumeToken();
2401
8
      if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
2402
8
        Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
2403
8
          << BridgeCastName
2404
8
          << FixItHint::CreateReplacement(BridgeKeywordLoc, "");
2405
8
    }
2406
19
    BridgeCast = false;
2407
19
  }
2408
6.05M
2409
6.05M
  // None of these cases should fall through with an invalid Result
2410
6.05M
  // unless they've already reported an error.
2411
6.05M
  if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
2412
11.2k
    Diag(Tok, diag::ext_gnu_statement_expr);
2413
11.2k
2414
11.2k
    if (!getCurScope()->getFnParent() && 
!getCurScope()->getBlockParent()2
) {
2415
2
      Result = ExprError(Diag(OpenLoc, diag::err_stmtexpr_file_scope));
2416
11.2k
    } else {
2417
11.2k
      // Find the nearest non-record decl context. Variables declared in a
2418
11.2k
      // statement expression behave as if they were declared in the enclosing
2419
11.2k
      // function, block, or other code construct.
2420
11.2k
      DeclContext *CodeDC = Actions.CurContext;
2421
11.2k
      while (CodeDC->isRecord() || 
isa<EnumDecl>(CodeDC)11.2k
) {
2422
3
        CodeDC = CodeDC->getParent();
2423
3
        assert(CodeDC && !CodeDC->isFileContext() &&
2424
3
               "statement expr not in code context");
2425
3
      }
2426
11.2k
      Sema::ContextRAII SavedContext(Actions, CodeDC, /*NewThisContext=*/false);
2427
11.2k
2428
11.2k
      Actions.ActOnStartStmtExpr();
2429
11.2k
2430
11.2k
      StmtResult Stmt(ParseCompoundStatement(true));
2431
11.2k
      ExprType = CompoundStmt;
2432
11.2k
2433
11.2k
      // If the substmt parsed correctly, build the AST node.
2434
11.2k
      if (!Stmt.isInvalid()) {
2435
11.2k
        Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.get(), Tok.getLocation());
2436
11.2k
      } else {
2437
0
        Actions.ActOnStmtExprError();
2438
0
      }
2439
11.2k
    }
2440
6.04M
  } else if (ExprType >= CompoundLiteral && BridgeCast) {
2441
324
    tok::TokenKind tokenKind = Tok.getKind();
2442
324
    SourceLocation BridgeKeywordLoc = ConsumeToken();
2443
324
2444
324
    // Parse an Objective-C ARC ownership cast expression.
2445
324
    ObjCBridgeCastKind Kind;
2446
324
    if (tokenKind == tok::kw___bridge)
2447
119
      Kind = OBC_Bridge;
2448
205
    else if (tokenKind == tok::kw___bridge_transfer)
2449
104
      Kind = OBC_BridgeTransfer;
2450
101
    else if (tokenKind == tok::kw___bridge_retained)
2451
97
      Kind = OBC_BridgeRetained;
2452
4
    else {
2453
4
      // As a hopefully temporary workaround, allow __bridge_retain as
2454
4
      // a synonym for __bridge_retained, but only in system headers.
2455
4
      assert(tokenKind == tok::kw___bridge_retain);
2456
4
      Kind = OBC_BridgeRetained;
2457
4
      if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
2458
2
        Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
2459
2
          << FixItHint::CreateReplacement(BridgeKeywordLoc,
2460
2
                                          "__bridge_retained");
2461
4
    }
2462
324
2463
324
    TypeResult Ty = ParseTypeName();
2464
324
    T.consumeClose();
2465
324
    ColonProtection.restore();
2466
324
    RParenLoc = T.getCloseLocation();
2467
324
2468
324
    PreferredType.enterTypeCast(Tok.getLocation(), Ty.get().get());
2469
324
    ExprResult SubExpr = ParseCastExpression(/*isUnaryExpression=*/false);
2470
324
2471
324
    if (Ty.isInvalid() || SubExpr.isInvalid())
2472
0
      return ExprError();
2473
324
2474
324
    return Actions.ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind,
2475
324
                                        BridgeKeywordLoc, Ty.get(),
2476
324
                                        RParenLoc, SubExpr.get());
2477
6.04M
  } else if (ExprType >= CompoundLiteral &&
2478
6.04M
             isTypeIdInParens(isAmbiguousTypeId)) {
2479
3.80M
2480
3.80M
    // Otherwise, this is a compound literal expression or cast expression.
2481
3.80M
2482
3.80M
    // In C++, if the type-id is ambiguous we disambiguate based on context.
2483
3.80M
    // If stopIfCastExpr is true the context is a typeof/sizeof/alignof
2484
3.80M
    // in which case we should treat it as type-id.
2485
3.80M
    // if stopIfCastExpr is false, we need to determine the context past the
2486
3.80M
    // parens, so we defer to ParseCXXAmbiguousParenExpression for that.
2487
3.80M
    if (isAmbiguousTypeId && 
!stopIfCastExpr1.10k
) {
2488
1.02k
      ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T,
2489
1.02k
                                                        ColonProtection);
2490
1.02k
      RParenLoc = T.getCloseLocation();
2491
1.02k
      return res;
2492
1.02k
    }
2493
3.80M
2494
3.80M
    // Parse the type declarator.
2495
3.80M
    DeclSpec DS(AttrFactory);
2496
3.80M
    ParseSpecifierQualifierList(DS);
2497
3.80M
    Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext);
2498
3.80M
    ParseDeclarator(DeclaratorInfo);
2499
3.80M
2500
3.80M
    // If our type is followed by an identifier and either ':' or ']', then
2501
3.80M
    // this is probably an Objective-C message send where the leading '[' is
2502
3.80M
    // missing. Recover as if that were the case.
2503
3.80M
    if (!DeclaratorInfo.isInvalidType() && 
Tok.is(tok::identifier)3.80M
&&
2504
3.80M
        
!InMessageExpression77
&&
getLangOpts().ObjC77
&&
2505
3.80M
        
(75
NextToken().is(tok::colon)75
||
NextToken().is(tok::r_square)0
)) {
2506
75
      TypeResult Ty;
2507
75
      {
2508
75
        InMessageExpressionRAIIObject InMessage(*this, false);
2509
75
        Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
2510
75
      }
2511
75
      Result = ParseObjCMessageExpressionBody(SourceLocation(),
2512
75
                                              SourceLocation(),
2513
75
                                              Ty.get(), nullptr);
2514
3.80M
    } else {
2515
3.80M
      // Match the ')'.
2516
3.80M
      T.consumeClose();
2517
3.80M
      ColonProtection.restore();
2518
3.80M
      RParenLoc = T.getCloseLocation();
2519
3.80M
      if (Tok.is(tok::l_brace)) {
2520
29.8k
        ExprType = CompoundLiteral;
2521
29.8k
        TypeResult Ty;
2522
29.8k
        {
2523
29.8k
          InMessageExpressionRAIIObject InMessage(*this, false);
2524
29.8k
          Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
2525
29.8k
        }
2526
29.8k
        return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc);
2527
29.8k
      }
2528
3.77M
2529
3.77M
      if (Tok.is(tok::l_paren)) {
2530
635k
        // This could be OpenCL vector Literals
2531
635k
        if (getLangOpts().OpenCL)
2532
380
        {
2533
380
          TypeResult Ty;
2534
380
          {
2535
380
            InMessageExpressionRAIIObject InMessage(*this, false);
2536
380
            Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
2537
380
          }
2538
380
          if(Ty.isInvalid())
2539
0
          {
2540
0
             return ExprError();
2541
0
          }
2542
380
          QualType QT = Ty.get().get().getCanonicalType();
2543
380
          if (QT->isVectorType())
2544
150
          {
2545
150
            // We parsed '(' vector-type-name ')' followed by '('
2546
150
2547
150
            // Parse the cast-expression that follows it next.
2548
150
            // isVectorLiteral = true will make sure we don't parse any
2549
150
            // Postfix expression yet
2550
150
            Result = ParseCastExpression(/*isUnaryExpression=*/false,
2551
150
                                         /*isAddressOfOperand=*/false,
2552
150
                                         /*isTypeCast=*/IsTypeCast,
2553
150
                                         /*isVectorLiteral=*/true);
2554
150
2555
150
            if (!Result.isInvalid()) {
2556
150
              Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
2557
150
                                             DeclaratorInfo, CastTy,
2558
150
                                             RParenLoc, Result.get());
2559
150
            }
2560
150
2561
150
            // After we performed the cast we can check for postfix-expr pieces.
2562
150
            if (!Result.isInvalid()) {
2563
147
              Result = ParsePostfixExpressionSuffix(Result);
2564
147
            }
2565
150
2566
150
            return Result;
2567
150
          }
2568
3.77M
        }
2569
635k
      }
2570
3.77M
2571
3.77M
      if (ExprType == CastExpr) {
2572
3.77M
        // We parsed '(' type-name ')' and the thing after it wasn't a '{'.
2573
3.77M
2574
3.77M
        if (DeclaratorInfo.isInvalidType())
2575
99
          return ExprError();
2576
3.77M
2577
3.77M
        // Note that this doesn't parse the subsequent cast-expression, it just
2578
3.77M
        // returns the parsed type to the callee.
2579
3.77M
        if (stopIfCastExpr) {
2580
126k
          TypeResult Ty;
2581
126k
          {
2582
126k
            InMessageExpressionRAIIObject InMessage(*this, false);
2583
126k
            Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
2584
126k
          }
2585
126k
          CastTy = Ty.get();
2586
126k
          return ExprResult();
2587
126k
        }
2588
3.64M
2589
3.64M
        // Reject the cast of super idiom in ObjC.
2590
3.64M
        if (Tok.is(tok::identifier) && 
getLangOpts().ObjC2.83M
&&
2591
3.64M
            
Tok.getIdentifierInfo() == Ident_super30.1k
&&
2592
3.64M
            
getCurScope()->isInObjcMethodScope()10
&&
2593
3.64M
            
GetLookAheadToken(1).isNot(tok::period)8
) {
2594
7
          Diag(Tok.getLocation(), diag::err_illegal_super_cast)
2595
7
            << SourceRange(OpenLoc, RParenLoc);
2596
7
          return ExprError();
2597
7
        }
2598
3.64M
2599
3.64M
        PreferredType.enterTypeCast(Tok.getLocation(), CastTy.get());
2600
3.64M
        // Parse the cast-expression that follows it next.
2601
3.64M
        // TODO: For cast expression with CastTy.
2602
3.64M
        Result = ParseCastExpression(/*isUnaryExpression=*/false,
2603
3.64M
                                     /*isAddressOfOperand=*/false,
2604
3.64M
                                     /*isTypeCast=*/IsTypeCast);
2605
3.64M
        if (!Result.isInvalid()) {
2606
3.64M
          Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc,
2607
3.64M
                                         DeclaratorInfo, CastTy,
2608
3.64M
                                         RParenLoc, Result.get());
2609
3.64M
        }
2610
3.64M
        return Result;
2611
3.64M
      }
2612
0
2613
0
      Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
2614
0
      return ExprError();
2615
0
    }
2616
2.23M
  } else if (ExprType >= FoldExpr && Tok.is(tok::ellipsis) &&
2617
2.23M
             
isFoldOperator(NextToken().getKind())15
) {
2618
11
    ExprType = FoldExpr;
2619
11
    return ParseFoldExpression(ExprResult(), T);
2620
2.23M
  } else if (isTypeCast) {
2621
536k
    // Parse the expression-list.
2622
536k
    InMessageExpressionRAIIObject InMessage(*this, false);
2623
536k
2624
536k
    ExprVector ArgExprs;
2625
536k
    CommaLocsTy CommaLocs;
2626
536k
2627
536k
    if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) {
2628
536k
      // FIXME: If we ever support comma expressions as operands to
2629
536k
      // fold-expressions, we'll need to allow multiple ArgExprs here.
2630
536k
      if (ExprType >= FoldExpr && ArgExprs.size() == 1 &&
2631
536k
          
isFoldOperator(Tok.getKind())529k
&&
NextToken().is(tok::ellipsis)6
) {
2632
6
        ExprType = FoldExpr;
2633
6
        return ParseFoldExpression(ArgExprs[0], T);
2634
6
      }
2635
536k
2636
536k
      ExprType = SimpleExpr;
2637
536k
      Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
2638
536k
                                          ArgExprs);
2639
536k
    }
2640
1.69M
  } else {
2641
1.69M
    InMessageExpressionRAIIObject InMessage(*this, false);
2642
1.69M
2643
1.69M
    Result = ParseExpression(MaybeTypeCast);
2644
1.69M
    if (!getLangOpts().CPlusPlus && 
MaybeTypeCast0
&&
Result.isUsable()520k
) {
2645
519k
      // Correct typos in non-C++ code earlier so that implicit-cast-like
2646
519k
      // expressions are parsed correctly.
2647
519k
      Result = Actions.CorrectDelayedTyposInExpr(Result);
2648
519k
    }
2649
1.69M
2650
1.69M
    if (ExprType >= FoldExpr && isFoldOperator(Tok.getKind()) &&
2651
1.69M
        
NextToken().is(tok::ellipsis)99
) {
2652
99
      ExprType = FoldExpr;
2653
99
      return ParseFoldExpression(Result, T);
2654
99
    }
2655
1.69M
    ExprType = SimpleExpr;
2656
1.69M
2657
1.69M
    // Don't build a paren expression unless we actually match a ')'.
2658
1.69M
    if (!Result.isInvalid() && 
Tok.is(tok::r_paren)1.69M
)
2659
1.69M
      Result =
2660
1.69M
          Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.get());
2661
1.69M
  }
2662
6.05M
2663
6.05M
  // Match the ')'.
2664
6.05M
  
if (2.24M
Result.isInvalid()2.24M
) {
2665
1.02k
    SkipUntil(tok::r_paren, StopAtSemi);
2666
1.02k
    return ExprError();
2667
1.02k
  }
2668
2.24M
2669
2.24M
  T.consumeClose();
2670
2.24M
  RParenLoc = T.getCloseLocation();
2671
2.24M
  return Result;
2672
2.24M
}
2673
2674
/// ParseCompoundLiteralExpression - We have parsed the parenthesized type-name
2675
/// and we are at the left brace.
2676
///
2677
/// \verbatim
2678
///       postfix-expression: [C99 6.5.2]
2679
///         '(' type-name ')' '{' initializer-list '}'
2680
///         '(' type-name ')' '{' initializer-list ',' '}'
2681
/// \endverbatim
2682
ExprResult
2683
Parser::ParseCompoundLiteralExpression(ParsedType Ty,
2684
                                       SourceLocation LParenLoc,
2685
29.8k
                                       SourceLocation RParenLoc) {
2686
29.8k
  assert(Tok.is(tok::l_brace) && "Not a compound literal!");
2687
29.8k
  if (!getLangOpts().C99)   // Compound literals don't exist in C90.
2688
3.57k
    Diag(LParenLoc, diag::ext_c99_compound_literal);
2689
29.8k
  ExprResult Result = ParseInitializer();
2690
29.8k
  if (!Result.isInvalid() && Ty)
2691
29.8k
    return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, Result.get());
2692
3
  return Result;
2693
3
}
2694
2695
/// ParseStringLiteralExpression - This handles the various token types that
2696
/// form string literals, and also handles string concatenation [C99 5.1.1.2,
2697
/// translation phase #6].
2698
///
2699
/// \verbatim
2700
///       primary-expression: [C99 6.5.1]
2701
///         string-literal
2702
/// \verbatim
2703
2.99M
ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral) {
2704
2.99M
  assert(isTokenStringLiteral() && "Not a string literal!");
2705
2.99M
2706
2.99M
  // String concat.  Note that keywords like __func__ and __FUNCTION__ are not
2707
2.99M
  // considered to be strings for concatenation purposes.
2708
2.99M
  SmallVector<Token, 4> StringToks;
2709
2.99M
2710
3.83M
  do {
2711
3.83M
    StringToks.push_back(Tok);
2712
3.83M
    ConsumeStringToken();
2713
3.83M
  } while (isTokenStringLiteral());
2714
2.99M
2715
2.99M
  // Pass the set of string tokens, ready for concatenation, to the actions.
2716
2.99M
  return Actions.ActOnStringLiteral(StringToks,
2717
2.99M
                                    AllowUserDefinedLiteral ? 
getCurScope()2.63M
2718
2.99M
                                                            : 
nullptr360k
);
2719
2.99M
}
2720
2721
/// ParseGenericSelectionExpression - Parse a C11 generic-selection
2722
/// [C11 6.5.1.1].
2723
///
2724
/// \verbatim
2725
///    generic-selection:
2726
///           _Generic ( assignment-expression , generic-assoc-list )
2727
///    generic-assoc-list:
2728
///           generic-association
2729
///           generic-assoc-list , generic-association
2730
///    generic-association:
2731
///           type-name : assignment-expression
2732
///           default : assignment-expression
2733
/// \endverbatim
2734
237
ExprResult Parser::ParseGenericSelectionExpression() {
2735
237
  assert(Tok.is(tok::kw__Generic) && "_Generic keyword expected");
2736
237
  SourceLocation KeyLoc = ConsumeToken();
2737
237
2738
237
  if (!getLangOpts().C11)
2739
8
    Diag(KeyLoc, diag::ext_c11_generic_selection);
2740
237
2741
237
  BalancedDelimiterTracker T(*this, tok::l_paren);
2742
237
  if (T.expectAndConsume())
2743
1
    return ExprError();
2744
236
2745
236
  ExprResult ControllingExpr;
2746
236
  {
2747
236
    // C11 6.5.1.1p3 "The controlling expression of a generic selection is
2748
236
    // not evaluated."
2749
236
    EnterExpressionEvaluationContext Unevaluated(
2750
236
        Actions, Sema::ExpressionEvaluationContext::Unevaluated);
2751
236
    ControllingExpr =
2752
236
        Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
2753
236
    if (ControllingExpr.isInvalid()) {
2754
1
      SkipUntil(tok::r_paren, StopAtSemi);
2755
1
      return ExprError();
2756
1
    }
2757
235
  }
2758
235
2759
235
  if (ExpectAndConsume(tok::comma)) {
2760
1
    SkipUntil(tok::r_paren, StopAtSemi);
2761
1
    return ExprError();
2762
1
  }
2763
234
2764
234
  SourceLocation DefaultLoc;
2765
234
  TypeVector Types;
2766
234
  ExprVector Exprs;
2767
654
  do {
2768
654
    ParsedType Ty;
2769
654
    if (Tok.is(tok::kw_default)) {
2770
32
      // C11 6.5.1.1p2 "A generic selection shall have no more than one default
2771
32
      // generic association."
2772
32
      if (!DefaultLoc.isInvalid()) {
2773
1
        Diag(Tok, diag::err_duplicate_default_assoc);
2774
1
        Diag(DefaultLoc, diag::note_previous_default_assoc);
2775
1
        SkipUntil(tok::r_paren, StopAtSemi);
2776
1
        return ExprError();
2777
1
      }
2778
31
      DefaultLoc = ConsumeToken();
2779
31
      Ty = nullptr;
2780
622
    } else {
2781
622
      ColonProtectionRAIIObject X(*this);
2782
622
      TypeResult TR = ParseTypeName();
2783
622
      if (TR.isInvalid()) {
2784
0
        SkipUntil(tok::r_paren, StopAtSemi);
2785
0
        return ExprError();
2786
0
      }
2787
622
      Ty = TR.get();
2788
622
    }
2789
654
    Types.push_back(Ty);
2790
653
2791
653
    if (ExpectAndConsume(tok::colon)) {
2792
1
      SkipUntil(tok::r_paren, StopAtSemi);
2793
1
      return ExprError();
2794
1
    }
2795
652
2796
652
    // FIXME: These expressions should be parsed in a potentially potentially
2797
652
    // evaluated context.
2798
652
    ExprResult ER(
2799
652
        Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
2800
652
    if (ER.isInvalid()) {
2801
8
      SkipUntil(tok::r_paren, StopAtSemi);
2802
8
      return ExprError();
2803
8
    }
2804
644
    Exprs.push_back(ER.get());
2805
644
  } while (TryConsumeToken(tok::comma));
2806
234
2807
234
  T.consumeClose();
2808
224
  if (T.getCloseLocation().isInvalid())
2809
0
    return ExprError();
2810
224
2811
224
  return Actions.ActOnGenericSelectionExpr(KeyLoc, DefaultLoc,
2812
224
                                           T.getCloseLocation(),
2813
224
                                           ControllingExpr.get(),
2814
224
                                           Types, Exprs);
2815
224
}
2816
2817
/// Parse A C++1z fold-expression after the opening paren and optional
2818
/// left-hand-side expression.
2819
///
2820
/// \verbatim
2821
///   fold-expression:
2822
///       ( cast-expression fold-operator ... )
2823
///       ( ... fold-operator cast-expression )
2824
///       ( cast-expression fold-operator ... fold-operator cast-expression )
2825
ExprResult Parser::ParseFoldExpression(ExprResult LHS,
2826
116
                                       BalancedDelimiterTracker &T) {
2827
116
  if (LHS.isInvalid()) {
2828
0
    T.skipToEnd();
2829
0
    return true;
2830
0
  }
2831
116
2832
116
  tok::TokenKind Kind = tok::unknown;
2833
116
  SourceLocation FirstOpLoc;
2834
116
  if (LHS.isUsable()) {
2835
105
    Kind = Tok.getKind();
2836
105
    assert(isFoldOperator(Kind) && "missing fold-operator");
2837
105
    FirstOpLoc = ConsumeToken();
2838
105
  }
2839
116
2840
116
  assert(Tok.is(tok::ellipsis) && "not a fold-expression");
2841
116
  SourceLocation EllipsisLoc = ConsumeToken();
2842
116
2843
116
  ExprResult RHS;
2844
116
  if (Tok.isNot(tok::r_paren)) {
2845
58
    if (!isFoldOperator(Tok.getKind()))
2846
1
      return Diag(Tok.getLocation(), diag::err_expected_fold_operator);
2847
57
2848
57
    if (Kind != tok::unknown && 
Tok.getKind() != Kind46
)
2849
2
      Diag(Tok.getLocation(), diag::err_fold_operator_mismatch)
2850
2
        << SourceRange(FirstOpLoc);
2851
57
    Kind = Tok.getKind();
2852
57
    ConsumeToken();
2853
57
2854
57
    RHS = ParseExpression();
2855
57
    if (RHS.isInvalid()) {
2856
0
      T.skipToEnd();
2857
0
      return true;
2858
0
    }
2859
115
  }
2860
115
2861
115
  Diag(EllipsisLoc, getLangOpts().CPlusPlus17
2862
115
                        ? 
diag::warn_cxx14_compat_fold_expression104
2863
115
                        : 
diag::ext_fold_expression11
);
2864
115
2865
115
  T.consumeClose();
2866
115
  return Actions.ActOnCXXFoldExpr(T.getOpenLocation(), LHS.get(), Kind,
2867
115
                                  EllipsisLoc, RHS.get(), T.getCloseLocation());
2868
115
}
2869
2870
/// ParseExpressionList - Used for C/C++ (argument-)expression-list.
2871
///
2872
/// \verbatim
2873
///       argument-expression-list:
2874
///         assignment-expression
2875
///         argument-expression-list , assignment-expression
2876
///
2877
/// [C++] expression-list:
2878
/// [C++]   assignment-expression
2879
/// [C++]   expression-list , assignment-expression
2880
///
2881
/// [C++0x] expression-list:
2882
/// [C++0x]   initializer-list
2883
///
2884
/// [C++0x] initializer-list
2885
/// [C++0x]   initializer-clause ...[opt]
2886
/// [C++0x]   initializer-list , initializer-clause ...[opt]
2887
///
2888
/// [C++0x] initializer-clause:
2889
/// [C++0x]   assignment-expression
2890
/// [C++0x]   braced-init-list
2891
/// \endverbatim
2892
bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
2893
                                 SmallVectorImpl<SourceLocation> &CommaLocs,
2894
4.57M
                                 llvm::function_ref<void()> ExpressionStarts) {
2895
4.57M
  bool SawError = false;
2896
10.1M
  while (1) {
2897
10.1M
    if (ExpressionStarts)
2898
10.1M
      ExpressionStarts();
2899
10.1M
2900
10.1M
    ExprResult Expr;
2901
10.1M
    if (getLangOpts().CPlusPlus11 && 
Tok.is(tok::l_brace)5.68M
) {
2902
713
      Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2903
713
      Expr = ParseBraceInitializer();
2904
713
    } else
2905
10.1M
      Expr = ParseAssignmentExpression();
2906
10.1M
2907
10.1M
    if (Tok.is(tok::ellipsis))
2908
44.1k
      Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
2909
10.1M
    if (Expr.isInvalid()) {
2910
4.91k
      SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
2911
4.91k
      SawError = true;
2912
10.1M
    } else {
2913
10.1M
      Exprs.push_back(Expr.get());
2914
10.1M
    }
2915
10.1M
2916
10.1M
    if (Tok.isNot(tok::comma))
2917
4.57M
      break;
2918
5.57M
    // Move to the next argument, remember where the comma was.
2919
5.57M
    Token Comma = Tok;
2920
5.57M
    CommaLocs.push_back(ConsumeToken());
2921
5.57M
2922
5.57M
    checkPotentialAngleBracketDelimiter(Comma);
2923
5.57M
  }
2924
4.57M
  if (SawError) {
2925
4.07k
    // Ensure typos get diagnosed when errors were encountered while parsing the
2926
4.07k
    // expression list.
2927
4.07k
    for (auto &E : Exprs) {
2928
3.33k
      ExprResult Expr = Actions.CorrectDelayedTyposInExpr(E);
2929
3.33k
      if (Expr.isUsable()) 
E = Expr.get()2.93k
;
2930
3.33k
    }
2931
4.07k
  }
2932
4.57M
  return SawError;
2933
4.57M
}
2934
2935
/// ParseSimpleExpressionList - A simple comma-separated list of expressions,
2936
/// used for misc language extensions.
2937
///
2938
/// \verbatim
2939
///       simple-expression-list:
2940
///         assignment-expression
2941
///         simple-expression-list , assignment-expression
2942
/// \endverbatim
2943
bool
2944
Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
2945
536k
                                  SmallVectorImpl<SourceLocation> &CommaLocs) {
2946
624k
  while (1) {
2947
624k
    ExprResult Expr = ParseAssignmentExpression();
2948
624k
    if (Expr.isInvalid())
2949
305
      return true;
2950
624k
2951
624k
    Exprs.push_back(Expr.get());
2952
624k
2953
624k
    if (Tok.isNot(tok::comma))
2954
536k
      return false;
2955
87.9k
2956
87.9k
    // Move to the next argument, remember where the comma was.
2957
87.9k
    Token Comma = Tok;
2958
87.9k
    CommaLocs.push_back(ConsumeToken());
2959
87.9k
2960
87.9k
    checkPotentialAngleBracketDelimiter(Comma);
2961
87.9k
  }
2962
536k
}
2963
2964
/// ParseBlockId - Parse a block-id, which roughly looks like int (int x).
2965
///
2966
/// \verbatim
2967
/// [clang] block-id:
2968
/// [clang]   specifier-qualifier-list block-declarator
2969
/// \endverbatim
2970
165
void Parser::ParseBlockId(SourceLocation CaretLoc) {
2971
165
  if (Tok.is(tok::code_completion)) {
2972
1
    Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type);
2973
1
    return cutOffParsing();
2974
1
  }
2975
164
2976
164
  // Parse the specifier-qualifier-list piece.
2977
164
  DeclSpec DS(AttrFactory);
2978
164
  ParseSpecifierQualifierList(DS);
2979
164
2980
164
  // Parse the block-declarator.
2981
164
  Declarator DeclaratorInfo(DS, DeclaratorContext::BlockLiteralContext);
2982
164
  DeclaratorInfo.setFunctionDefinitionKind(FDK_Definition);
2983
164
  ParseDeclarator(DeclaratorInfo);
2984
164
2985
164
  MaybeParseGNUAttributes(DeclaratorInfo);
2986
164
2987
164
  // Inform sema that we are starting a block.
2988
164
  Actions.ActOnBlockArguments(CaretLoc, DeclaratorInfo, getCurScope());
2989
164
}
2990
2991
/// ParseBlockLiteralExpression - Parse a block literal, which roughly looks
2992
/// like ^(int x){ return x+1; }
2993
///
2994
/// \verbatim
2995
///         block-literal:
2996
/// [clang]   '^' block-args[opt] compound-statement
2997
/// [clang]   '^' block-id compound-statement
2998
/// [clang] block-args:
2999
/// [clang]   '(' parameter-list ')'
3000
/// \endverbatim
3001
2.71k
ExprResult Parser::ParseBlockLiteralExpression() {
3002
2.71k
  assert(Tok.is(tok::caret) && "block literal starts with ^");
3003
2.71k
  SourceLocation CaretLoc = ConsumeToken();
3004
2.71k
3005
2.71k
  PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), CaretLoc,
3006
2.71k
                                "block literal parsing");
3007
2.71k
3008
2.71k
  // Enter a scope to hold everything within the block.  This includes the
3009
2.71k
  // argument decls, decls within the compound expression, etc.  This also
3010
2.71k
  // allows determining whether a variable reference inside the block is
3011
2.71k
  // within or outside of the block.
3012
2.71k
  ParseScope BlockScope(this, Scope::BlockScope | Scope::FnScope |
3013
2.71k
                                  Scope::CompoundStmtScope | Scope::DeclScope);
3014
2.71k
3015
2.71k
  // Inform sema that we are starting a block.
3016
2.71k
  Actions.ActOnBlockStart(CaretLoc, getCurScope());
3017
2.71k
3018
2.71k
  // Parse the return type if present.
3019
2.71k
  DeclSpec DS(AttrFactory);
3020
2.71k
  Declarator ParamInfo(DS, DeclaratorContext::BlockLiteralContext);
3021
2.71k
  ParamInfo.setFunctionDefinitionKind(FDK_Definition);
3022
2.71k
  // FIXME: Since the return type isn't actually parsed, it can't be used to
3023
2.71k
  // fill ParamInfo with an initial valid range, so do it manually.
3024
2.71k
  ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation()));
3025
2.71k
3026
2.71k
  // If this block has arguments, parse them.  There is no ambiguity here with
3027
2.71k
  // the expression case, because the expression case requires a parameter list.
3028
2.71k
  if (Tok.is(tok::l_paren)) {
3029
1.11k
    ParseParenDeclarator(ParamInfo);
3030
1.11k
    // Parse the pieces after the identifier as if we had "int(...)".
3031
1.11k
    // SetIdentifier sets the source range end, but in this case we're past
3032
1.11k
    // that location.
3033
1.11k
    SourceLocation Tmp = ParamInfo.getSourceRange().getEnd();
3034
1.11k
    ParamInfo.SetIdentifier(nullptr, CaretLoc);
3035
1.11k
    ParamInfo.SetRangeEnd(Tmp);
3036
1.11k
    if (ParamInfo.isInvalidType()) {
3037
0
      // If there was an error parsing the arguments, they may have
3038
0
      // tried to use ^(x+y) which requires an argument list.  Just
3039
0
      // skip the whole block literal.
3040
0
      Actions.ActOnBlockError(CaretLoc, getCurScope());
3041
0
      return ExprError();
3042
0
    }
3043
1.11k
3044
1.11k
    MaybeParseGNUAttributes(ParamInfo);
3045
1.11k
3046
1.11k
    // Inform sema that we are starting a block.
3047
1.11k
    Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope());
3048
1.60k
  } else if (!Tok.is(tok::l_brace)) {
3049
165
    ParseBlockId(CaretLoc);
3050
1.43k
  } else {
3051
1.43k
    // Otherwise, pretend we saw (void).
3052
1.43k
    SourceLocation NoLoc;
3053
1.43k
    ParamInfo.AddTypeInfo(
3054
1.43k
        DeclaratorChunk::getFunction(/*HasProto=*/true,
3055
1.43k
                                     /*IsAmbiguous=*/false,
3056
1.43k
                                     /*RParenLoc=*/NoLoc,
3057
1.43k
                                     /*ArgInfo=*/nullptr,
3058
1.43k
                                     /*NumParams=*/0,
3059
1.43k
                                     /*EllipsisLoc=*/NoLoc,
3060
1.43k
                                     /*RParenLoc=*/NoLoc,
3061
1.43k
                                     /*RefQualifierIsLvalueRef=*/true,
3062
1.43k
                                     /*RefQualifierLoc=*/NoLoc,
3063
1.43k
                                     /*MutableLoc=*/NoLoc, EST_None,
3064
1.43k
                                     /*ESpecRange=*/SourceRange(),
3065
1.43k
                                     /*Exceptions=*/nullptr,
3066
1.43k
                                     /*ExceptionRanges=*/nullptr,
3067
1.43k
                                     /*NumExceptions=*/0,
3068
1.43k
                                     /*NoexceptExpr=*/nullptr,
3069
1.43k
                                     /*ExceptionSpecTokens=*/nullptr,
3070
1.43k
                                     /*DeclsInPrototype=*/None, CaretLoc,
3071
1.43k
                                     CaretLoc, ParamInfo),
3072
1.43k
        CaretLoc);
3073
1.43k
3074
1.43k
    MaybeParseGNUAttributes(ParamInfo);
3075
1.43k
3076
1.43k
    // Inform sema that we are starting a block.
3077
1.43k
    Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope());
3078
1.43k
  }
3079
2.71k
3080
2.71k
3081
2.71k
  ExprResult Result(true);
3082
2.71k
  if (!Tok.is(tok::l_brace)) {
3083
3
    // Saw something like: ^expr
3084
3
    Diag(Tok, diag::err_expected_expression);
3085
3
    Actions.ActOnBlockError(CaretLoc, getCurScope());
3086
3
    return ExprError();
3087
3
  }
3088
2.71k
3089
2.71k
  StmtResult Stmt(ParseCompoundStatementBody());
3090
2.71k
  BlockScope.Exit();
3091
2.71k
  if (!Stmt.isInvalid())
3092
2.71k
    Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.get(), getCurScope());
3093
0
  else
3094
0
    Actions.ActOnBlockError(CaretLoc, getCurScope());
3095
2.71k
  return Result;
3096
2.71k
}
3097
3098
/// ParseObjCBoolLiteral - This handles the objective-c Boolean literals.
3099
///
3100
///         '__objc_yes'
3101
///         '__objc_no'
3102
164
ExprResult Parser::ParseObjCBoolLiteral() {
3103
164
  tok::TokenKind Kind = Tok.getKind();
3104
164
  return Actions.ActOnObjCBoolLiteral(ConsumeToken(), Kind);
3105
164
}
3106
3107
/// Validate availability spec list, emitting diagnostics if necessary. Returns
3108
/// true if invalid.
3109
static bool CheckAvailabilitySpecList(Parser &P,
3110
76
                                      ArrayRef<AvailabilitySpec> AvailSpecs) {
3111
76
  llvm::SmallSet<StringRef, 4> Platforms;
3112
76
  bool HasOtherPlatformSpec = false;
3113
76
  bool Valid = true;
3114
160
  for (const auto &Spec : AvailSpecs) {
3115
160
    if (Spec.isOtherPlatformSpec()) {
3116
75
      if (HasOtherPlatformSpec) {
3117
0
        P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_star);
3118
0
        Valid = false;
3119
0
      }
3120
75
3121
75
      HasOtherPlatformSpec = true;
3122
75
      continue;
3123
75
    }
3124
85
3125
85
    bool Inserted = Platforms.insert(Spec.getPlatform()).second;
3126
85
    if (!Inserted) {
3127
1
      // Rule out multiple version specs referring to the same platform.
3128
1
      // For example, we emit an error for:
3129
1
      // @available(macos 10.10, macos 10.11, *)
3130
1
      StringRef Platform = Spec.getPlatform();
3131
1
      P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_platform)
3132
1
          << Spec.getEndLoc() << Platform;
3133
1
      Valid = false;
3134
1
    }
3135
85
  }
3136
76
3137
76
  if (!HasOtherPlatformSpec) {
3138
1
    SourceLocation InsertWildcardLoc = AvailSpecs.back().getEndLoc();
3139
1
    P.Diag(InsertWildcardLoc, diag::err_availability_query_wildcard_required)
3140
1
        << FixItHint::CreateInsertion(InsertWildcardLoc, ", *");
3141
1
    return true;
3142
1
  }
3143
75
3144
75
  return !Valid;
3145
75
}
3146
3147
/// Parse availability query specification.
3148
///
3149
///  availability-spec:
3150
///     '*'
3151
///     identifier version-tuple
3152
171
Optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
3153
171
  if (Tok.is(tok::star)) {
3154
77
    return AvailabilitySpec(ConsumeToken());
3155
94
  } else {
3156
94
    // Parse the platform name.
3157
94
    if (Tok.is(tok::code_completion)) {
3158
2
      Actions.CodeCompleteAvailabilityPlatformName();
3159
2
      cutOffParsing();
3160
2
      return None;
3161
2
    }
3162
92
    if (Tok.isNot(tok::identifier)) {
3163
2
      Diag(Tok, diag::err_avail_query_expected_platform_name);
3164
2
      return None;
3165
2
    }
3166
90
3167
90
    IdentifierLoc *PlatformIdentifier = ParseIdentifierLoc();
3168
90
    SourceRange VersionRange;
3169
90
    VersionTuple Version = ParseVersionTuple(VersionRange);
3170
90
3171
90
    if (Version.empty())
3172
1
      return None;
3173
89
3174
89
    StringRef GivenPlatform = PlatformIdentifier->Ident->getName();
3175
89
    StringRef Platform =
3176
89
        AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
3177
89
3178
89
    if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) {
3179
3
      Diag(PlatformIdentifier->Loc,
3180
3
           diag::err_avail_query_unrecognized_platform_name)
3181
3
          << GivenPlatform;
3182
3
      return None;
3183
3
    }
3184
86
3185
86
    return AvailabilitySpec(Version, Platform, PlatformIdentifier->Loc,
3186
86
                            VersionRange.getEnd());
3187
86
  }
3188
171
}
3189
3190
84
ExprResult Parser::ParseAvailabilityCheckExpr(SourceLocation BeginLoc) {
3191
84
  assert(Tok.is(tok::kw___builtin_available) ||
3192
84
         Tok.isObjCAtKeyword(tok::objc_available));
3193
84
3194
84
  // Eat the available or __builtin_available.
3195
84
  ConsumeToken();
3196
84
3197
84
  BalancedDelimiterTracker Parens(*this, tok::l_paren);
3198
84
  if (Parens.expectAndConsume())
3199
1
    return ExprError();
3200
83
3201
83
  SmallVector<AvailabilitySpec, 4> AvailSpecs;
3202
83
  bool HasError = false;
3203
171
  while (true) {
3204
171
    Optional<AvailabilitySpec> Spec = ParseAvailabilitySpec();
3205
171
    if (!Spec)
3206
8
      HasError = true;
3207
163
    else
3208
163
      AvailSpecs.push_back(*Spec);
3209
171
3210
171
    if (!TryConsumeToken(tok::comma))
3211
83
      break;
3212
171
  }
3213
83
3214
83
  if (HasError) {
3215
7
    SkipUntil(tok::r_paren, StopAtSemi);
3216
7
    return ExprError();
3217
7
  }
3218
76
3219
76
  CheckAvailabilitySpecList(*this, AvailSpecs);
3220
76
3221
76
  if (Parens.consumeClose())
3222
0
    return ExprError();
3223
76
3224
76
  return Actions.ActOnObjCAvailabilityCheckExpr(AvailSpecs, BeginLoc,
3225
76
                                                Parens.getCloseLocation());
3226
76
}