Skip to content

llvm-cov: Calculate RegionCoverage based on CoverageData::Segments #121191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
51 changes: 51 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <cstdio>

template <typename Ty>
bool ab(Ty a, Ty b) {
return (a && b);
}
// CHECK: [[@LINE-2]]| 4| return

// CHECK: MC/DC Coverage for Decision{{[:]}} 50.00%
// CHECK: MC/DC Coverage for Decision{{[:]}} 50.00%
// CHECK: MC/DC Coverage for Decision{{[:]}} 0.00%
// CHECK-NOT: MC/DC Coverage for Decision{{[:]}}

// CHECK: _Z2abIbEbT_S0_{{[:]}}
// CHECK: | | MC/DC Coverage for Decision{{[:]}} 50.00%

// CHECK: _Z2abIxEbT_S0_{{[:]}}
// CHECK: | | MC/DC Coverage for Decision{{[:]}} 50.00%

// CHECK: Unexecuted instantiation{{[:]}} _Z2abIdEbT_S0_

template <bool C>
bool Cab(bool a, bool b) {
return (a && b && C);
}
// CHECK: [[@LINE-2]]| 4| return

// CHECK: MC/DC Coverage for Decision{{[:]}} 0.00%
// CHECK: MC/DC Coverage for Decision{{[:]}} 50.00%
// CHECK-NOT: MC/DC Coverage for Decision{{[:]}}

// CHECK: _Z3CabILb0EEbbb{{[:]}}
// CHECK: | | MC/DC Coverage for Decision{{[:]}} 0.00%

// CHECK: _Z3CabILb1EEbbb{{[:]}}
// CHECK: | | MC/DC Coverage for Decision{{[:]}} 50.00%

// CHECK: [[@LINE+1]]| 1|int main
int main(int argc, char **argv) {
printf("%d\n", Cab<false>(false, false));
printf("%d\n", Cab<false>(true, true));
printf("%d\n", Cab<true>(true, false));
printf("%d\n", Cab<true>(true, true));
printf("%d\n", ab(false, false));
printf("%d\n", ab(true, true));
printf("%d\n", ab(1LL, 0LL));
printf("%d\n", ab(1LL, 1LL));
if (argc == 2)
printf("%d\n", ab(0.0, 0.0));
return 0;
}
73 changes: 73 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.proftext
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
_Z2abIbEbT_S0_
# Func Hash:
1550
# Num Counters:
3
# Counter Values:
2
1
1
# Num Bitmap Bytes:
$1
# Bitmap Byte Values:
0x5


_Z2abIxEbT_S0_
# Func Hash:
1550
# Num Counters:
3
# Counter Values:
2
2
1
# Num Bitmap Bytes:
$1
# Bitmap Byte Values:
0x6


_Z3CabILb0EEbbb
# Func Hash:
99214
# Num Counters:
5
# Counter Values:
2
1
0
1
1
# Num Bitmap Bytes:
$1
# Bitmap Byte Values:
0x5


_Z3CabILb1EEbbb
# Func Hash:
99214
# Num Counters:
5
# Counter Values:
2
1
1
2
1
# Num Bitmap Bytes:
$1
# Bitmap Byte Values:
0xa


main
# Func Hash:
175973464
# Num Counters:
2
# Counter Values:
1
0

