Skip to content

Commit 3d9b908

Browse files
committed
[Coverage] Don't assign counter expressions to non-existent AST nodes (NFC)
1 parent 54031f1 commit 3d9b908

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/SILGen/SILGenProfiling.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ struct CoverageMapping : public ASTWalker {
290290

291291
/// \brief Create a counter expression for \c Node and add it to the map.
292292
CounterExpr &assignCounter(ASTNode Node, CounterExpr &&Expr) {
293+
assert(Node && "Assigning counter expression to non-existent AST node");
293294
CounterExpr &Result = createCounter(std::move(Expr));
294295
CounterMap[Node] = &Result;
295296
return Result;
@@ -491,8 +492,9 @@ struct CoverageMapping : public ASTWalker {
491492
} else if (auto *IS = dyn_cast<IfStmt>(S)) {
492493
assignCounter(IS, CounterExpr::Zero());
493494
CounterExpr &ThenCounter = assignCounter(IS->getThenStmt());
494-
assignCounter(IS->getElseStmt(),
495-
CounterExpr::Sub(getCurrentCounter(), ThenCounter));
495+
if (IS->getElseStmt())
496+
assignCounter(IS->getElseStmt(),
497+
CounterExpr::Sub(getCurrentCounter(), ThenCounter));
496498
} else if (auto *GS = dyn_cast<GuardStmt>(S)) {
497499
assignCounter(GS, CounterExpr::Zero());
498500
assignCounter(GS->getBody());

0 commit comments

Comments
 (0)