@@ -757,8 +757,9 @@ struct CoverageMapping : public ASTWalker {
757
757
Res.first ->second = std::move (Expr);
758
758
}
759
759
760
- // / Create a counter expression referencing \c Node's own counter.
761
- CounterExpr assignCounter (ASTNode Node) {
760
+ // / Create a counter expression referencing \c Node's own counter. This must
761
+ // / have been previously mapped by MapRegionCounters.
762
+ CounterExpr assignKnownCounter (ASTNode Node) {
762
763
auto Counter = CounterExpr::Leaf (Node);
763
764
assignCounter (Node, Counter);
764
765
return Counter;
@@ -966,10 +967,10 @@ struct CoverageMapping : public ASTWalker {
966
967
PreWalkAction walkToDeclPre (Decl *D) override {
967
968
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
968
969
return visitFunctionDecl (*this , AFD, [&] {
969
- assignCounter (AFD->getBody ());
970
+ assignKnownCounter (AFD->getBody ());
970
971
});
971
972
} else if (auto *TLCD = dyn_cast<TopLevelCodeDecl>(D)) {
972
- assignCounter (TLCD->getBody ());
973
+ assignKnownCounter (TLCD->getBody ());
973
974
ImplicitTopLevelBody = TLCD->getBody ();
974
975
return Action::Continue ();
975
976
}
@@ -1005,15 +1006,15 @@ struct CoverageMapping : public ASTWalker {
1005
1006
1006
1007
// We emit a counter for the then block, and define the else block in
1007
1008
// terms of it.
1008
- auto ThenCounter = assignCounter (IS->getThenStmt ());
1009
+ auto ThenCounter = assignKnownCounter (IS->getThenStmt ());
1009
1010
if (IS->getElseStmt ()) {
1010
1011
auto ElseCounter =
1011
1012
CounterExpr::Sub (getCurrentCounter (), ThenCounter, CounterAlloc);
1012
1013
assignCounter (IS->getElseStmt (), ElseCounter);
1013
1014
}
1014
1015
} else if (auto *GS = dyn_cast<GuardStmt>(S)) {
1015
1016
assignCounter (GS, CounterExpr::Zero ());
1016
- assignCounter (GS->getBody ());
1017
+ assignKnownCounter (GS->getBody ());
1017
1018
1018
1019
} else if (auto *WS = dyn_cast<WhileStmt>(S)) {
1019
1020
// The counter for the while statement itself tracks the number of jumps
@@ -1022,22 +1023,22 @@ struct CoverageMapping : public ASTWalker {
1022
1023
1023
1024
if (auto *E = getConditionNode (WS->getCond ()))
1024
1025
assignCounter (E, getCurrentCounter ());
1025
- assignCounter (WS->getBody ());
1026
+ assignKnownCounter (WS->getBody ());
1026
1027
1027
1028
} else if (auto *RWS = dyn_cast<RepeatWhileStmt>(S)) {
1028
1029
// The counter for the while statement itself tracks the number of jumps
1029
1030
// to it by break and continue statements.
1030
1031
assignCounter (RWS, CounterExpr::Zero ());
1031
1032
1032
- auto BodyCounter = assignCounter (RWS->getBody ());
1033
+ auto BodyCounter = assignKnownCounter (RWS->getBody ());
1033
1034
assignCounter (RWS->getCond (), BodyCounter);
1034
1035
RepeatWhileStack.push_back (RWS);
1035
1036
1036
1037
} else if (auto *FES = dyn_cast<ForEachStmt>(S)) {
1037
1038
// The counter for the for statement itself tracks the number of jumps
1038
1039
// to it by break and continue statements.
1039
1040
assignCounter (FES, CounterExpr::Zero ());
1040
- assignCounter (FES->getBody ());
1041
+ assignKnownCounter (FES->getBody ());
1041
1042
1042
1043
} else if (auto *SS = dyn_cast<SwitchStmt>(S)) {
1043
1044
// The counter for the switch statement itself tracks the number of jumps
@@ -1049,7 +1050,7 @@ struct CoverageMapping : public ASTWalker {
1049
1050
1050
1051
// Assign counters for cases so they're available for fallthrough.
1051
1052
for (CaseStmt *Case : SS->getCases ())
1052
- assignCounter (Case);
1053
+ assignKnownCounter (Case);
1053
1054
1054
1055
} else if (auto caseStmt = dyn_cast<CaseStmt>(S)) {
1055
1056
if (caseStmt->getParentKind () == CaseParentKind::Switch)
@@ -1066,7 +1067,7 @@ struct CoverageMapping : public ASTWalker {
1066
1067
assignCounter (DCS->getBody (), getCurrentCounter ());
1067
1068
1068
1069
for (CaseStmt *Catch : DCS->getCatches ())
1069
- assignCounter (Catch->getBody ());
1070
+ assignKnownCounter (Catch->getBody ());
1070
1071
1071
1072
// Initialize the exit count of the do-catch to the entry count, then
1072
1073
// subtract off non-local exits as they are visited.
@@ -1183,19 +1184,19 @@ struct CoverageMapping : public ASTWalker {
1183
1184
if (Parent.isNull ()) {
1184
1185
assert (RegionStack.empty () &&
1185
1186
" Mapped a region before visiting the root?" );
1186
- assignCounter (E);
1187
+ assignKnownCounter (E);
1187
1188
}
1188
1189
1189
1190
if (isa<LazyInitializerExpr>(E))
1190
- assignCounter (E);
1191
+ assignKnownCounter (E);
1191
1192
1192
1193
if (hasCounter (E))
1193
1194
pushRegion (E);
1194
1195
1195
1196
assert (!RegionStack.empty () && " Must be within a region" );
1196
1197
1197
1198
if (auto *IE = dyn_cast<TernaryExpr>(E)) {
1198
- auto ThenCounter = assignCounter (IE->getThenExpr ());
1199
+ auto ThenCounter = assignKnownCounter (IE->getThenExpr ());
1199
1200
auto ElseCounter =
1200
1201
CounterExpr::Sub (getCurrentCounter (), ThenCounter, CounterAlloc);
1201
1202
assignCounter (IE->getElseExpr (), ElseCounter);
0 commit comments