@@ -500,21 +500,43 @@ class ResultObjectVisitor : public RecursiveASTVisitor<ResultObjectVisitor> {
500
500
501
501
ResultObjectMap[E] = Loc;
502
502
503
+ switch (E->getStmtClass ()) {
503
504
// The following AST node kinds are "original initializers": They are the
504
505
// lowest-level AST node that initializes a given object, and nothing
505
506
// below them can initialize the same object (or part of it).
506
- if (isa<CXXConstructExpr>(E) || isa<CallExpr>(E) || isa<LambdaExpr>(E) ||
507
- isa<CXXDefaultArgExpr>(E) || isa<CXXDefaultInitExpr>(E) ||
508
- isa<CXXStdInitializerListExpr>(E)) {
507
+ case Stmt::CXXConstructExprClass:
508
+ case Stmt::CallExprClass:
509
+ case Stmt::LambdaExprClass:
510
+ case Stmt::CXXDefaultArgExprClass:
511
+ case Stmt::CXXDefaultInitExprClass:
512
+ case Stmt::CXXStdInitializerListExprClass:
513
+ return ;
514
+ case Stmt::BinaryOperatorClass: {
515
+ auto *Op = cast<BinaryOperator>(E);
516
+ if (Op->getOpcode () == BO_Cmp) {
517
+ // Builtin `<=>` returns a `std::strong_ordering` object. We
518
+ // consider this to be an "original" initializer too (see above).
519
+ return ;
520
+ }
521
+ if (Op->isCommaOp ()) {
522
+ PropagateResultObject (Op->getRHS (), Loc);
523
+ return ;
524
+ }
525
+ // We don't expect any other binary operators to produce a record
526
+ // prvalue, so if we get here, we've hit some case we don't know
527
+ // about.
528
+ assert (false );
509
529
return ;
510
530
}
511
- if (auto *Op = dyn_cast<BinaryOperator>(E);
512
- Op && Op->getOpcode () == BO_Cmp) {
513
- // Builtin `<=>` returns a `std::strong_ordering` object.
531
+ case Stmt::BinaryConditionalOperatorClass:
532
+ case Stmt::ConditionalOperatorClass: {
533
+ auto *Cond = cast<AbstractConditionalOperator>(E);
534
+ PropagateResultObject (Cond->getTrueExpr (), Loc);
535
+ PropagateResultObject (Cond->getFalseExpr (), Loc);
514
536
return ;
515
537
}
516
-
517
- if ( auto *InitList = dyn_cast <InitListExpr>(E)) {
538
+ case Stmt::InitListExprClass: {
539
+ auto *InitList = cast <InitListExpr>(E);
518
540
if (!InitList->isSemanticForm ())
519
541
return ;
520
542
if (InitList->isTransparent ()) {
@@ -544,28 +566,20 @@ class ResultObjectVisitor : public RecursiveASTVisitor<ResultObjectVisitor> {
544
566
}
545
567
return ;
546
568
}
547
-
548
- if (auto *Op = dyn_cast<BinaryOperator>(E); Op && Op->isCommaOp ()) {
549
- PropagateResultObject (Op->getRHS (), Loc);
569
+ default : {
570
+ // All other expression nodes that propagate a record prvalue should
571
+ // have exactly one child.
572
+ SmallVector<Stmt *, 1 > Children (E->child_begin (), E->child_end ());
573
+ LLVM_DEBUG ({
574
+ if (Children.size () != 1 )
575
+ E->dump ();
576
+ });
577
+ assert (Children.size () == 1 );
578
+ for (Stmt *S : Children)
579
+ PropagateResultObject (cast<Expr>(S), Loc);
550
580
return ;
551
581
}
552
-
553
- if (auto *Cond = dyn_cast<AbstractConditionalOperator>(E)) {
554
- PropagateResultObject (Cond->getTrueExpr (), Loc);
555
- PropagateResultObject (Cond->getFalseExpr (), Loc);
556
- return ;
557
582
}
558
-
559
- // All other expression nodes that propagate a record prvalue should have
560
- // exactly one child.
561
- SmallVector<Stmt *, 1 > Children (E->child_begin (), E->child_end ());
562
- LLVM_DEBUG ({
563
- if (Children.size () != 1 )
564
- E->dump ();
565
- });
566
- assert (Children.size () == 1 );
567
- for (Stmt *S : Children)
568
- PropagateResultObject (cast<Expr>(S), Loc);
569
583
}
570
584
571
585
private:
0 commit comments