diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -319,6 +319,10 @@ virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) { } + /// Hood called when the source range is comment, which should be skipped. + /// \param Range The SourceRange that is comment. + virtual void CommentSkipped(SourceRange Range) {} + enum ConditionValueKind { CVK_NotEvaluated, CVK_False, CVK_True }; @@ -565,6 +569,11 @@ Second->SourceRangeSkipped(Range, EndifLoc); } + void CommentSkipped(SourceRange Range) override { + First->CommentSkipped(Range); + Second->CommentSkipped(Range); + } + /// Hook called whenever an \#if is seen. void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override { diff --git a/clang/lib/CodeGen/CoverageMappingGen.h b/clang/lib/CodeGen/CoverageMappingGen.h --- a/clang/lib/CodeGen/CoverageMappingGen.h +++ b/clang/lib/CodeGen/CoverageMappingGen.h @@ -38,6 +38,8 @@ ArrayRef getSkippedRanges() const { return SkippedRanges; } void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override; + + void CommentSkipped(SourceRange Range) override; }; namespace CodeGen { diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -39,6 +39,10 @@ SkippedRanges.push_back(Range); } +void CoverageSourceInfo::CommentSkipped(SourceRange Range) { + SkippedRanges.push_back(Range); +} + namespace { /// A region of source code that can be mapped to a counter. diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -34,6 +34,7 @@ explicit ActionCommentHandler(Sema &S) : S(S) { } bool HandleComment(Preprocessor &PP, SourceRange Comment) override { + PP.getPPCallbacks()->CommentSkipped(Comment); S.ActOnComment(Comment); return false; }