forked from OSchip/llvm-project
[Coverage] Add comment to skipped regions
Bug filled here: https://bugs.llvm.org/show_bug.cgi?id=45757. Add comment to skipped regions so we don't track execution count for lines containing only comments. Differential Revision: https://reviews.llvm.org/D84208
This commit is contained in:
parent
ace0bf7490
commit
abd45154bd
|
@ -419,6 +419,9 @@ class Preprocessor {
|
|||
/// The number of (LexLevel 0) preprocessor tokens.
|
||||
unsigned TokenCount = 0;
|
||||
|
||||
/// Preprocess every token regardless of LexLevel.
|
||||
bool PreprocessToken = false;
|
||||
|
||||
/// The maximum number of (LexLevel 0) tokens before issuing a -Wmax-tokens
|
||||
/// warning, or zero for unlimited.
|
||||
unsigned MaxTokens = 0;
|
||||
|
@ -1038,6 +1041,8 @@ public:
|
|||
OnToken = std::move(F);
|
||||
}
|
||||
|
||||
void setPreprocessToken(bool Preprocess) { PreprocessToken = Preprocess; }
|
||||
|
||||
bool isMacroDefined(StringRef Id) {
|
||||
return isMacroDefined(&Identifiers.get(Id));
|
||||
}
|
||||
|
|
|
@ -990,11 +990,9 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
|||
|
||||
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(),
|
||||
|
|
|
@ -35,8 +35,40 @@ using namespace clang;
|
|||
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);
|
||||
PP.setPreprocessToken(true);
|
||||
PP.setTokenWatcher([CoverageInfo](clang::Token Tok) {
|
||||
// Update previous token location.
|
||||
CoverageInfo->PrevTokLoc = Tok.getLocation();
|
||||
CoverageInfo->updateNextTokLoc(Tok.getLocation());
|
||||
});
|
||||
return CoverageInfo;
|
||||
}
|
||||
|
||||
void CoverageSourceInfo::SourceRangeSkipped(SourceRange Range, SourceLocation) {
|
||||
SkippedRanges.push_back(Range);
|
||||
SkippedRanges.push_back({Range});
|
||||
}
|
||||
|
||||
bool CoverageSourceInfo::HandleComment(Preprocessor &PP, SourceRange Range) {
|
||||
if (PrevTokLoc.isValid() && PrevTokLoc == BeforeCommentLoc)
|
||||
SkippedRanges.back().Range.setEnd(Range.getEnd());
|
||||
else {
|
||||
SkippedRanges.push_back({Range, PrevTokLoc});
|
||||
BeforeCommentLoc = PrevTokLoc;
|
||||
}
|
||||
LastCommentIndex = SkippedRanges.size() - 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CoverageSourceInfo::updateNextTokLoc(SourceLocation Loc) {
|
||||
if (LastCommentIndex) {
|
||||
SkippedRanges[LastCommentIndex.getValue()].NextTokLoc = Loc;
|
||||
LastCommentIndex = None;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -274,8 +306,34 @@ public:
|
|||
return None;
|
||||
}
|
||||
|
||||
/// This shrinks the skipped range if it spans a line that contains a
|
||||
/// non-comment token. If shrinking the skipped range would make it empty,
|
||||
/// this returns None.
|
||||
Optional<SpellingRegion> adjustSkippedRange(SourceManager &SM,
|
||||
SpellingRegion SR,
|
||||
SourceLocation PrevTokLoc,
|
||||
SourceLocation NextTokLoc) {
|
||||
// If Range begin location is invalid, it's not a comment region.
|
||||
if (PrevTokLoc.isInvalid())
|
||||
return SR;
|
||||
unsigned PrevTokLine = SM.getSpellingLineNumber(PrevTokLoc);
|
||||
unsigned NextTokLine = SM.getSpellingLineNumber(NextTokLoc);
|
||||
SpellingRegion newSR(SR);
|
||||
if (SR.LineStart == PrevTokLine) {
|
||||
newSR.LineStart = SR.LineStart + 1;
|
||||
newSR.ColumnStart = 1;
|
||||
}
|
||||
if (SR.LineEnd == NextTokLine) {
|
||||
newSR.LineEnd = SR.LineEnd - 1;
|
||||
newSR.ColumnEnd = 1;
|
||||
}
|
||||
if (newSR.isInSourceOrder())
|
||||
return newSR;
|
||||
return None;
|
||||
}
|
||||
|
||||
/// Gather all the regions that were skipped by the preprocessor
|
||||
/// using the constructs like #if.
|
||||
/// using the constructs like #if or comments.
|
||||
void gatherSkippedRegions() {
|
||||
/// An array of the minimum lineStarts and the maximum lineEnds
|
||||
/// for mapping regions from the appropriate source files.
|
||||
|
@ -291,9 +349,10 @@ public:
|
|||
}
|
||||
|
||||
auto SkippedRanges = CVM.getSourceInfo().getSkippedRanges();
|
||||
for (const auto &I : SkippedRanges) {
|
||||
auto LocStart = I.getBegin();
|
||||
auto LocEnd = I.getEnd();
|
||||
for (auto &I : SkippedRanges) {
|
||||
SourceRange Range = I.Range;
|
||||
auto LocStart = Range.getBegin();
|
||||
auto LocEnd = Range.getEnd();
|
||||
assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
|
||||
"region spans multiple files");
|
||||
|
||||
|
@ -301,6 +360,11 @@ public:
|
|||
if (!CovFileID)
|
||||
continue;
|
||||
SpellingRegion SR{SM, LocStart, LocEnd};
|
||||
if (Optional<SpellingRegion> res =
|
||||
adjustSkippedRange(SM, SR, I.PrevTokLoc, I.NextTokLoc))
|
||||
SR = res.getValue();
|
||||
else
|
||||
continue;
|
||||
auto Region = CounterMappingRegion::makeSkipped(
|
||||
*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd, SR.ColumnEnd);
|
||||
// Make sure that we only collect the regions that are inside
|
||||
|
|
|
@ -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"
|
||||
|
@ -29,15 +30,42 @@ class Preprocessor;
|
|||
class Decl;
|
||||
class Stmt;
|
||||
|
||||
struct SkippedRange {
|
||||
SourceRange Range;
|
||||
// The location of token before the skipped source range.
|
||||
SourceLocation PrevTokLoc;
|
||||
// The location of token after the skipped source range.
|
||||
SourceLocation NextTokLoc;
|
||||
|
||||
SkippedRange(SourceRange Range, SourceLocation PrevTokLoc = SourceLocation(),
|
||||
SourceLocation NextTokLoc = SourceLocation())
|
||||
: Range(Range), PrevTokLoc(PrevTokLoc), NextTokLoc(NextTokLoc) {}
|
||||
};
|
||||
|
||||
/// 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 {
|
||||
std::vector<SourceRange> SkippedRanges;
|
||||
class CoverageSourceInfo : public PPCallbacks, public CommentHandler {
|
||||
// A vector of skipped source ranges and PrevTokLoc with NextTokLoc.
|
||||
std::vector<SkippedRange> SkippedRanges;
|
||||
Optional<unsigned> LastCommentIndex = None;
|
||||
|
||||
public:
|
||||
ArrayRef<SourceRange> getSkippedRanges() const { return SkippedRanges; }
|
||||
// Location of the token parsed before HandleComment is called. This is
|
||||
// updated every time Preprocessor::Lex lexes a new token.
|
||||
SourceLocation PrevTokLoc;
|
||||
// The location of token before comment.
|
||||
SourceLocation BeforeCommentLoc;
|
||||
|
||||
std::vector<SkippedRange> &getSkippedRanges() {
|
||||
return SkippedRanges;
|
||||
}
|
||||
|
||||
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override;
|
||||
|
||||
bool HandleComment(Preprocessor &PP, SourceRange Range) override;
|
||||
|
||||
void updateNextTokLoc(SourceLocation Loc);
|
||||
};
|
||||
|
||||
namespace CodeGen {
|
||||
|
@ -66,6 +94,8 @@ class CoverageMappingModuleGen {
|
|||
uint64_t FilenamesRef);
|
||||
|
||||
public:
|
||||
static CoverageSourceInfo *setUpCoverageCallbacks(Preprocessor &PP);
|
||||
|
||||
CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo)
|
||||
: CGM(CGM), SourceInfo(SourceInfo) {}
|
||||
|
||||
|
|
|
@ -969,7 +969,8 @@ void Preprocessor::Lex(Token &Result) {
|
|||
LastTokenWasAt = Result.is(tok::at);
|
||||
--LexLevel;
|
||||
|
||||
if (LexLevel == 0 && !Result.getFlag(Token::IsReinjected)) {
|
||||
if ((LexLevel == 0 || PreprocessToken) &&
|
||||
!Result.getFlag(Token::IsReinjected)) {
|
||||
++TokenCount;
|
||||
if (OnToken)
|
||||
OnToken(Result);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name break.c %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name break.c %t.stripped.c | FileCheck %s
|
||||
|
||||
int main() { // CHECK: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 = #0
|
||||
int cnt = 0; // CHECK-NEXT: File 0, [[@LINE+1]]:9 -> [[@LINE+1]]:18 = #0
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name builtinmacro.c %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name builtinmacro.c %t.stripped.c | FileCheck %s
|
||||
|
||||
// Test the coverage mapping generation for built-in macroes.
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -triple %itanium_abi_triple -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name classtemplate.cpp %s > %tmapping
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -triple %itanium_abi_triple -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name classtemplate.cpp %t.stripped.cpp > %tmapping
|
||||
// RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-CONSTRUCTOR
|
||||
// RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-GETTER
|
||||
// RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-SETTER
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %t.stripped.c | FileCheck %s
|
||||
|
||||
#define x1 "" // ...
|
||||
#define x2 return 0
|
||||
|
@ -7,5 +8,5 @@ int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+3]]:2 = #0
|
|||
x1; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:5 = #0
|
||||
x2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:5 = #0
|
||||
}
|
||||
// CHECK-NEXT: File 1, 3:12 -> 3:14 = #0
|
||||
// CHECK-NEXT: File 2, 4:12 -> 4:20 = #0
|
||||
// CHECK-NEXT: File 1, 4:12 -> 4:14 = #0
|
||||
// CHECK-NEXT: File 2, 5:12 -> 5:20 = #0
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name continue.c %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name continue.c %t.stripped.c | FileCheck %s
|
||||
|
||||
int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+21]]:2 = #0
|
||||
int j = 0; // CHECK-NEXT: File 0, [[@LINE+2]]:18 -> [[@LINE+2]]:24 = (#0 + #1)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// fixme: the following line is added to cleanup bots, will be removed in weeks.
|
||||
// RUN: rm -f %S/coroutine.ll
|
||||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping %s -o - | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping %t.stripped.cpp -o - | FileCheck %s
|
||||
|
||||
namespace std::experimental {
|
||||
template <typename... T>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fexceptions -fcxx-exceptions -emit-llvm-only -triple %itanium_abi_triple -main-file-name deferred-region.cpp -I %S/Inputs %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fexceptions -fcxx-exceptions -emit-llvm-only -triple %itanium_abi_triple -main-file-name deferred-region.cpp -I %S/Inputs %t.stripped.cpp | FileCheck %s
|
||||
|
||||
#define IF if
|
||||
#define STMT(S) S
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name if.cpp %t.stripped.cpp | FileCheck %s
|
||||
|
||||
int nop() { return 0; }
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name includehell.cpp %s > %tmapping
|
||||
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -I/%S -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name includehell.cpp %t.stripped.cpp > %tmapping
|
||||
int main() {
|
||||
int x = 0;
|
||||
|
||||
|
@ -51,6 +51,7 @@ int main() {
|
|||
// CHECK-START: File [[START3]], 4:29 -> 5:1 = #9
|
||||
|
||||
// CHECK-CODE: File [[CODE1:[0-9]]], 1:1 -> 14:1 = #1
|
||||
// CHECK-CODE: Skipped,File [[CODE1]], 1:1 -> 1:41 = 0
|
||||
// CHECK-CODE-NEXT: File [[CODE1]], 4:5 -> 4:11 = #1
|
||||
// CHECK-CODE: File [[CODE1]], 4:13 -> 6:2 = #2
|
||||
// CHECK-CODE: File [[CODE1]], 6:8 -> 8:2 = (#1 - #2)
|
||||
|
@ -58,6 +59,7 @@ int main() {
|
|||
// CHECK-CODE: File [[CODE1]], 9:11 -> 11:2 = #3
|
||||
// CHECK-CODE: File [[CODE1]], 11:8 -> 13:2 = (#1 - #3)
|
||||
// CHECK-CODE: File [[CODE2:[0-9]]], 1:1 -> 14:1 = #5
|
||||
// CHECK-CODE: Skipped,File [[CODE2]], 1:1 -> 1:41 = 0
|
||||
// CHECK-CODE-NEXT: File [[CODE2]], 4:5 -> 4:11 = #5
|
||||
// CHECK-CODE: File [[CODE2]], 4:13 -> 6:2 = #6
|
||||
// CHECK-CODE: File [[CODE2]], 6:8 -> 8:2 = (#5 - #6)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name label.cpp %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name label.cpp %t.stripped.cpp | FileCheck %s
|
||||
|
||||
// CHECK: func
|
||||
// CHECK: func
|
||||
void func() { // CHECK-NEXT: File 0, [[@LINE]]:13 -> {{[0-9]+}}:2 = #0
|
||||
int i = 0; // CHECK-NEXT: File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = (#0 + #3)
|
||||
// CHECK-NEXT: File 0, [[@LINE+1]]:22 -> [[@LINE+1]]:25 = #3
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name logical.cpp %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name logical.cpp %t.stripped.cpp | FileCheck %s
|
||||
|
||||
int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+15]]:2 = #0
|
||||
bool bt = true;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name loops.cpp %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name loops.cpp %t.stripped.cpp | FileCheck %s
|
||||
|
||||
// CHECK: rangedFor
|
||||
// CHECK: rangedFor
|
||||
void rangedFor() { // CHECK-NEXT: File 0, [[@LINE]]:18 -> {{[0-9]+}}:2 = #0
|
||||
int arr[] = { 1, 2, 3, 4, 5 };
|
||||
int sum = 0; // CHECK: Gap,File 0, [[@LINE+1]]:20 -> [[@LINE+1]]:21 = #1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macro-expressions.cpp -w %s | FileCheck %s
|
||||
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macro-expressions.cpp -w %t.stripped.cpp | FileCheck %s
|
||||
#define EXPR(x) (x)
|
||||
#define NEXPR(x) (!x)
|
||||
#define DECL(T, x) T x
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroparams2.c %s | FileCheck %s
|
||||
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroparams2.c %t.stripped.c | FileCheck %s
|
||||
#define MACRO(REFS, CALLS) (4 * (CALLS) < (REFS))
|
||||
|
||||
struct S {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macros.c %s | FileCheck %s
|
||||
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macros.c %t.stripped.c | FileCheck %s
|
||||
#define MACRO return; bar()
|
||||
#define MACRO_2 bar()
|
||||
#define MACRO_1 return; MACRO_2
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroscopes.cpp %s | FileCheck %s
|
||||
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroscopes.cpp %t.stripped.cpp | FileCheck %s
|
||||
#define starts_a_scope for (int i = 0; i < 2; ++i) {
|
||||
|
||||
#define ends_a_scope \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macro-expansion.c %s | FileCheck %s
|
||||
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macro-expansion.c %t.stripped.c | FileCheck %s
|
||||
#define LBRAC {
|
||||
#define RBRAC }
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name objc.m -triple x86_64-apple-darwin -fobjc-runtime=macosx-fragile-10.5 -w %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.m
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name objc.m -triple x86_64-apple-darwin -fobjc-runtime=macosx-fragile-10.5 -w %t.stripped.m | FileCheck %s
|
||||
|
||||
@interface A
|
||||
- (void)bork:(int)msg;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// RUN: %clang_cc1 -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj -fprofile-instrument=clang -std=c++14 -fdelayed-template-parsing -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name pr32679.cpp -o - %s | FileCheck %s -check-prefix=MSABI -implicit-check-not=f2
|
||||
// RUN: %clang_cc1 -cc1 -triple %itanium_abi_triple -emit-obj -fprofile-instrument=clang -std=c++14 -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name pr32679.cpp -o - %s | FileCheck %s -check-prefix=ITANIUM -implicit-check-not=f2
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj -fprofile-instrument=clang -std=c++14 -fdelayed-template-parsing -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name pr32679.cpp -o - %t.stripped.cpp | FileCheck %s -check-prefix=MSABI -implicit-check-not=f2
|
||||
// RUN: %clang_cc1 -cc1 -triple %itanium_abi_triple -emit-obj -fprofile-instrument=clang -std=c++14 -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name pr32679.cpp -o - %t.stripped.cpp | FileCheck %s -check-prefix=ITANIUM -implicit-check-not=f2
|
||||
|
||||
template <typename T, int S1>
|
||||
struct CreateSpecialization;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name preprocessor.c %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name preprocessor.c %t.stripped.c | FileCheck %s
|
||||
|
||||
// CHECK: func
|
||||
// CHECK: func
|
||||
void func() { // CHECK: File 0, [[@LINE]]:13 -> [[@LINE+5]]:2 = #0
|
||||
int i = 0;
|
||||
#ifdef MACRO // CHECK-NEXT: Skipped,File 0, [[@LINE]]:1 -> [[@LINE+2]]:7 = 0
|
||||
|
@ -11,7 +12,7 @@ void func() { // CHECK: File 0, [[@LINE]]:13 -> [[@LINE+5]]:2 = #0
|
|||
// CHECK: main
|
||||
int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 = #0
|
||||
int i = 0;
|
||||
# if 0 // CHECK-NEXT: Skipped,File 0, [[@LINE]]:1 -> [[@LINE+4]]:29 = 0
|
||||
#if 0 // CHECK-NEXT: Skipped,File 0, [[@LINE]]:1 -> [[@LINE+4]]:9 = 0
|
||||
if(i == 0) {
|
||||
i = 1;
|
||||
}
|
||||
|
@ -29,7 +30,7 @@ int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 = #0
|
|||
}
|
||||
#endif
|
||||
|
||||
// CHECK-NEXT: Skipped,File 0, [[@LINE+1]]:1 -> [[@LINE+4]]:24
|
||||
// CHECK-NEXT: Skipped,File 0, [[@LINE+1]]:1 -> [[@LINE+4]]:8
|
||||
#\
|
||||
if 0
|
||||
#\
|
||||
|
@ -59,7 +60,7 @@ int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 = #0
|
|||
#\
|
||||
endif
|
||||
|
||||
// CHECK-NEXT: Skipped,File 0, [[@LINE+1]]:1 -> [[@LINE+6]]:26
|
||||
// CHECK-NEXT: Skipped,File 0, [[@LINE+1]]:1 -> [[@LINE+6]]:10
|
||||
#\
|
||||
ifdef NOT_DEFINED
|
||||
#\
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name return.c %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name return.c %t.stripped.c | FileCheck %s
|
||||
|
||||
// CHECK: func
|
||||
// CHECK: func
|
||||
void func() { // CHECK: File 0, [[@LINE]]:13 -> [[@LINE+3]]:2 = #0
|
||||
return;
|
||||
int i = 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = 0
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name switch.cpp %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name switch.cpp %t.stripped.cpp | FileCheck %s
|
||||
|
||||
// CHECK: foo
|
||||
// CHECK: foo
|
||||
void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0
|
||||
switch(i) { // CHECK-NEXT: Gap,File 0, [[@LINE]]:13 -> [[@LINE+4]]:10 = 0
|
||||
case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = #2
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switchmacro.c %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switchmacro.c %t.stripped.c | FileCheck %s
|
||||
|
||||
#define FOO(x) (void)x
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name test.c %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name test.c %t.stripped.c | FileCheck %s
|
||||
|
||||
void bar();
|
||||
static void static_func();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 -fexceptions -fcxx-exceptions -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name trycatch.cpp %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.cpp
|
||||
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 -fexceptions -fcxx-exceptions -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name trycatch.cpp %t.stripped.cpp | FileCheck %s
|
||||
|
||||
class Error {
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
|
||||
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %t.stripped.c | FileCheck %s
|
||||
#define WHILE while (0) {}
|
||||
|
||||
// CHECK: counters_in_macro_following_unreachable
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name loops.cpp %s | FileCheck %s
|
||||
// RUN: %strip_comments > %t.stripped.c
|
||||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name loops.cpp %t.stripped.c | FileCheck %s
|
||||
|
||||
// CHECK: main
|
||||
// CHECK: main
|
||||
int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+8]]:2 = #0
|
||||
int j = 0; // CHECK-NEXT: File 0, [[@LINE+1]]:9 -> [[@LINE+1]]:14 = (#0 + #1)
|
||||
while(j < 5) ++j; // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE]]:16 = #1
|
||||
|
|
|
@ -91,6 +91,11 @@ config.substitutions.append(
|
|||
('%hmaptool', "'%s' %s" % (config.python_executable,
|
||||
os.path.join(config.clang_tools_dir, 'hmaptool'))))
|
||||
|
||||
# Strip C++ comments "//"" from tests
|
||||
config.substitutions.append(
|
||||
('%strip_comments', "sed 's/[ \t]*\/\/.*//' %s")
|
||||
)
|
||||
|
||||
# Plugins (loadable modules)
|
||||
if config.has_plugins and config.llvm_plugin_ext:
|
||||
config.available_features.add('plugins')
|
||||
|
|
|
@ -18,6 +18,6 @@ template <class T> T FOO<T>::DoIt(T ti) { // HEADER: [[@LINE]]| 2|template
|
|||
if (I > ti / 2) // HEADER: [[@LINE]]| 20| if (I > ti
|
||||
t -= 1; // HEADER: [[@LINE]]| 8| t -= 1;
|
||||
} // HEADER: [[@LINE]]| 10| }
|
||||
// HEADER: [[@LINE]]| 1|
|
||||
// HEADER: [[@LINE]]| |
|
||||
return t; // HEADER: [[@LINE]]| 1| return t;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
// RUN: %clangxx_profgen -fcoverage-mapping -Wno-comment -o %t %s
|
||||
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
|
||||
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
|
||||
// RUN: llvm-cov show %t -instr-profile %t.profdata -path-equivalence=/tmp,%S 2>&1 | FileCheck %s
|
||||
|
||||
int main() { // CHECK: [[# @LINE]]| 1|int main() {
|
||||
/* comment */ int x = 0; // CHECK: [[# @LINE]]| 1| /* comment */ int x = 0;
|
||||
int y = 0; /* comment */ // CHECK: [[# @LINE]]| 1| int y = 0; /* comment */
|
||||
int z = 0; // comment // CHECK: [[# @LINE]]| 1| int z = 0; // comment
|
||||
// comment // CHECK: [[# @LINE]]| | // comment
|
||||
// CHECK: [[# @LINE]]| |
|
||||
x = 0; /* // CHECK: [[# @LINE]]| 1| x = 0; /*
|
||||
comment // CHECK: [[# @LINE]]| | comment
|
||||
*/ // CHECK: [[# @LINE]]| | */
|
||||
// CHECK: [[# @LINE]]| |
|
||||
/* // CHECK: [[# @LINE]]| | /*
|
||||
comment // CHECK: [[# @LINE]]| | comment
|
||||
*/ x = 0; // CHECK: [[# @LINE]]| 1| */ x = 0;
|
||||
// CHECK: [[# @LINE]]| |
|
||||
/* comment */ // CHECK: [[# @LINE]]| | /* comment */
|
||||
// comment // CHECK: [[# @LINE]]| | // comment
|
||||
/* comment */ // CHECK: [[# @LINE]]| | /* comment */
|
||||
z = // CHECK: [[# @LINE]]| 1| z =
|
||||
x // comment // CHECK: [[# @LINE]]| 1| x // comment
|
||||
// comment // CHECK: [[# @LINE]]| | // comment
|
||||
+ /* // CHECK: [[# @LINE]]| 1| + /*
|
||||
comment // CHECK: [[# @LINE]]| | comment
|
||||
*/ // CHECK: [[# @LINE]]| | */
|
||||
/* // CHECK: [[# @LINE]]| | /*
|
||||
comment // CHECK: [[# @LINE]]| | comment
|
||||
*/y; // CHECK: [[# @LINE]]| 1| */y;
|
||||
// CHECK: [[# @LINE]]| |
|
||||
// Comments inside directives. // CHECK: [[# @LINE]]| | // Comments inside directives.
|
||||
#if 0 //comment // CHECK: [[# @LINE]]| | #if 0 //comment
|
||||
/* comment */ x = 0; // CHECK: [[# @LINE]]| | /* comment */ x = 0;
|
||||
y = 0; /* comment */ // CHECK: [[# @LINE]]| | y = 0; /* comment */
|
||||
z = 0; // comment // CHECK: [[# @LINE]]| | z = 0; // comment
|
||||
// comment // CHECK: [[# @LINE]]| | // comment
|
||||
// CHECK: [[# @LINE]]| |
|
||||
x = 0; /* // CHECK: [[# @LINE]]| | x = 0; /*
|
||||
comment // CHECK: [[# @LINE]]| | comment
|
||||
*/ // CHECK: [[# @LINE]]| | */
|
||||
// CHECK: [[# @LINE]]| |
|
||||
/* // CHECK: [[# @LINE]]| | /*
|
||||
comment // CHECK: [[# @LINE]]| | comment
|
||||
*/ x = 0; // CHECK: [[# @LINE]]| | */ x = 0;
|
||||
// CHECK: [[# @LINE]]| |
|
||||
/* comment */ // CHECK: [[# @LINE]]| | /* comment */
|
||||
// comment // CHECK: [[# @LINE]]| | // comment
|
||||
/* comment */ // CHECK: [[# @LINE]]| | /* comment */
|
||||
#endif // comment // CHECK: [[# @LINE]]| | #endif // comment
|
||||
#if 1 // comment // CHECK: [[# @LINE]]| 1| #if 1 // comment
|
||||
/* comment */ x = 0; // CHECK: [[# @LINE]]| 1| /* comment */ x = 0;
|
||||
y = 0; /* comment */ // CHECK: [[# @LINE]]| 1| y = 0; /* comment */
|
||||
z = 0; // comment // CHECK: [[# @LINE]]| 1| z = 0; // comment
|
||||
// comment // CHECK: [[# @LINE]]| | // comment
|
||||
// CHECK: [[# @LINE]]| |
|
||||
x = 0; /* // CHECK: [[# @LINE]]| 1| x = 0; /*
|
||||
comment // CHECK: [[# @LINE]]| | comment
|
||||
*/ // CHECK: [[# @LINE]]| | */
|
||||
// CHECK: [[# @LINE]]| |
|
||||
/* // CHECK: [[# @LINE]]| | /*
|
||||
comment // CHECK: [[# @LINE]]| | comment
|
||||
*/ x = 0; // CHECK: [[# @LINE]]| 1| */ x = 0;
|
||||
// CHECK: [[# @LINE]]| |
|
||||
/* comment */ // CHECK: [[# @LINE]]| | /* comment */
|
||||
// comment // CHECK: [[# @LINE]]| | // comment
|
||||
/* comment */ // CHECK: [[# @LINE]]| | /* comment */
|
||||
#endif //comment // CHECK: [[# @LINE]]| 1| #endif //comment
|
||||
return 0; // CHECK: [[# @LINE]]| 1| return 0;
|
||||
} // CHECK: [[# @LINE]]| 1|}
|
Loading…
Reference in New Issue