105 changes: 105 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/mcdc-templates-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
OSABI: ELFOSABI_GNU
Type: ET_REL
Machine: EM_X86_64
SectionHeaderStringTable: .strtab
Sections:
- Name: __llvm_covfun
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: FAD58DE7366495DB2500000058247D0A00000000249EC986A505B62F0101010105050127210C020109070010200502000700100500110185808080080501050021
- Name: '__llvm_covfun (1)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 9CC3B348501DBFE8480000008E83010000000000249EC986A505B62F010103010D0D1105090901171A020201010B000C01000B0011280403000B0016300D02010300000B000C0D0010001130110603020000100011050015001630000A02000000150016
- Name: '__llvm_covfun (2)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 9873627177A03F8E460000008E83010000000000249EC986A505B62F010102010D0D110901171A020201010B000C01000B0011280403000B0016300D02010300000B000C0D0010001130110603020000100011050015001630090002000000150016
- Name: '__llvm_covfun (3)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: BF407A207503B266320000000E06000000000000249EC986A505B62F0101020105050906010415020201010B000C280302000B0011300502010200000B000C050010001130090602000000100011
- Name: '__llvm_covfun (4)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 8A05A22CB467C37D320000000E06000000000000249EC986A505B62F0101020105050906010415020201010B000C280302000B0011300502010200000B000C050010001130090602000000100011
- Name: '__llvm_covfun (5)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 1700192CAC8F3F26320000000E06000000000000249EC986A505B62F0101020105050906010415020201010B000C280302000B0011300502010200000B000C050010001130090602000000100011
- Name: __llvm_covmap
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 000000001D0000000000000006000000021A0000186D6364632D74656D706C617465732D6D657267652E637070000000
- Name: __llvm_prf_names
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_GNU_RETAIN ]
AddressAlign: 0x1
Content: 51006D61696E015F5A33436162494C62304545626262015F5A33436162494C62314545626262015F5A32616249624562545F53305F015F5A32616249784562545F53305F015F5A32616249644562545F53305F
- Type: SectionHeaderTable
Sections:
- Name: .strtab
- Name: __llvm_covfun
- Name: '__llvm_covfun (1)'
- Name: '__llvm_covfun (2)'
- Name: '__llvm_covfun (3)'
- Name: '__llvm_covfun (4)'
- Name: '__llvm_covfun (5)'
- Name: __llvm_covmap
- Name: __llvm_prf_names
- Name: .symtab
Symbols:
- Name: __llvm_covmap
Type: STT_SECTION
Section: __llvm_covmap
- Name: __llvm_prf_names
Type: STT_SECTION
Section: __llvm_prf_names
- Name: __covrec_DB956436E78DD5FAu
Type: STT_OBJECT
Section: __llvm_covfun
Binding: STB_WEAK
Size: 0x41
Other: [ STV_HIDDEN ]
- Name: __covrec_E8BF1D5048B3C39Cu
Type: STT_OBJECT
Section: '__llvm_covfun (1)'
Binding: STB_WEAK
Size: 0x64
Other: [ STV_HIDDEN ]
- Name: __covrec_8E3FA07771627398u
Type: STT_OBJECT
Section: '__llvm_covfun (2)'
Binding: STB_WEAK
Size: 0x62
Other: [ STV_HIDDEN ]
- Name: __covrec_66B20375207A40BFu
Type: STT_OBJECT
Section: '__llvm_covfun (3)'
Binding: STB_WEAK
Size: 0x4E
Other: [ STV_HIDDEN ]
- Name: __covrec_7DC367B42CA2058Au
Type: STT_OBJECT
Section: '__llvm_covfun (4)'
Binding: STB_WEAK
Size: 0x4E
Other: [ STV_HIDDEN ]
- Name: __covrec_263F8FAC2C190017u
Type: STT_OBJECT
Section: '__llvm_covfun (5)'
Binding: STB_WEAK
Size: 0x4E
Other: [ STV_HIDDEN ]
...
12 changes: 6 additions & 6 deletions llvm/test/tools/llvm-cov/branch-c-general.test
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@
// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// REPORT-NEXT: ---
// REPORT-NEXT: simple_loops 8 0 100.00% 9 0 100.00% 6 0 100.00%
// REPORT-NEXT: conditionals 24 0 100.00% 15 0 100.00% 16 2 87.50%
// REPORT-NEXT: conditionals 22 0 100.00% 15 0 100.00% 16 2 87.50%
// REPORT-NEXT: early_exits 20 4 80.00% 25 2 92.00% 16 6 62.50%
// REPORT-NEXT: jumps 39 12 69.23% 48 2 95.83% 26 9 65.38%
// REPORT-NEXT: switches 28 5 82.14% 38 4 89.47% 28 7 75.00%
// REPORT-NEXT: switches 27 4 85.19% 38 4 89.47% 28 7 75.00%
// REPORT-NEXT: big_switch 25 1 96.00% 32 0 100.00% 30 6 80.00%
// REPORT-NEXT: boolean_operators 16 0 100.00% 13 0 100.00% 22 2 90.91%
// REPORT-NEXT: boolop_loops 19 0 100.00% 14 0 100.00% 16 2 87.50%
// REPORT-NEXT: boolean_operators 14 0 100.00% 13 0 100.00% 22 2 90.91%
// REPORT-NEXT: boolop_loops 15 0 100.00% 14 0 100.00% 16 2 87.50%
// REPORT-NEXT: conditional_operator 4 2 50.00% 8 0 100.00% 4 2 50.00%
// REPORT-NEXT: do_fallthrough 9 0 100.00% 12 0 100.00% 6 0 100.00%
// REPORT-NEXT: main 1 0 100.00% 16 0 100.00% 0 0 0.00%
// REPORT-NEXT: c-general.c:static_func 4 0 100.00% 4 0 100.00% 2 0 100.00%
// REPORT-NEXT: ---
// REPORT-NEXT: TOTAL 197 24 87.82% 234 8 96.58% 172 36 79.07%
// REPORT-NEXT: TOTAL 188 23 87.77% 234 8 96.58% 172 36 79.07%

