Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Parse/ParseInit.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- ParseInit.cpp - Initializer 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
// This file implements initializer parsing as specified by C99 6.7.8.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Basic/TokenKinds.h"
14
#include "clang/Parse/ParseDiagnostic.h"
15
#include "clang/Parse/Parser.h"
16
#include "clang/Parse/RAIIObjectsForParser.h"
17
#include "clang/Sema/Designator.h"
18
#include "clang/Sema/Ownership.h"
19
#include "clang/Sema/Scope.h"
20
#include "llvm/ADT/STLExtras.h"
21
#include "llvm/ADT/SmallString.h"
22
using namespace clang;
23
24
25
/// MayBeDesignationStart - Return true if the current token might be the start
26
/// of a designator.  If we can tell it is impossible that it is a designator,
27
/// return false.
28
402k
bool Parser::MayBeDesignationStart() {
29
402k
  switch (Tok.getKind()) {
30
151k
  default:
31
151k
    return false;
32
33
1.55k
  case tok::period:      // designator: '.' identifier
34
1.55k
    return true;
35
36
412
  case tok::l_square: {  // designator: array-designator
37
412
    if (!PP.getLangOpts().CPlusPlus11)
38
247
      return true;
39
40
    // C++11 lambda expressions and C99 designators can be ambiguous all the
41
    // way through the closing ']' and to the next character. Handle the easy
42
    // cases here, and fall back to tentative parsing if those fail.
43
165
    switch (PP.LookAhead(0).getKind()) {
44
0
    case tok::equal:
45
8
    case tok::ellipsis:
46
31
    case tok::r_square:
47
      // Definitely starts a lambda expression.
48
31
      return false;
49
50
3
    case tok::amp:
51
6
    case tok::kw_this:
52
9
    case tok::star:
53
69
    case tok::identifier:
54
      // We have to do additional analysis, because these could be the
55
      // start of a constant expression or a lambda capture list.
56
69
      break;
57
58
65
    default:
59
      // Anything not mentioned above cannot occur following a '[' in a
60
      // lambda expression.
61
65
      return true;
62
165
    }
63
64
    // Handle the complicated case below.
65
69
    break;
66
165
  }
67
249k
  case tok::identifier:  // designation: identifier ':'
68
249k
    return PP.LookAhead(0).is(tok::colon);
69
402k
  }
70
71
  // Parse up to (at most) the token after the closing ']' to determine
72
  // whether this is a C99 designator or a lambda.
73
69
  RevertingTentativeParsingAction Tentative(*this);
74
75
69
  LambdaIntroducer Intro;
76
69
  LambdaIntroducerTentativeParse ParseResult;
77
69
  if (ParseLambdaIntroducer(Intro, &ParseResult)) {
78
    // Hit and diagnosed an error in a lambda.
79
    // FIXME: Tell the caller this happened so they can recover.
80
0
    return true;
81
0
  }
82
83
69
  switch (ParseResult) {
84
34
  case LambdaIntroducerTentativeParse::Success:
85
52
  case LambdaIntroducerTentativeParse::Incomplete:
86
    // Might be a lambda-expression. Keep looking.
87
    // FIXME: If our tentative parse was not incomplete, parse the lambda from
88
    // here rather than throwing away then reparsing the LambdaIntroducer.
89
52
    break;
90
91
12
  case LambdaIntroducerTentativeParse::MessageSend:
92
17
  case LambdaIntroducerTentativeParse::Invalid:
93
    // Can't be a lambda-expression. Treat it as a designator.
94
    // FIXME: Should we disambiguate against a message-send?
95
17
    return true;
96
69
  }
97
98
  // Once we hit the closing square bracket, we look at the next
99
  // token. If it's an '=', this is a designator. Otherwise, it's a
100
  // lambda expression. This decision favors lambdas over the older
101
  // GNU designator syntax, which allows one to omit the '=', but is
102
  // consistent with GCC.
103
52
  return Tok.is(tok::equal);
104
69
}
105
106
static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc,
107
68
                                       Designation &Desig) {
108
  // If we have exactly one array designator, this used the GNU
109
  // 'designation: array-designator' extension, otherwise there should be no
110
  // designators at all!
111
68
  if (Desig.getNumDesignators() == 1 &&
112
68
      
(12
Desig.getDesignator(0).isArrayDesignator()12
||
113
12
       
Desig.getDesignator(0).isArrayRangeDesignator()4
))
114
8
    P.Diag(Loc, diag::ext_gnu_missing_equal_designator);
115
60
  else if (Desig.getNumDesignators() > 0)
116
4
    P.Diag(Loc, diag::err_expected_equal_designator);
117
68
}
118
119
/// ParseInitializerWithPotentialDesignator - Parse the 'initializer' production
120
/// checking to see if the token stream starts with a designator.
121
///
122
/// C99:
123
///
124
///       designation:
125
///         designator-list '='
126
/// [GNU]   array-designator
127
/// [GNU]   identifier ':'
128
///
129
///       designator-list:
130
///         designator
131
///         designator-list designator
132
///
133
///       designator:
134
///         array-designator
135
///         '.' identifier
136
///
137
///       array-designator:
138
///         '[' constant-expression ']'
139
/// [GNU]   '[' constant-expression '...' constant-expression ']'
140
///
141
/// C++20:
142
///
143
///       designated-initializer-list:
144
///         designated-initializer-clause
145
///         designated-initializer-list ',' designated-initializer-clause
146
///
147
///       designated-initializer-clause:
148
///         designator brace-or-equal-initializer
149
///
150
///       designator:
151
///         '.' identifier
152
///
153
/// We allow the C99 syntax extensions in C++20, but do not allow the C++20
154
/// extension (a braced-init-list after the designator with no '=') in C99.
155
///
156
/// NOTE: [OBC] allows '[ objc-receiver objc-message-args ]' as an
157
/// initializer (because it is an expression).  We need to consider this case
158
/// when parsing array designators.
159
///
160
/// \p CodeCompleteCB is called with Designation parsed so far.
161
ExprResult Parser::ParseInitializerWithPotentialDesignator(
162
1.91k
    DesignatorCompletionInfo DesignatorCompletion) {
163
  // If this is the old-style GNU extension:
164
  //   designation ::= identifier ':'
165
  // Handle it as a field designator.  Otherwise, this must be the start of a
166
  // normal expression.
167
1.91k
  if (Tok.is(tok::identifier)) {
168
10
    const IdentifierInfo *FieldName = Tok.getIdentifierInfo();
169
170
10
    SmallString<256> NewSyntax;
171
10
    llvm::raw_svector_ostream(NewSyntax) << '.' << FieldName->getName()
172
10
                                         << " = ";
173
174
10
    SourceLocation NameLoc = ConsumeToken(); // Eat the identifier.
175
176
10
    assert(Tok.is(tok::colon) && "MayBeDesignationStart not working properly!");
177
0
    SourceLocation ColonLoc = ConsumeToken();
178
179
10
    Diag(NameLoc, diag::ext_gnu_old_style_field_designator)
180
10
      << FixItHint::CreateReplacement(SourceRange(NameLoc, ColonLoc),
181
10
                                      NewSyntax);
182
183
10
    Designation D;
184
10
    D.AddDesignator(Designator::getField(FieldName, SourceLocation(), NameLoc));
185
10
    PreferredType.enterDesignatedInitializer(
186
10
        Tok.getLocation(), DesignatorCompletion.PreferredBaseType, D);
187
10
    return Actions.ActOnDesignatedInitializer(D, ColonLoc, true,
188
10
                                              ParseInitializer());
189
10
  }
190
191
  // Desig - This is initialized when we see our first designator.  We may have
192
  // an objc message send with no designator, so we don't want to create this
193
  // eagerly.
194
1.90k
  Designation Desig;
195
196
  // Parse each designator in the designator list until we find an initializer.
197
4.04k
  while (Tok.is(tok::period) || 
Tok.is(tok::l_square)2.25k
) {
198
2.22k
    if (Tok.is(tok::period)) {
199
      // designator: '.' identifier
200
1.78k
      SourceLocation DotLoc = ConsumeToken();
201
202
1.78k
      if (Tok.is(tok::code_completion)) {
203
13
        cutOffParsing();
204
13
        Actions.CodeCompleteDesignator(DesignatorCompletion.PreferredBaseType,
205
13
                                       DesignatorCompletion.InitExprs, Desig);
206
13
        return ExprError();
207
13
      }
208
1.77k
      if (Tok.isNot(tok::identifier)) {
209
0
        Diag(Tok.getLocation(), diag::err_expected_field_designator);
210
0
        return ExprError();
211
0
      }
212
213
1.77k
      Desig.AddDesignator(Designator::getField(Tok.getIdentifierInfo(), DotLoc,
214
1.77k
                                               Tok.getLocation()));
215
1.77k
      ConsumeToken(); // Eat the identifier.
216
1.77k
      continue;
217
1.77k
    }
218
219
    // We must have either an array designator now or an objc message send.
220
434
    assert(Tok.is(tok::l_square) && "Unexpected token!");
221
222
    // Handle the two forms of array designator:
223
    //   array-designator: '[' constant-expression ']'
224
    //   array-designator: '[' constant-expression '...' constant-expression ']'
225
    //
226
    // Also, we have to handle the case where the expression after the
227
    // designator an an objc message send: '[' objc-message-expr ']'.
228
    // Interesting cases are:
229
    //   [foo bar]         -> objc message send
230
    //   [foo]             -> array designator
231
    //   [foo ... bar]     -> array designator
232
    //   [4][foo bar]      -> obsolete GNU designation with objc message send.
233
    //
234
    // We do not need to check for an expression starting with [[ here. If it
235
    // contains an Objective-C message send, then it is not an ill-formed
236
    // attribute. If it is a lambda-expression within an array-designator, then
237
    // it will be rejected because a constant-expression cannot begin with a
238
    // lambda-expression.
239
0
    InMessageExpressionRAIIObject InMessage(*this, true);
240
241
434
    BalancedDelimiterTracker T(*this, tok::l_square);
242
434
    T.consumeOpen();
243
434
    SourceLocation StartLoc = T.getOpenLocation();
244
245
434
    ExprResult Idx;
246
247
    // If Objective-C is enabled and this is a typename (class message
248
    // send) or send to 'super', parse this as a message send
249
    // expression.  We handle C++ and C separately, since C++ requires
250
    // much more complicated parsing.
251
434
    if  (getLangOpts().ObjC && 
getLangOpts().CPlusPlus96
) {
252
      // Send to 'super'.
253
58
      if (Tok.is(tok::identifier) && 
Tok.getIdentifierInfo() == Ident_super30
&&
254
58
          
NextToken().isNot(tok::period)3
&&
255
58
          
getCurScope()->isInObjcMethodScope()3
) {
256
3
        CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
257
3
        return ParseAssignmentExprWithObjCMessageExprStart(
258
3
            StartLoc, ConsumeToken(), nullptr, nullptr);
259
3
      }
260
261
      // Parse the receiver, which is either a type or an expression.
262
55
      bool IsExpr;
263
55
      void *TypeOrExpr;
264
55
      if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
265
0
        SkipUntil(tok::r_square, StopAtSemi);
266
0
        return ExprError();
267
0
      }
268
269
      // If the receiver was a type, we have a class message; parse
270
      // the rest of it.
271
55
      if (!IsExpr) {
272
20
        CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
273
20
        return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
274
20
                                                           SourceLocation(),
275
20
                                   ParsedType::getFromOpaquePtr(TypeOrExpr),
276
20
                                                           nullptr);
277
20
      }
278
279
      // If the receiver was an expression, we still don't know
280
      // whether we have a message send or an array designator; just
281
      // adopt the expression for further analysis below.
282
      // FIXME: potentially-potentially evaluated expression above?
283
35
      Idx = ExprResult(static_cast<Expr*>(TypeOrExpr));
284
376
    } else if (getLangOpts().ObjC && 
Tok.is(tok::identifier)38
) {
285
10
      IdentifierInfo *II = Tok.getIdentifierInfo();
286
10
      SourceLocation IILoc = Tok.getLocation();
287
10
      ParsedType ReceiverType;
288
      // Three cases. This is a message send to a type: [type foo]
289
      // This is a message send to super:  [super foo]
290
      // This is a message sent to an expr:  [super.bar foo]
291
10
      switch (Actions.getObjCMessageKind(
292
10
          getCurScope(), II, IILoc, II == Ident_super,
293
10
          NextToken().is(tok::period), ReceiverType)) {
294
1
      case Sema::ObjCSuperMessage:
295
1
        CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
296
1
        return ParseAssignmentExprWithObjCMessageExprStart(
297
1
            StartLoc, ConsumeToken(), nullptr, nullptr);
298
299
3
      case Sema::ObjCClassMessage:
300
3
        CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
301
3
        ConsumeToken(); // the identifier
302
3
        if (!ReceiverType) {
303
0
          SkipUntil(tok::r_square, StopAtSemi);
304
0
          return ExprError();
305
0
        }
306
307
        // Parse type arguments and protocol qualifiers.
308
3
        if (Tok.is(tok::less)) {
309
0
          SourceLocation NewEndLoc;
310
0
          TypeResult NewReceiverType
311
0
            = parseObjCTypeArgsAndProtocolQualifiers(IILoc, ReceiverType,
312
0
                                                     /*consumeLastToken=*/true,
313
0
                                                     NewEndLoc);
314
0
          if (!NewReceiverType.isUsable()) {
315
0
            SkipUntil(tok::r_square, StopAtSemi);
316
0
            return ExprError();
317
0
          }
318
319
0
          ReceiverType = NewReceiverType.get();
320
0
        }
321
322
3
        return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
323
3
                                                           SourceLocation(),
324
3
                                                           ReceiverType,
325
3
                                                           nullptr);
326
327
6
      case Sema::ObjCInstanceMessage:
328
        // Fall through; we'll just parse the expression and
329
        // (possibly) treat this like an Objective-C message send
330
        // later.
331
6
        break;
332
10
      }
