@@ -556,6 +556,10 @@ class CFGBuilder {
556
556
557
557
private:
558
558
// 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);
559
563
CFGBlock *VisitInitListExpr (InitListExpr *ILE, AddStmtChoice asc);
560
564
CFGBlock *VisitAddrLabelExpr (AddrLabelExpr *A, AddStmtChoice asc);
561
565
CFGBlock *VisitAttributedStmt (AttributedStmt *A, AddStmtChoice asc);
@@ -2261,16 +2265,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
2261
2265
asc, ExternallyDestructed);
2262
2266
2263
2267
case Stmt::CXXDefaultArgExprClass:
2268
+ return VisitCXXDefaultArgExpr (cast<CXXDefaultArgExpr>(S), asc);
2269
+
2264
2270
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);
2274
2272
2275
2273
case Stmt::CXXBindTemporaryExprClass:
2276
2274
return VisitCXXBindTemporaryExpr (cast<CXXBindTemporaryExpr>(S), asc);
@@ -2440,6 +2438,40 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
2440
2438
return B;
2441
2439
}
2442
2440
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
+
2443
2475
CFGBlock *CFGBuilder::VisitInitListExpr (InitListExpr *ILE, AddStmtChoice asc) {
2444
2476
if (asc.alwaysAdd (*this , ILE)) {
2445
2477
autoCreateBlock ();
0 commit comments