forked from OSchip/llvm-project
[Coverage] Enable emitting gap area between macros
Differential Revision: https://reviews.llvm.org/D85176
This commit is contained in:
parent
fc544dcf2d
commit
a31c89c1b7
|
@ -864,22 +864,13 @@ struct CounterCoverageMappingBuilder
|
|||
/// Find a valid gap range between \p AfterLoc and \p BeforeLoc.
|
||||
Optional<SourceRange> findGapAreaBetween(SourceLocation AfterLoc,
|
||||
SourceLocation BeforeLoc) {
|
||||
// If the start and end locations of the gap are both within the same macro
|
||||
// file, the range may not be in source order.
|
||||
if (AfterLoc.isMacroID() || BeforeLoc.isMacroID())
|
||||
return None;
|
||||
AfterLoc = SM.getExpansionLoc(AfterLoc);
|
||||
BeforeLoc = SM.getExpansionLoc(BeforeLoc);
|
||||
if (!SM.isWrittenInSameFile(AfterLoc, BeforeLoc))
|
||||
return None;
|
||||
return {{AfterLoc, BeforeLoc}};
|
||||
}
|
||||
|
||||
/// Find the source range after \p AfterStmt and before \p BeforeStmt.
|
||||
Optional<SourceRange> findGapAreaBetween(const Stmt *AfterStmt,
|
||||
const Stmt *BeforeStmt) {
|
||||
return findGapAreaBetween(getPreciseTokenLocEnd(getEnd(AfterStmt)),
|
||||
getStart(BeforeStmt));
|
||||
}
|
||||
|
||||
/// Emit a gap region between \p StartLoc and \p EndLoc with the given count.
|
||||
void fillGapAreaWithCount(SourceLocation StartLoc, SourceLocation EndLoc,
|
||||
Counter Count) {
|
||||
|
@ -1044,7 +1035,8 @@ struct CounterCoverageMappingBuilder
|
|||
adjustForOutOfOrderTraversal(getEnd(S));
|
||||
|
||||
// The body count applies to the area immediately after the increment.
|
||||
auto Gap = findGapAreaBetween(S->getCond(), S->getBody());
|
||||
auto Gap = findGapAreaBetween(getPreciseTokenLocEnd(S->getRParenLoc()),
|
||||
getStart(S->getBody()));
|
||||
if (Gap)
|
||||
fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), BodyCount);
|
||||
|
||||
|
@ -1261,7 +1253,8 @@ struct CounterCoverageMappingBuilder
|
|||
propagateCounts(ParentCount, S->getCond());
|
||||
|
||||
// The 'then' count applies to the area immediately after the condition.
|
||||
auto Gap = findGapAreaBetween(S->getCond(), S->getThen());
|
||||
auto Gap = findGapAreaBetween(getPreciseTokenLocEnd(S->getRParenLoc()),
|
||||
getStart(S->getThen()));
|
||||
if (Gap)
|
||||
fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), ThenCount);
|
||||
|
||||
|
@ -1271,7 +1264,8 @@ struct CounterCoverageMappingBuilder
|
|||
Counter ElseCount = subtractCounters(ParentCount, ThenCount);
|
||||
if (const Stmt *Else = S->getElse()) {
|
||||
// The 'else' count applies to the area immediately after the 'then'.
|
||||
Gap = findGapAreaBetween(S->getThen(), Else);
|
||||
Gap = findGapAreaBetween(getPreciseTokenLocEnd(getEnd(S->getThen())),
|
||||
getStart(Else));
|
||||
if (Gap)
|
||||
fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), ElseCount);
|
||||
extendRegion(Else);
|
||||
|
|
|
@ -44,10 +44,3 @@ int main() { // CHECK: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 =
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FOO true
|
||||
|
||||
// CHECK-LABEL: _Z7ternaryv:
|
||||
void ternary() {
|
||||
true ? FOO : FOO; // CHECK-NOT: Gap,{{.*}}, [[@LINE]]:8 ->
|
||||
}
|
||||
|
|
|
@ -57,7 +57,8 @@ void foo(int i) {
|
|||
// CHECK: File 0, [[@LINE+1]]:10 -> [[@LINE+1]]:12 = #1
|
||||
if (0) {}
|
||||
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:7 -> [[@LINE+2]]:11 = #0
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:11 = #0
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = #2
|
||||
// CHECK-NEXT: File 0, [[@LINE+1]]:16 -> [[@LINE+1]]:18 = #2
|
||||
if (EXPR(i)) {}
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:9 -> [[@LINE+2]]:14 = (#0 + #3)
|
||||
|
@ -70,7 +71,8 @@ void foo(int i) {
|
|||
for (ASSIGN(DECL(int, j), 0); LT(j, i); INC(j)) {}
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:9 = #0
|
||||
ASSIGN(DECL(int, k), 0);
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:10 -> [[@LINE+3]]:12 = (#0 + #5)
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:12 = (#0 + #5)
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:19 -> [[@LINE+3]]:20 = #5
|
||||
// CHECK-NEXT: File 0, [[@LINE+2]]:20 -> [[@LINE+2]]:31 = #5
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:22 -> [[@LINE+1]]:25 = #5
|
||||
while (LT(k, i)) { INC(k); }
|
||||
|
@ -82,6 +84,7 @@ void foo(int i) {
|
|||
// CHECK: File 0, [[@LINE+1]]:42 -> [[@LINE+1]]:44 = #7
|
||||
for (DECL(int, j) : ARR(int, 1, 2, 3)) {}
|
||||
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:12 -> [[@LINE+3]]:14 = #8
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = #0
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:23 -> [[@LINE+1]]:29 = #0
|
||||
(void)(i ? PRIo64 : PRIu64);
|
||||
|
|
|
@ -6,11 +6,12 @@ struct S {
|
|||
int i, j;
|
||||
};
|
||||
|
||||
// CHECK: File 0, [[@LINE+1]]:12 -> [[@LINE+10]]:2 = #0
|
||||
// CHECK: File 0, [[@LINE+1]]:12 -> [[@LINE+11]]:2 = #0
|
||||
int main() {
|
||||
struct S arr[32] = { 0 };
|
||||
int n = 0;
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:7 -> [[@LINE+2]]:12 = #0
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:12 = #0
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE+2]]:33 -> [[@LINE+2]]:34 = #1
|
||||
// CHECK-NEXT: File 0, [[@LINE+1]]:34 -> [[@LINE+3]]:4 = #1
|
||||
if (MACRO(arr[n].j, arr[n].i)) {
|
||||
n = 1;
|
||||
|
|
|
@ -38,29 +38,32 @@ void func3() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+3]]:2 = #0
|
|||
// CHECK-NEXT: File 2, 4:17 -> 4:22 = #0
|
||||
|
||||
// CHECK-NEXT: func4
|
||||
void func4() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+6]]:2 = #0
|
||||
void func4() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+7]]:2 = #0
|
||||
int i = 0;
|
||||
while (i++ < 10) // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:18 = (#0 + #1)
|
||||
if (i < 5) // CHECK: File 0, [[@LINE]]:5 -> [[@LINE+2]]:14 = #1
|
||||
if (i < 5) // CHECK: File 0, [[@LINE]]:5 -> [[@LINE+3]]:14 = #1
|
||||
// CHECK-NEXT: File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:14 = #1
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:15 -> [[@LINE+1]]:7 = #2
|
||||
MACRO_2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:7 -> [[@LINE]]:14 = #2
|
||||
}
|
||||
// CHECK-NEXT: File 1, 4:17 -> 4:22 = #2
|
||||
// CHECK-NOT: File 1
|
||||
|
||||
// CHECK-NEXT: func5
|
||||
void func5() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+4]]:2 = #0
|
||||
void func5() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+5]]:2 = #0
|
||||
int i = 0;
|
||||
if (i > 5) // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = #0
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE-1]]:13 -> [[@LINE+1]]:5 = #1
|
||||
MACRO_3; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:5 -> [[@LINE]]:12 = #1
|
||||
}
|
||||
// CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
|
||||
// CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
|
||||
|
||||
// CHECK-NEXT: func6
|
||||
void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+4]]:2 = #0
|
||||
begin: // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+3]]:2 = #1
|
||||
void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+5]]:2 = #0
|
||||
begin: // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+4]]:2 = #1
|
||||
if (count--) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:16 = #1
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE-1]]:17 -> [[@LINE+1]]:9 = #2
|
||||
GOTO begin; // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:19 = #2
|
||||
}
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE-2]]:9 -> [[@LINE-2]]:13 = #2
|
||||
|
|
|
@ -61,13 +61,15 @@ int main() {
|
|||
starts_a_scope
|
||||
ends_a_scope
|
||||
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:3 -> [[@LINE+2]]:17 = #0
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:3 -> [[@LINE+3]]:17 = #0
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE+2]]:3 -> [[@LINE+3]]:5 = #8
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:5 -> [[@LINE+2]]:16 = #8
|
||||
starts_a_while
|
||||
simple_stmt;
|
||||
|
||||
x = 0;
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:3 -> [[@LINE+4]]:17 = #0
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+5]]:3 -> [[@LINE+5]]:17 = #0
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE+4]]:3 -> [[@LINE+4]]:18 = #9
|
||||
// CHECK-NEXT: File 0, [[@LINE+3]]:18 -> [[@LINE+5]]:15 = #9
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:5 -> [[@LINE+3]]:16 = #9
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:3 -> [[@LINE+3]]:15 = #9
|
||||
|
|
|
@ -9,16 +9,18 @@ int main(int argc, const char *argv[]) {
|
|||
// CHECK-NEXT: File 0, [[@LINE+1]]:7 -> [[@LINE+1]]:12 = #0
|
||||
if (!argc) {} // CHECK: File 0, [[@LINE]]:14 -> [[@LINE]]:16 = #1
|
||||
|
||||
// CHECK-NEXT: File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:12 = #0
|
||||
// CHECK-NEXT: File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:12 = #0
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:13 -> [[@LINE+3]]:14 = #2
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:19 = #2
|
||||
// CHECK-NEXT: File 0, [[@LINE+1]]:19 -> [[@LINE+4]]:8 = #2
|
||||
if (!argc) LBRAC
|
||||
return 0;
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:8 = #2
|
||||
RBRAC // CHECK-NEXT: [[@LINE]]:8 -> [[@LINE+6]]:3 = (#0 - #2)
|
||||
RBRAC // CHECK-NEXT: [[@LINE]]:8 -> [[@LINE+7]]:3 = (#0 - #2)
|
||||
|
||||
// CHECK-NEXT: File 0, [[@LINE+4]]:3 -> [[@LINE+15]]:2 = (#0 - #2)
|
||||
// CHECK-NEXT: File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:12 = (#0 - #2)
|
||||
// CHECK-NEXT: File 0, [[@LINE+5]]:3 -> [[@LINE+16]]:2 = (#0 - #2)
|
||||
// CHECK-NEXT: File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:12 = (#0 - #2)
|
||||
// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:13 -> [[@LINE+3]]:14 = #3
|
||||
// CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:19 = #3
|
||||
// CHECK-NEXT: File 0, [[@LINE+1]]:19 -> [[@LINE+3]]:4 = #3
|
||||
if (!argc) LBRAC
|
||||
|
|
Loading…
Reference in New Issue