333
10
    }
334
335
    // Parse the index expression, if we haven't already gotten one
336
    // above (which can only happen in Objective-C++).
337
    // Note that we parse this as an assignment expression, not a constant
338
    // expression (allowing *=, =, etc) to handle the objc case.  Sema needs
339
    // to validate that the expression is a constant.
340
    // FIXME: We also need to tell Sema that we're in a
341
    // potentially-potentially evaluated context.
342
407
    if (!Idx.get()) {
343
372
      Idx = ParseAssignmentExpression();
344
372
      if (Idx.isInvalid()) {
345
0
        SkipUntil(tok::r_square, StopAtSemi);
346
0
        return Idx;
347
0
      }
348
372
    }
349
350
    // Given an expression, we could either have a designator (if the next
351
    // tokens are '...' or ']' or an objc message send.  If this is an objc
352
    // message send, handle it now.  An objc-message send is the start of
353
    // an assignment-expression production.
354
407
    if (getLangOpts().ObjC && 
Tok.isNot(tok::ellipsis)69
&&
355
407
        
Tok.isNot(tok::r_square)69
) {
356
41
      CheckArrayDesignatorSyntax(*this, Tok.getLocation(), Desig);
357
41
      return ParseAssignmentExprWithObjCMessageExprStart(
358
41
          StartLoc, SourceLocation(), nullptr, Idx.get());
359
41
    }