// Test file-level report.
// RUN: llvm-profdata merge %S/Inputs/branch-c-general.proftext -o %t.profdata
Expand Down Expand Up @@ -159,7 +159,7 @@
// HTML-INDEX: <td class='column-entry-yellow'>
// HTML-INDEX: 96.58% (226/234)
// HTML-INDEX: <td class='column-entry-yellow'>
// HTML-INDEX: 87.82% (173/197)
// HTML-INDEX: 87.77% (165/188)
// HTML-INDEX: <td class='column-entry-red'>
// HTML-INDEX: 79.07% (136/172)
// HTML-INDEX: <tr class='light-row-bold'>
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-cov/branch-export-json.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// CHECK: 45,5,45,11,0,5,0,0,4
// CHECK: 47,5,47,12,3,2,0,0,4
// CHECK: 53,12,53,20,50,5,0,0,4
// CHECK: {"count":30,"covered":26,"notcovered":4,"percent":86.666666666666671}
// CHECK: {"count":30,"covered":26,"notcovered":4,"percent":86.6[[#]]}

// Check recursive macro-expansions.
// RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
Expand Down
14 changes: 11 additions & 3 deletions llvm/test/tools/llvm-cov/branch-macros.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
// RUN: llvm-cov show --show-expansions --show-branches=count %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-macros.cpp -check-prefixes=CHECK,BRCOV -D#C=999
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-macros.cpp | FileCheck %s -check-prefix=FILE

// RUN: llvm-cov show --binary-counters --show-expansions --show-branches=count %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-macros.cpp -check-prefixes=CHECK,BRCOV -D#C=1
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-macros.cpp | FileCheck %s -check-prefix=REPORT

Expand All @@ -9,8 +11,14 @@

// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// REPORT-NEXT: ---
// REPORT-NEXT: _Z4funcii 28 4 85.71% 18 0 100.00% 30 14 53.33%
// REPORT-NEXT: _Z5func2ii 13 1 92.31% 8 0 100.00% 10 2 80.00%
// REPORT-NEXT: _Z4funcii 12 4 66.67% 18 0 100.00% 30 14 53.33%
// REPORT-NEXT: _Z5func2ii 3 0 100.00% 8 0 100.00% 10 2 80.00%
// REPORT-NEXT: main 1 0 100.00% 6 0 100.00% 0 0 0.00%
// REPORT-NEXT: ---
// REPORT-NEXT: TOTAL 42 5 88.10% 32 0 100.00% 40 16 60.00%
// REPORT-NEXT: TOTAL 16 4 75.00% 32 0 100.00% 40 16 60.00%

// FILE: Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover
// FILE-NEXT: ---
// FILE-NEXT: branch-macros.cpp 16 4 75.00% 3 0 100.00% 32 0 100.00% 40 16 60.00%
// FILE-NEXT: ---
// FILE-NEXT: TOTAL 16 4 75.00% 3 0 100.00% 32 0 100.00% 40 16 60.00%
12 changes: 6 additions & 6 deletions llvm/test/tools/llvm-cov/branch-noShowBranch.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
// REPORT-NOT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// REPORT: ---
// REPORT-NOT: simple_loops 8 0 100.00% 9 0 100.00% 6 0 100.00%
// REPORT-NOT: conditionals 24 0 100.00% 15 0 100.00% 16 2 87.50%
// REPORT-NOT: conditionals 22 0 100.00% 15 0 100.00% 16 2 87.50%
// REPORT-NOT: early_exits 20 4 80.00% 25 2 92.00% 16 6 62.50%
// REPORT-NOT: jumps 39 12 69.23% 48 2 95.83% 26 9 65.38%
// REPORT-NOT: switches 28 5 82.14% 38 4 89.47% 28 7 75.00%
// REPORT-NOT: switches 27 4 85.19% 38 4 89.47% 28 7 75.00%
// REPORT-NOT: big_switch 25 1 96.00% 32 0 100.00% 30 6 80.00%
// REPORT-NOT: boolean_operators 16 0 100.00% 13 0 100.00% 22 2 90.91%
// REPORT-NOT: boolop_loops 19 0 100.00% 14 0 100.00% 16 2 87.50%
// REPORT-NOT: boolean_operators 14 0 100.00% 13 0 100.00% 22 2 90.91%
// REPORT-NOT: boolop_loops 15 0 100.00% 14 0 100.00% 16 2 87.50%
// REPORT-NOT: conditional_operator 4 2 50.00% 8 0 100.00% 4 2 50.00%
// REPORT-NOT: do_fallthrough 9 0 100.00% 12 0 100.00% 6 0 100.00%
// REPORT-NOT: main 1 0 100.00% 16 0 100.00% 0 0 0.00%
// REPORT-NOT: c-general.c:static_func 4 0 100.00% 4 0 100.00% 2 0 100.00%
// REPORT: TOTAL 197 24 87.82% 234 8 96.58%
// REPORT-NOT: TOTAL 197 24 87.82% 234 8 96.58% 172 36 79.07%
// REPORT: TOTAL 188 23 87.77% 234 8 96.58%
// REPORT-NOT: TOTAL 188 23 87.77% 234 8 96.58% 172 36 79.07%
6 changes: 3 additions & 3 deletions llvm/test/tools/llvm-cov/mcdc-general-none.test
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover MC/DC Conditions Miss Cover
// REPORT-NEXT: -------------------------------------------------------------------------------------------------------------------------------------------
// REPORT-NEXT: _Z4testbbbb 25 0 100.00% 9 0 100.00% 24 2 91.67% 12 12 0.00%
// REPORT-NEXT: _Z4testbbbb 21 0 100.00% 9 0 100.00% 24 2 91.67% 12 12 0.00%
// REPORT-NEXT: main 1 0 100.00% 11 0 100.00% 0 0 0.00% 0 0 0.00%
// REPORT-NEXT: ---
// REPORT-NEXT: TOTAL 26 0 100.00% 20 0 100.00% 24 2 91.67% 12 12 0.00%
// REPORT-NEXT: TOTAL 22 0 100.00% 20 0 100.00% 24 2 91.67% 12 12 0.00%

