zequanwu updated this revision to Diff 277611. zequanwu added a comment. Accidentally uploaded binary.. removed now.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D83592/new/ https://reviews.llvm.org/D83592 Files: clang/lib/CodeGen/CodeGenAction.cpp clang/lib/CodeGen/CoverageMappingGen.cpp clang/lib/CodeGen/CoverageMappingGen.h Index: clang/lib/CodeGen/CoverageMappingGen.h =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.h +++ clang/lib/CodeGen/CoverageMappingGen.h @@ -16,6 +16,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" #include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" #include "llvm/ADT/DenseMap.h" #include "llvm/IR/GlobalValue.h" #include "llvm/Support/raw_ostream.h" @@ -32,12 +33,14 @@ /// Stores additional source code information like skipped ranges which /// is required by the coverage mapping generator and is obtained from /// the preprocessor. -class CoverageSourceInfo : public PPCallbacks { +class CoverageSourceInfo : public PPCallbacks, public CommentHandler { std::vector<SourceRange> SkippedRanges; public: ArrayRef<SourceRange> getSkippedRanges() const { return SkippedRanges; } void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override; + + bool HandleComment(Preprocessor &PP, SourceRange Range) override; }; namespace CodeGen { @@ -66,6 +69,8 @@ uint64_t FilenamesRef); public: + static CoverageSourceInfo *setUpCoverageCallbacks(Preprocessor &PP); + CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo) : CGM(CGM), SourceInfo(SourceInfo) {} Index: clang/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.cpp +++ clang/lib/CodeGen/CoverageMappingGen.cpp @@ -35,10 +35,23 @@ using namespace CodeGen; using namespace llvm::coverage; +CoverageSourceInfo * +CoverageMappingModuleGen::setUpCoverageCallbacks(Preprocessor &PP) { + CoverageSourceInfo *CoverageInfo = new CoverageSourceInfo; + PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(CoverageInfo)); + PP.addCommentHandler(CoverageInfo); + return CoverageInfo; +} + void CoverageSourceInfo::SourceRangeSkipped(SourceRange Range, SourceLocation) { SkippedRanges.push_back(Range); } +bool CoverageSourceInfo::HandleComment(Preprocessor &, SourceRange Range) { + SkippedRanges.push_back(Range); + return false; +} + namespace { /// A region of source code that can be mapped to a counter. Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -990,11 +990,9 @@ CoverageSourceInfo *CoverageInfo = nullptr; // Add the preprocessor callback only when the coverage mapping is generated. - if (CI.getCodeGenOpts().CoverageMapping) { - CoverageInfo = new CoverageSourceInfo; - CI.getPreprocessor().addPPCallbacks( - std::unique_ptr<PPCallbacks>(CoverageInfo)); - } + if (CI.getCodeGenOpts().CoverageMapping) + CoverageInfo = CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks( + CI.getPreprocessor()); std::unique_ptr<BackendConsumer> Result(new BackendConsumer( BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(),
Index: clang/lib/CodeGen/CoverageMappingGen.h =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.h +++ clang/lib/CodeGen/CoverageMappingGen.h @@ -16,6 +16,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" #include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" #include "llvm/ADT/DenseMap.h" #include "llvm/IR/GlobalValue.h" #include "llvm/Support/raw_ostream.h" @@ -32,12 +33,14 @@ /// Stores additional source code information like skipped ranges which /// is required by the coverage mapping generator and is obtained from /// the preprocessor. -class CoverageSourceInfo : public PPCallbacks { +class CoverageSourceInfo : public PPCallbacks, public CommentHandler { std::vector<SourceRange> SkippedRanges; public: ArrayRef<SourceRange> getSkippedRanges() const { return SkippedRanges; } void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override; + + bool HandleComment(Preprocessor &PP, SourceRange Range) override; }; namespace CodeGen { @@ -66,6 +69,8 @@ uint64_t FilenamesRef); public: + static CoverageSourceInfo *setUpCoverageCallbacks(Preprocessor &PP); + CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo) : CGM(CGM), SourceInfo(SourceInfo) {} Index: clang/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.cpp +++ clang/lib/CodeGen/CoverageMappingGen.cpp @@ -35,10 +35,23 @@ using namespace CodeGen; using namespace llvm::coverage; +CoverageSourceInfo * +CoverageMappingModuleGen::setUpCoverageCallbacks(Preprocessor &PP) { + CoverageSourceInfo *CoverageInfo = new CoverageSourceInfo; + PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(CoverageInfo)); + PP.addCommentHandler(CoverageInfo); + return CoverageInfo; +} + void CoverageSourceInfo::SourceRangeSkipped(SourceRange Range, SourceLocation) { SkippedRanges.push_back(Range); } +bool CoverageSourceInfo::HandleComment(Preprocessor &, SourceRange Range) { + SkippedRanges.push_back(Range); + return false; +} + namespace { /// A region of source code that can be mapped to a counter. Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -990,11 +990,9 @@ CoverageSourceInfo *CoverageInfo = nullptr; // Add the preprocessor callback only when the coverage mapping is generated. - if (CI.getCodeGenOpts().CoverageMapping) { - CoverageInfo = new CoverageSourceInfo; - CI.getPreprocessor().addPPCallbacks( - std::unique_ptr<PPCallbacks>(CoverageInfo)); - } + if (CI.getCodeGenOpts().CoverageMapping) + CoverageInfo = CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks( + CI.getPreprocessor()); std::unique_ptr<BackendConsumer> Result(new BackendConsumer( BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits