@@ -1207,6 +1207,12 @@ struct CounterCoverageMappingBuilder
12071207 // / Find a valid gap range between \p AfterLoc and \p BeforeLoc.
12081208 std::optional<SourceRange> findGapAreaBetween (SourceLocation AfterLoc,
12091209 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+
12101216 // If AfterLoc is in function-like macro, use the right parenthesis
12111217 // location.
12121218 if (AfterLoc.isMacroID ()) {
@@ -1370,9 +1376,8 @@ struct CounterCoverageMappingBuilder
13701376 for (const Stmt *Child : S->children ())
13711377 if (Child) {
13721378 // 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) {
13761381 auto Gap = findGapAreaBetween (getEnd (LastStmt), getStart (Child));
13771382 if (Gap)
13781383 fillGapAreaWithCount (Gap->getBegin (), Gap->getEnd (),
0 commit comments