@@ -1208,6 +1208,12 @@ struct CounterCoverageMappingBuilder
1208
1208
// / Find a valid gap range between \p AfterLoc and \p BeforeLoc.
1209
1209
std::optional<SourceRange> findGapAreaBetween (SourceLocation AfterLoc,
1210
1210
SourceLocation BeforeLoc) {
1211
+ // Some statements (like AttributedStmt and ImplicitValueInitExpr) don't
1212
+ // have valid source locations. Do not emit a gap region if this is the case
1213
+ // in either AfterLoc end or BeforeLoc end.
1214
+ if (AfterLoc.isInvalid () || BeforeLoc.isInvalid ())
1215
+ return std::nullopt;
1216
+
1211
1217
// If AfterLoc is in function-like macro, use the right parenthesis
1212
1218
// location.
1213
1219
if (AfterLoc.isMacroID ()) {
@@ -1368,9 +1374,8 @@ struct CounterCoverageMappingBuilder
1368
1374
for (const Stmt *Child : S->children ())
1369
1375
if (Child) {
1370
1376
// If last statement contains terminate statements, add a gap area
1371
- // between the two statements. Skipping attributed statements, because
1372
- // they don't have valid start location.
1373
- if (LastStmt && HasTerminateStmt && !isa<AttributedStmt>(Child)) {
1377
+ // between the two statements.
1378
+ if (LastStmt && HasTerminateStmt) {
1374
1379
auto Gap = findGapAreaBetween (getEnd (LastStmt), getStart (Child));
1375
1380
if (Gap)
1376
1381
fillGapAreaWithCount (Gap->getBegin (), Gap->getEnd (),
0 commit comments