360
361
    // If this is a normal array designator, remember it.
362
366
    if (Tok.isNot(tok::ellipsis)) {
363
346
      Desig.AddDesignator(Designator::getArray(Idx.get(), StartLoc));
364
346
    } else {
365
      // Handle the gnu array range extension.
366
20
      Diag(Tok, diag::ext_gnu_array_range);
367
20
      SourceLocation EllipsisLoc = ConsumeToken();
368
369
20
      ExprResult RHS(ParseConstantExpression());
370
20
      if (RHS.isInvalid()) {
371
0
        SkipUntil(tok::r_square, StopAtSemi);
372
0
        return RHS;
373
0
      }
374
20
      Desig.AddDesignator(Designator::getArrayRange(Idx.get(),
375
20
                                                    RHS.get(),
376
20
                                                    StartLoc, EllipsisLoc));
377
20
    }
378
379
366
    T.consumeClose();
380
366
    Desig.getDesignator(Desig.getNumDesignators() - 1).setRBracketLoc(
381
366
                                                        T.getCloseLocation());
382
366
  }
383
384
  // Okay, we're done with the designator sequence.  We know that there must be
385
  // at least one designator, because the only case we can get into this method
386
  // without a designator is when we have an objc message send.  That case is
387
  // handled and returned from above.
388
1.82k
  assert(!Desig.empty() && "Designator is empty?");
389
390
  // Handle a normal designator sequence end, which is an equal.
391
1.82k
  if (Tok.is(tok::equal)) {
392
1.80k
    SourceLocation EqualLoc = ConsumeToken();
393
1.80k
    PreferredType.enterDesignatedInitializer(
394
1.80k
        Tok.getLocation(), DesignatorCompletion.PreferredBaseType, Desig);
395
1.80k
    return Actions.ActOnDesignatedInitializer(Desig, EqualLoc, false,
396
1.80k
                                              ParseInitializer());
397
1.80k
  }
398
399
  // Handle a C++20 braced designated initialization, which results in
400
  // direct-list-initialization of the aggregate element. We allow this as an
401
  // extension from C++11 onwards (when direct-list-initialization was added).
402
24
  if (Tok.is(tok::l_brace) && 
getLangOpts().CPlusPlus1116
) {
403
14
    PreferredType.enterDesignatedInitializer(
404
14
        Tok.getLocation(), DesignatorCompletion.PreferredBaseType, Desig);
405
14
    return Actions.ActOnDesignatedInitializer(Desig, SourceLocation(), false,
406
14
                                              ParseBraceInitializer());
407
14
  }
408
409
  // We read some number of designators and found something that isn't an = or
