@@ -556,6 +556,10 @@ class CFGBuilder {
556556
557557private:
558558 // Visitors to walk an AST and construct the CFG.
559+ CFGBlock *VisitCXXDefaultArgExpr (CXXDefaultArgExpr *Default,
560+ AddStmtChoice asc);
561+ CFGBlock *VisitCXXDefaultInitExpr (CXXDefaultInitExpr *Default,
562+ AddStmtChoice asc);
559563 CFGBlock *VisitInitListExpr (InitListExpr *ILE, AddStmtChoice asc);
560564 CFGBlock *VisitAddrLabelExpr (AddrLabelExpr *A, AddStmtChoice asc);
561565 CFGBlock *VisitAttributedStmt (AttributedStmt *A, AddStmtChoice asc);
@@ -2261,16 +2265,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
22612265 asc, ExternallyDestructed);
22622266
22632267 case Stmt::CXXDefaultArgExprClass:
2268+ return VisitCXXDefaultArgExpr (cast<CXXDefaultArgExpr>(S), asc);
2269+
22642270 case Stmt::CXXDefaultInitExprClass:
2265- // FIXME: The expression inside a CXXDefaultArgExpr is owned by the
2266- // called function's declaration, not by the caller. If we simply add
2267- // this expression to the CFG, we could end up with the same Expr
2268- // appearing multiple times (PR13385).
2269- //
2270- // It's likewise possible for multiple CXXDefaultInitExprs for the same
2271- // expression to be used in the same function (through aggregate
2272- // initialization).
2273- return VisitStmt (S, asc);
2271+ return VisitCXXDefaultInitExpr (cast<CXXDefaultInitExpr>(S), asc);
22742272
22752273 case Stmt::CXXBindTemporaryExprClass:
22762274 return VisitCXXBindTemporaryExpr (cast<CXXBindTemporaryExpr>(S), asc);
@@ -2440,6 +2438,40 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
24402438 return B;
24412439}
24422440
2441+ CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr (CXXDefaultArgExpr *Arg,
2442+ AddStmtChoice asc) {
2443+ if (Arg->hasRewrittenInit ()) {
2444+ if (asc.alwaysAdd (*this , Arg)) {
2445+ autoCreateBlock ();
2446+ appendStmt (Block, Arg);
2447+ }
2448+ return VisitStmt (Arg->getExpr (), asc);
2449+ }
2450+
2451+ // We can't add the default argument if it's not rewritten because the
2452+ // expression inside a CXXDefaultArgExpr is owned by the called function's
2453+ // declaration, not by the caller, we could end up with the same expression
2454+ // appearing multiple times.
2455+ return VisitStmt (Arg, asc);
2456+ }
2457+
2458+ CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr (CXXDefaultInitExpr *Init,
2459+ AddStmtChoice asc) {
2460+ if (Init->hasRewrittenInit ()) {
2461+ if (asc.alwaysAdd (*this , Init)) {
2462+ autoCreateBlock ();
2463+ appendStmt (Block, Init);
2464+ }
2465+ return VisitStmt (Init->getExpr (), asc);
2466+ }
2467+
2468+ // We can't add the default initializer if it's not rewritten because multiple
2469+ // CXXDefaultInitExprs for the same sub-expression to be used in the same
2470+ // function (through aggregate initialization). we could end up with the same
2471+ // expression appearing multiple times.
2472+ return VisitStmt (Init, asc);
2473+ }
2474+
24432475CFGBlock *CFGBuilder::VisitInitListExpr (InitListExpr *ILE, AddStmtChoice asc) {
24442476 if (asc.alwaysAdd (*this , ILE)) {
24452477 autoCreateBlock ();
0 commit comments