// Turn off MC/DC summary.
// RUN: llvm-cov report %S/Inputs/mcdc-general.o -instr-profile %t.profdata -show-functions -path-equivalence=.,%S/Inputs %S/Inputs/mcdc-general.cpp | FileCheck %s -check-prefix=REPORT_NOMCDC
Expand Down Expand Up @@ -67,7 +67,7 @@
// HTML-INDEX: <td class='column-entry-green'>
// HTML-INDEX: 100.00% (2/2)
// HTML-INDEX: 100.00% (20/20)
// HTML-INDEX: 100.00% (26/26)
// HTML-INDEX: 100.00% (22/22)
// HTML-INDEX: 91.67% (22/24)
// HTML-INDEX: 0.00% (0/12)
// HTML-INDEX: Totals
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/tools/llvm-cov/mcdc-general.test
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@

// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover MC/DC Conditions Miss Cover
// REPORT-NEXT: -------------------------------------------------------------------------------------------------------------------------------------------
// REPORT-NEXT: _Z4testbbbb 25 0 100.00% 9 0 100.00% 24 2 91.67% 12 2 83.33%
// REPORT-NEXT: _Z4testbbbb 21 0 100.00% 9 0 100.00% 24 2 91.67% 12 2 83.33%
// REPORT-NEXT: main 1 0 100.00% 11 0 100.00% 0 0 0.00% 0 0 0.00%
// REPORT-NEXT: ---
// REPORT-NEXT: TOTAL 26 0 100.00% 20 0 100.00% 24 2 91.67% 12 2 83.33%
// REPORT-NEXT: TOTAL 22 0 100.00% 20 0 100.00% 24 2 91.67% 12 2 83.33%

// Turn off MC/DC summary.
// RUN: llvm-cov report %S/Inputs/mcdc-general.o -instr-profile %t.profdata -show-functions -path-equivalence=.,%S/Inputs %S/Inputs/mcdc-general.cpp | FileCheck %s -check-prefix=REPORT_NOMCDC
Expand Down Expand Up @@ -133,7 +133,7 @@
// HTML-INDEX: <td class='column-entry-green'>
// HTML-INDEX: 100.00% (2/2)
// HTML-INDEX: 100.00% (20/20)
// HTML-INDEX: 100.00% (26/26)
// HTML-INDEX: 100.00% (22/22)
// HTML-INDEX: 91.67% (22/24)
// HTML-INDEX: 83.33% (10/12)
// HTML-INDEX: Totals
Expand Down
27 changes: 27 additions & 0 deletions llvm/test/tools/llvm-cov/mcdc-templates-merge.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Test `merge-instantiations=merge/any/all`

RUN: yaml2obj %S/Inputs/mcdc-templates-merge.yaml -o %t.o
RUN: llvm-profdata merge %S/Inputs/mcdc-templates-merge.proftext -o %t.profdata

RUN: llvm-cov show --show-mcdc -show-instantiations=true %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs | FileCheck %S/Inputs/mcdc-templates-merge.cpp

RUN: llvm-cov report --show-mcdc-summary %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs | FileCheck %s

REPORT: mcdc-templates-merge.cpp

# Regions
CHECK: 10 1 90.00%

# Functions
CHECK: 3 0 100.00%

# Lines
CHECK: 19 1 94.74%

# Branches
CHECK: 11 3 72.73%

# MC/DC Conditions
CHECK: 4 2 50.00%

REPORT: TOTAL
Loading
Loading