410
  // an initializer.  If we have exactly one array designator, this
411
  // is the GNU 'designation: array-designator' extension.  Otherwise, it is a
412
  // parse error.
413
10
  if (Desig.getNumDesignators() == 1 &&
414
10
      
(9
Desig.getDesignator(0).isArrayDesignator()9
||
415
9
       
Desig.getDesignator(0).isArrayRangeDesignator()2
)) {
416
7
    Diag(Tok, diag::ext_gnu_missing_equal_designator)
417
7
      << FixItHint::CreateInsertion(Tok.getLocation(), "= ");
418
7
    return Actions.ActOnDesignatedInitializer(Desig, Tok.getLocation(),
419
7
                                              true, ParseInitializer());
420
7
  }
421
422
3
  Diag(Tok, diag::err_expected_equal_designator);
423
3
  return ExprError();
424
10
}
425
426
/// ParseBraceInitializer - Called when parsing an initializer that has a
427
/// leading open brace.
428
///
429
///       initializer: [C99 6.7.8]
430
///         '{' initializer-list '}'
431
///         '{' initializer-list ',' '}'
432
/// [GNU]   '{' '}'
433
///
434
///       initializer-list:
435
///         designation[opt] initializer ...[opt]
436
///         initializer-list ',' designation[opt] initializer ...[opt]
437
///
438
96.4k
ExprResult Parser::ParseBraceInitializer() {
439
96.4k
  InMessageExpressionRAIIObject InMessage(*this, false);
440
441
96.4k
  BalancedDelimiterTracker T(*this, tok::l_brace);
442
96.4k
  T.consumeOpen();
443
96.4k
  SourceLocation LBraceLoc = T.getOpenLocation();
444
445
  /// InitExprs - This is the actual list of expressions contained in the
446
  /// initializer.
447
96.4k
  ExprVector InitExprs;
448
449
96.4k
  if (Tok.is(tok::r_brace)) {
450
    // Empty initializers are a C++ feature and a GNU extension to C.
451
12.4k
    if (!getLangOpts().CPlusPlus)
452
677
      Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
453
    // Match the '}'.
454
12.4k
    return Actions.ActOnInitList(LBraceLoc, None, ConsumeBrace());
455
12.4k
  }
456
457
  // Enter an appropriate expression evaluation context for an initializer list.
458
83.9k
  EnterExpressionEvaluationContext EnterContext(
459
83.9k
      Actions, EnterExpressionEvaluationContext::InitList);
460
461
83.9k
  bool InitExprsOk = true;
462
83.9k
  DesignatorCompletionInfo DesignatorCompletion{
463
83.9k
      InitExprs,
464
83.9k
      PreferredType.get(T.getOpenLocation()),
465
83.9k
  };
466
467
402k
  while (1) {
468
    // Handle Microsoft __if_exists/if_not_exists if necessary.
469
402k
    if (getLangOpts().MicrosoftExt && 
(12.4k
Tok.is(tok::kw___if_exists)12.4k
||
470
12.4k
        
Tok.is(tok::kw___if_not_exists)12.4k
)) {
471
9
      if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) {
472
0
        if (Tok.isNot(tok::comma)) break;
473
0
        ConsumeToken();
474
0
      }
475
9
      if (Tok.is(tok::r_brace)) 
break0
;
476
9
      continue;
477
9
    }
478
479
    // Parse: designation[opt] initializer
480
481
    // If we know that this cannot be a designation, just parse the nested
482
    // initializer directly.
483
402k
    ExprResult SubElt;
484
402k
    if (MayBeDesignationStart())
485
1.91k
      SubElt = ParseInitializerWithPotentialDesignator(DesignatorCompletion);
486
400k
    else
487
400k
      SubElt = ParseInitializer();
488
489
402k
    if (Tok.is(tok::ellipsis))
490
133
      SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
491
492
402k
    SubElt = Actions.CorrectDelayedTyposInExpr(SubElt.get());
493
494
    // If we couldn't parse the subelement, bail out.
495
402k
    if (SubElt.isUsable()) {
496
402k
      InitExprs.push_back(SubElt.get());
497
402k
    } else {
498
64
      InitExprsOk = false;
499
500
      // We have two ways to try to recover from this error: if the code looks
501
      // grammatically ok (i.e. we have a comma coming up) try to continue
502
      // parsing the rest of the initializer.  This allows us to emit
503
      // diagnostics for later elements that we find.  If we don't see a comma,
504
      // assume there is a parse error, and just skip to recover.
505
      // FIXME: This comment doesn't sound right. If there is a r_brace
506
      // immediately, it can't be an error, since there is no other way of
507
      // leaving this loop except through this if.
508
64
      if (Tok.isNot(tok::comma)) {
509
58
        SkipUntil(tok::r_brace, StopBeforeMatch);
510
58
        break;
511
58
      }
512
64
    }
513
514
    // If we don't have a comma continued list, we're done.
515
402k
    if (Tok.isNot(tok::comma)) 
break83.2k
;
516
517
    // TODO: save comma locations if some client cares.
518
319k
    ConsumeToken();
519
520
    // Handle trailing comma.
521
319k
    if (Tok.is(tok::r_brace)) 
break670
;
522
319k
  }
