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