@@ -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);
@@ -2263,16 +2267,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
22632267 asc, ExternallyDestructed);
22642268
22652269 case Stmt::CXXDefaultArgExprClass:
2270+ return VisitCXXDefaultArgExpr (cast<CXXDefaultArgExpr>(S), asc);
2271+
22662272 case Stmt::CXXDefaultInitExprClass:
2267- // FIXME: The expression inside a CXXDefaultArgExpr is owned by the
2268- // called function's declaration, not by the caller. If we simply add
2269- // this expression to the CFG, we could end up with the same Expr
2270- // appearing multiple times (PR13385).
2271- //
2272- // It's likewise possible for multiple CXXDefaultInitExprs for the same
2273- // expression to be used in the same function (through aggregate
2274- // initialization).
2275- return VisitStmt (S, asc);
2273+ return VisitCXXDefaultInitExpr (cast<CXXDefaultInitExpr>(S), asc);
22762274
22772275 case Stmt::CXXBindTemporaryExprClass:
22782276 return VisitCXXBindTemporaryExpr (cast<CXXBindTemporaryExpr>(S), asc);
@@ -2442,6 +2440,44 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
24422440 return B;
24432441}
24442442
2443+ CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr (CXXDefaultArgExpr *Arg,
2444+ AddStmtChoice asc) {
2445+ if (Arg->hasRewrittenInit ()) {
2446+ if (asc.alwaysAdd (*this , Arg)) {
2447+ autoCreateBlock ();
2448+ appendStmt (Block, Arg);
2449+ }
2450+ return VisitStmt (Arg->getExpr ()->IgnoreParens (), asc);
2451+ }
2452+
2453+ // We can't add the default argument if it's not rewritten because the
2454+ // expression inside a CXXDefaultArgExpr is owned by the called function's
2455+ // declaration, not by the caller, we could end up with the same expression
2456+ // appearing multiple times.
2457+ return VisitStmt (Arg, asc);
2458+ }
2459+
2460+ CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr (CXXDefaultInitExpr *Init,
2461+ AddStmtChoice asc) {
2462+ if (Init->hasRewrittenInit ()) {
2463+ if (asc.alwaysAdd (*this , Init)) {
2464+ autoCreateBlock ();
2465+ appendStmt (Block, Init);
2466+ }
2467+
2468+ // Unlike CXXDefaultArgExpr::getExpr stripped off the top level FullExpr and
2469+ // ConstantExpr, CXXDefaultInitExpr::getExpr does not do this, so we don't
2470+ // need to ignore ParenExprs, because the top level will not be a ParenExpr.
2471+ return VisitStmt (Init->getExpr (), asc);
2472+ }
2473+
2474+ // We can't add the default initializer if it's not rewritten because multiple
2475+ // CXXDefaultInitExprs for the same sub-expression to be used in the same
2476+ // function (through aggregate initialization). we could end up with the same
2477+ // expression appearing multiple times.
2478+ return VisitStmt (Init, asc);
2479+ }
2480+
24452481CFGBlock *CFGBuilder::VisitInitListExpr (InitListExpr *ILE, AddStmtChoice asc) {
24462482 if (asc.alwaysAdd (*this , ILE)) {
24472483 autoCreateBlock ();
0 commit comments