523
524
83.9k
  bool closed = !T.consumeClose();
525
526
83.9k
  if (InitExprsOk && 
closed83.9k
)
527
83.9k
    return Actions.ActOnInitList(LBraceLoc, InitExprs,
528
83.9k
                                 T.getCloseLocation());
529
530
60
  return ExprError(); // an error occurred.
531
83.9k
}
532
533
534
// Return true if a comma (or closing brace) is necessary after the
535
// __if_exists/if_not_exists statement.
536
bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
537
9
                                                    bool &InitExprsOk) {
538
9
  bool trailingComma = false;
539
9
  IfExistsCondition Result;
540
9
  if (ParseMicrosoftIfExistsCondition(Result))
541
0
    return false;
542
543
9
  BalancedDelimiterTracker Braces(*this, tok::l_brace);
544
9
  if (Braces.consumeOpen()) {
545
0
    Diag(Tok, diag::err_expected) << tok::l_brace;
546
0
    return false;
547
0
  }
548
549
9
  switch (Result.Behavior) {
550
4
  case IEB_Parse:
551
    // Parse the declarations below.
552
4
    break;
553
554
1
  case IEB_Dependent:
555
1
    Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
556
1
      << Result.IsIfExists;
557
    // Fall through to skip.
558
1
    LLVM_FALLTHROUGH;
559
560
5
  case IEB_Skip:
561
5
    Braces.skipToEnd();
562
5
    return false;
563
9
  }
564
565
4
  DesignatorCompletionInfo DesignatorCompletion{
566
4
      InitExprs,
567
4
      PreferredType.get(Braces.getOpenLocation()),
568
4
  };
569
4
  while (!isEofOrEom()) {
570
4
    trailingComma = false;
571
    // If we know that this cannot be a designation, just parse the nested
572
    // initializer directly.
573
4
    ExprResult SubElt;
574
4
    if (MayBeDesignationStart())
575
0
      SubElt = ParseInitializerWithPotentialDesignator(DesignatorCompletion);
576
4
    else
577
4
      SubElt = ParseInitializer();
578
579
4
    if (Tok.is(tok::ellipsis))
580
0
      SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
581
582
    // If we couldn't parse the subelement, bail out.
583
4
    if (!SubElt.isInvalid())
584
4
      InitExprs.push_back(SubElt.get());
585
0
    else
586
0
      InitExprsOk = false;
587
588
4
    if (Tok.is(tok::comma)) {
589
4
      ConsumeToken();
590
4
      trailingComma = true;
591
4
    }
592
593
4
    if (Tok.is(tok::r_brace))
594
4
      break;
595
4
  }
596
597
4
  Braces.consumeClose();
598
599
4
  return !trailingComma;
600
9
}