177 changes: 177 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
--- !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: D7878914FBE99B0760000000D136449C106D04004C551E9517F40F4F01010401050109010D010D0E010715080203020F0016200501000F0016050018001B05001C009D8080800805001D010407020A000F200901000A000F09001001858080800809010500080F010600080F00100018200D01001000181001010001
- Name: '__llvm_covfun (1)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 83AD05A5F1438E68F300000052D33558163C11444C551E9517F40F4F010101014D270111150E02030113001A2005550013001A4D001C001F05002000A1808080080500210B04050109000E09000F009080808008090010020609010B000C15000D008E8080800815000E0010250106008C8080800825000C040625001000151D00160097808080081D001702061D010B000C29000D008E8080800829000E0010210106008C8080800821000C020621010B000C31000D008E8080800831000E0010100201005B1101050204110009000A110009000F41000E000F39001000918080800839001100133D010501043D0009000A3D0009000F51000E000F49001000918080800849001100131002010001
- Name: '__llvm_covfun (2)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 0449C70428C57369140100003D5C2D0E4B13F9274C551E9517F40F4F010107071D0919114111411141252925292A012114180210020100010101070008050009008A8080800805000A000C1001010001090103130203000A0011200D41000A00110D00120093808080080D001306040D0209000F110010018780808008110107000C15000D0185808080081501050204150009000E19000F018780808008190107000F13010402838080800810010100011301030B021300070008210009008A8080800821000A000C100101000125010309021B000605041B0109000F2D00100187808080082D0107000D31000E028780808008310207000A35010C0013202945000C0013450015028380808008100101000145010302024500070008390009008A8080800839000A000C1001010001
- Name: '__llvm_covfun (3)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 55947829059F255ED40100001B9C495D3463E1D04C551E9517F40F4F010103010D3D496D794A013B0E2F02100201000103010F0014200571000F00140D0016001905001A009B8080800805001B040400011402858080800810010100230001050104000009000A09000B008C8080800809000C000E710104028180808008100101000111010126021101070008150009008A8080800815000A000C1001010001190103000D19000E0283808080081001010001000103210229000A000B201D75000A000B1D000C008D808080081D000D03042101030204210109000A25000B008C8080800825000C000E1002010001750103000D75000E0181808080082D01011B023101011A023501011902350207000C39000D018580808008390105000F3D001002838080800810010100013D0103140207000A000F204179000A000F4100100091808080084100110A0445010309040001100691808080084D0105011100011201858080800851010501120001130185808080085501050111790304028380808008100101000179010308020B000F001520597D000F00156D0017001A59001B009C8080800859001C0604000115028580808008100101003F0001050304000009000A5D000B008C808080085D000C000E6501030204650109000A69000B008C8080800869000C000E1002010001
- Name: '__llvm_covfun (4)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 7129CA3C268292BF560100003E688383C9A099004C551E9517F40F4F010101051136016C112502100201011C000217028A80808008090103010A05020402838080800810010100620501031C0203003F0046200D69003F0046110048004B0D004C00CD808080080D004D1704000119148F80808008150105130F15010B000C19000D008E8080800819000E00101001010015210105100F21010B000C25000D008E8080800825000E0010290107000C29000D0185808080082D01050D0F2D010B000C31000D008E8080800831000E0010350107000F3500100185808080083901050A0F39010B000C3D000D008E808080083D000E0010410107080F000012039180808008490107021149010D000E4D000F0090808080084D0010001251010900114501080285808080081001010001550105020F55010B0017590018018980808008590109000F69020403838080800810010101216902030202690007001161001200938080800861001300151001010001
- Name: '__llvm_covfun (5)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 3F4D1C6E6087417B3B010000D6FF56B8865A69B64C551E9517F40F4F010101010932019301131F0203011300192005610013001909001B001E05001F00A0808080080500201C04000115198C808080080D0105180C0D010B000C11000D008E8080800811000E00101001010015190105150C19010B000C1D000D008E808080081D000E0010210107000C21000D018580808008250105120C25010B000C29000D008E8080800829000E00102D0107000C2D000D03858080800810010101013102050D0C31010B000C35000D008E8080800835000E0010390107000C39000D0185808080083D01050A0C3D010B000C41000D008E8080800841000E0010450107000C45000D0385808080081001010101490205050C49010B000C4D000D008E808080084D000E0010510107000C51000D018580808008550105020C55010B000C59000D008E8080800859000E00105D0107000C1003010001
- Name: '__llvm_covfun (6)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 59A48AA8899AA3587B00000091E33C8FF36C04004C551E9517F40F4F01010101051601B4011A0C02030213001A2005010013001A05001C001F05002000A1808080080500210804050109000E0900120013100101005D050109000E1100120013100101005D050109000E0500090017210012001719001B001C1001010063050109000E0500090017310012001729001B001C1002010063
- Name: '__llvm_covfun (7)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: F5953D044B505D139D0000005FD132562FE71EAC4C551E9517F40F4F010107010501110111011D011D012901291A01C201150D02100201000103010A000B03000A001509000F0015050016018580808008050105000810010100010B010A00110B000A001C150015001C11001D018580808008110105000810010100011301110012130011001C210016001C1D001E00211D0022002310010100611B010A00111B000A001C2D0015001C29001E002129002200231001010061
- Name: '__llvm_covfun (8)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 20E5C369BDF15C7940000000D0D60000000000004C551E9517F40F4F0101000B01D1011D0702100201000101010B001109001300948080800809001400150D001800191001010001050103020205000B000C01001000111001010001
- Name: '__llvm_covfun (9)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 7DE8E7C47096EB426A00000092EAF0986287F0784C551E9517F40F4F0101050715010D0D15050905090F01DA01170B020301130019200519001300190B001B001E05001F00A08080800805002009041302080606100101024D13030B00100D00110092808080080D00120017110018018780808008110107010611010E0013200915000E0013
- Name: '__llvm_covfun (10)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: FAD58DE7366495DB0A00000018000000000000004C551E9517F40F4F0101000101F501280F02
- Name: '__llvm_covfun (11)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 4CB4F49D6737EBF92B000000D1460000000000004C551E9517F40F4F01010101050601E7011B030203011300192005010013001905001B001E05001F00A0808080080500200104
- Name: __llvm_covmap
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 0000000017000000000000000600000002140000126272616E63682D632D67656E6572616C2E6300
- Name: __llvm_prf_names
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_GNU_RETAIN ]
AddressAlign: 0x1
Content: A6010073696D706C655F6C6F6F707301636F6E646974696F6E616C73016561726C795F6578697473016A756D7073017377697463686573016269675F73776974636801626F6F6C65616E5F6F70657261746F727301626F6F6C6F705F6C6F6F707301636F6E646974696F6E616C5F6F70657261746F7201646F5F66616C6C7468726F756768016D61696E016272616E63682D632D67656E6572616C2E633A7374617469635F66756E63
- 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_covfun (6)'
- Name: '__llvm_covfun (7)'
- Name: '__llvm_covfun (8)'
- Name: '__llvm_covfun (9)'
- Name: '__llvm_covfun (10)'
- Name: '__llvm_covfun (11)'
- 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_79BE9FB148987D7u
Type: STT_OBJECT
Section: __llvm_covfun
Binding: STB_WEAK
Size: 0x7C
Other: [ STV_HIDDEN ]
- Name: __covrec_688E43F1A505AD83u
Type: STT_OBJECT
Section: '__llvm_covfun (1)'
Binding: STB_WEAK
Size: 0x10F
Other: [ STV_HIDDEN ]
- Name: __covrec_6973C52804C74904u
Type: STT_OBJECT
Section: '__llvm_covfun (2)'
Binding: STB_WEAK
Size: 0x130
Other: [ STV_HIDDEN ]
- Name: __covrec_5E259F0529789455u
Type: STT_OBJECT
Section: '__llvm_covfun (3)'
Binding: STB_WEAK
Size: 0x1F0
Other: [ STV_HIDDEN ]
- Name: __covrec_BF9282263CCA2971u
Type: STT_OBJECT
Section: '__llvm_covfun (4)'
Binding: STB_WEAK
Size: 0x172
Other: [ STV_HIDDEN ]
- Name: __covrec_7B4187606E1C4D3Fu
Type: STT_OBJECT
Section: '__llvm_covfun (5)'
Binding: STB_WEAK
Size: 0x157
Other: [ STV_HIDDEN ]
- Name: __covrec_58A39A89A88AA459u
Type: STT_OBJECT
Section: '__llvm_covfun (6)'
Binding: STB_WEAK
Size: 0x97
Other: [ STV_HIDDEN ]
- Name: __covrec_135D504B043D95F5u
Type: STT_OBJECT
Section: '__llvm_covfun (7)'
Binding: STB_WEAK
Size: 0xB9
Other: [ STV_HIDDEN ]
- Name: __covrec_795CF1BD69C3E520u
Type: STT_OBJECT
Section: '__llvm_covfun (8)'
Binding: STB_WEAK
Size: 0x5C
Other: [ STV_HIDDEN ]
- Name: __covrec_42EB9670C4E7E87Du
Type: STT_OBJECT
Section: '__llvm_covfun (9)'
Binding: STB_WEAK
Size: 0x86
Other: [ STV_HIDDEN ]
- Name: __covrec_DB956436E78DD5FAu
Type: STT_OBJECT
Section: '__llvm_covfun (10)'
Binding: STB_WEAK
Size: 0x26
Other: [ STV_HIDDEN ]
- Name: __covrec_F9EB37679DF4B44Cu
Type: STT_OBJECT
Section: '__llvm_covfun (11)'
Binding: STB_WEAK
Size: 0x47
Other: [ STV_HIDDEN ]
...
202 changes: 101 additions & 101 deletions llvm/test/tools/llvm-cov/Inputs/branch-c-general.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,232 +4,232 @@



void simple_loops() {
void simple_loops() { // CHECK: @LINE|{{.*}}simple_loops()
int i;
for (i = 0; i < 100; ++i) {
for (i = 0; i < 100; ++i) { // CHECK: Branch ([[@LINE]]:15): [True: [[C100:100|1]], False: 1]
}
while (i > 0)
while (i > 0) // CHECK: Branch ([[@LINE]]:10): [True: [[C100]], False: 1]
i--;
do {} while (i++ < 75);
do {} while (i++ < 75); // CHECK: Branch ([[@LINE]]:16): [True: [[C75:75|1]], False: 1]

}

void conditionals() {
for (int i = 0; i < 100; ++i) {
if (i % 2) {
if (i) {}
} else if (i % 3) {
if (i) {}
void conditionals() { // CHECK: @LINE|{{.*}}conditionals()
for (int i = 0; i < 100; ++i) {//CHECK: Branch ([[@LINE]]:19): [True: [[C100]], False: 1]
if (i % 2) { // BRCOV: Branch ([[@LINE]]:9): [True: [[C50:50|1]], False: [[C50]]]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C50]], False: 0]
} else if (i % 3) { // BRCOV: Branch ([[@LINE]]:16): [True: [[C33:33|1]], False: [[C17:17|1]]]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C33]], False: 0]
} else {
if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C16:16|1]], False: 1]
}

if (1 && i) {}
if (0 || i) {}
}
// BRCOV: Branch ([[@LINE+1]]:9): [True: [[C100]], Folded]
if (1 && i) {} // BRCOV: Branch ([[@LINE]]:14): [True: [[C99:99|1]], False: 1]
if (0 || i) {} // BRCOV: Branch ([[@LINE]]:9): [Folded, False: [[C100]]]
} // BRCOV: Branch ([[@LINE-1]]:14): [True: [[C99]], False: 1]

}

void early_exits() {
void early_exits() { // CHECK: @LINE|{{.*}}early_exits()
int i = 0;

if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: 1]

while (i < 100) {
while (i < 100) { // CHECK: Branch ([[@LINE]]:10): [True: [[C51:51|1]], False: 0]
i++;
if (i > 50)
if (i > 50) // BRCOV: Branch ([[@LINE]]:9): [True: 1, False: [[C50]]]
break;
if (i % 2)
if (i % 2) // BRCOV: Branch ([[@LINE]]:9): [True: [[C25:25|1]], False: [[C25]]]
continue;
}

if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:7): [True: 1, False: 0]

do {
if (i > 75)
if (i > 75) // BRCOV: Branch ([[@LINE]]:9): [True: 1, False: [[C25]]]
return;
else
i++;
} while (i < 100);
} while (i < 100); // CHECK: Branch ([[@LINE]]:12): [True: [[C25:25|1]], False: 0]

if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: 0]

}

void jumps() {
void jumps() { // CHECK: @LINE|{{.*}}jumps()
int i;

for (i = 0; i < 2; ++i) {
for (i = 0; i < 2; ++i) { // CHECK: Branch ([[@LINE]]:15): [True: 1, False: 0]
goto outofloop;
// Never reached -> no weights
if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:9): [True: 0, False: 0]
}

outofloop:
if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: 1]

goto loop1;

while (i) {
while (i) { // CHECK: Branch ([[@LINE]]:10): [True: 0, False: 1]
loop1:
if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:9): [True: 0, False: 1]
}

goto loop2;
first:
second:
third:
i++;
if (i < 3)
if (i < 3) // BRCOV: Branch ([[@LINE]]:7): [True: [[C2:2|1]], False: 1]
goto loop2;

while (i < 3) {
while (i < 3) { // CHECK: Branch ([[@LINE]]:10): [True: 0, False: 1]
loop2:
switch (i) {
case 0:
case 0: // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded]
goto first;
case 1:
case 1: // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded]
goto second;
case 2:
case 2: // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded]
goto third;
}
}

for (i = 0; i < 10; ++i) {
for (i = 0; i < 10; ++i) { // CHECK: Branch ([[@LINE]]:15): [True: [[C10:10|1]], False: 1]
goto withinloop;
// never reached -> no weights
if (i) {}
// never reached -> no weights
if (i) {} // BRCOV: Branch ([[@LINE]]:9): [True: 0, False: 0]
withinloop:
if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:9): [True: [[C9:9|1]], False: 1]
}

}

void switches() {
void switches() { // CHECK: @LINE|{{.*}}switches()
static int weights[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5};

// No cases -> no weights
switch (weights[0]) {
default:
default: // BRCOV: Branch ([[@LINE]]:3): [True: 1, Folded]
break;
}

// CHECK: Branch ([[@LINE+1]]:63): [True: [[C15:15|1]], False: 0]
for (int i = 0, len = sizeof(weights) / sizeof(weights[0]); i < len; ++i) {
switch (i[weights]) {
case 1:
if (i) {}
case 1: // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 0, False: 1]
// fallthrough
case 2:
if (i) {}
case 2: // BRCOV: Branch ([[@LINE]]:5): [True: [[C2]], Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C2]], False: 1]
break;
case 3:
if (i) {}
case 3: // BRCOV: Branch ([[@LINE]]:5): [True: [[C3:3|1]], Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C3]], False: 0]
continue;
case 4:
if (i) {}
case 4: // BRCOV: Branch ([[@LINE]]:5): [True: [[C4:4|1]], Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C4]], False: 0]
switch (i) {
case 6 ... 9:
if (i) {}
case 6 ... 9: // BRCOV: Branch ([[@LINE]]:7): [True: [[C4]], Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:13): [True: [[C4]], False: 0]
continue;
}

default:
if (i == len - 1)
default: // BRCOV: Branch ([[@LINE]]:5): [True: [[C5:5|1]], Folded]
if (i == len - 1) // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: [[C4]]]
return;
}
}

// Never reached -> no weights
if (weights[0]) {}
if (weights[0]) {} // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: 0]

}

void big_switch() {
for (int i = 0; i < 32; ++i) {
void big_switch() { // CHECK: @LINE|{{.*}}big_switch()
for (int i = 0; i < 32; ++i) {// CHECK: Branch ([[@LINE]]:19): [True: [[C32:32|1]], False: 1]
switch (1 << i) {
case (1 << 0):
if (i) {}
case (1 << 0): // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 0, False: 1]
// fallthrough
case (1 << 1):
if (i) {}
case (1 << 1): // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: 1]
break;
case (1 << 2) ... (1 << 12):
if (i) {}
case (1 << 2) ... (1 << 12):// BRCOV: Branch ([[@LINE]]:5): [True: [[C11:11|1]], Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C11]], False: 0]
break;
// The branch for the large case range above appears after the case body.

case (1 << 13):
if (i) {}
case (1 << 13): // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: 0]
break;
case (1 << 14) ... (1 << 28):
if (i) {}
case (1 << 14) ... (1 << 28)://BRCOV: Branch ([[@LINE]]:5): [True: [[C15]], Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C15]], False: 0]
break;
// The branch for the large case range above appears after the case body.

case (1 << 29) ... ((1 << 29) + 1):
if (i) {}
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: 0]
break;
default:
if (i) {}
default: // BRCOV: Branch ([[@LINE]]:5): [True: [[C2]], Folded]
if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[C2]], False: 0]
break;
}
}

}

void boolean_operators() {
void boolean_operators() { // CHECK: @LINE|{{.*}}boolean_operators()
int v;
for (int i = 0; i < 100; ++i) {
v = i % 3 || i;

v = i % 3 && i;

v = i % 3 || i % 2 || i;

v = i % 2 && i % 3 && i;
}

}

void boolop_loops() {
v = i % 3 || i; // BRCOV: Branch ([[@LINE]]:9): [True: [[C66:66|1]], False: [[C34:34|1]]]
// BRCOV: Branch ([[@LINE-1]]:18): [True: [[C33]], False: 1]
v = i % 3 && i; // BRCOV: Branch ([[@LINE]]:9): [True: [[C66]], False: [[C34]]]
// BRCOV: Branch ([[@LINE-1]]:18): [True: [[C66]], False: 0]
v = i % 3 || i % 2 || i; // BRCOV: Branch ([[@LINE]]:9): [True: [[C66]], False: [[C34]]]
// BRCOV: Branch ([[@LINE-1]]:18): [True: [[C17]], False: [[C17]]]
v = i % 2 && i % 3 && i; // BRCOV: Branch ([[@LINE-2]]:27): [True: [[C16]], False: 1]
} // BRCOV: Branch ([[@LINE-1]]:9): [True: [[C50]], False: [[C50]]]
// BRCOV: Branch ([[@LINE-2]]:18): [True: [[C33]], False: [[C17]]]
} // BRCOV: Branch ([[@LINE-3]]:27): [True: [[C33]], False: 0]

void boolop_loops() { // CHECK: @LINE|{{.*}}boolop_loops()
int i = 100;

while (i && i > 50)
i--;

while ((i % 2) || (i > 0))
i--;

for (i = 100; i && i > 50; --i);
while (i && i > 50) // BRCOV: Branch ([[@LINE]]:10): [True: [[C51]], False: 0]
i--; // BRCOV: Branch ([[@LINE-1]]:15): [True: [[C50]], False: 1]

for (; (i % 2) || (i > 0); --i);
while ((i % 2) || (i > 0)) // BRCOV: Branch ([[@LINE]]:10): [True: [[C25]], False: [[C26:26|1]]]
i--; // BRCOV: Branch ([[@LINE-1]]:21): [True: [[C25]], False: 1]

for (i = 100; i && i > 50; --i); // BRCOV: Branch ([[@LINE]]:17): [True: [[C51]], False: 0]
// BRCOV: Branch ([[@LINE-1]]:22): [True: [[C50]], False: 1]
for (; (i % 2) || (i > 0); --i); // BRCOV: Branch ([[@LINE]]:10): [True: [[C25]], False: [[C26]]]
// BRCOV: Branch ([[@LINE-1]]:21): [True: [[C25]], False: 1]
}

void conditional_operator() {
void conditional_operator() { // CHECK: @LINE|{{.*}}conditional_operator()
int i = 100;

int j = i < 50 ? i : 1;
int j = i < 50 ? i : 1; // BRCOV: Branch ([[@LINE]]:11): [True: 0, False: 1]

int k = i ?: 0;
int k = i ?: 0; // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: 0]

}

void do_fallthrough() {
for (int i = 0; i < 10; ++i) {
void do_fallthrough() { // CHECK: @LINE|{{.*}}do_fallthrough()
for (int i = 0; i < 10; ++i) {// CHECK: Branch ([[@LINE]]:19): [True: [[C10]], False: 1]
int j = 0;
do {
// The number of exits out of this do-loop via the break statement
// exceeds the counter value for the loop (which does not include the
// fallthrough count). Make sure that does not violate any assertions.
if (i < 8) break;
j++;
} while (j < 2);
} while (j < 2); // CHECK: Branch ([[@LINE]]:14): [True: [[C2:2|1]], False: [[C2]]]
}
}

static void static_func() {
for (int i = 0; i < 10; ++i) {
static void static_func() { // CHECK: @LINE|{{.*}}static_func()
for (int i = 0; i < 10; ++i) {// CHECK: Branch ([[@LINE]]:19): [True: [[C10]], False: 1]
}
}

Expand All @@ -254,7 +254,7 @@ int main(int argc, const char *argv[]) {
conditional_operator();
do_fallthrough();
static_func();
extern void __llvm_profile_write_file();
__llvm_profile_write_file();
(void)0;
(void)0;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Instrument block coverage
:single_byte_coverage
_Z4funcii
# Func Hash:
8468630735863722633
# Num Counters:
67
# Counter Values:
4
0
0
0
0
2
0
2
2
3
2
0
0
0
0
0
0
1
0
1
1
3
3
3
3
3
3
1
2
0
3
0
0
0
1
0
1
0
3
3
3
3
4
1
0
2
1
0
0
3
0
2
0
2
0
0
4
4
4
0
4
1
3
4
3
1
4

main
# Func Hash:
24
# Num Counters:
1
# Counter Values:
4

57 changes: 57 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--- !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: F0A0ED2C305C0BB32D02000089B21C19C99E86758F2950E06FBD46E8010100600108194302100701000101010C000E01000C010E01000C020E01000C030E01000C040E25010C000E1D010C000E15010C000E0D010C000E05010C000E100101000101010C000E01000C010E01000C020E01000C030E01000C040E4D010C000E45010C000E3D010C000E35010C000E2D010C000E100101000101010C011001000C031001000C051001000C071001000C091001000D000F69010D000F65010C011065000D000F71010D000F61010C011061000D000F79010D000F5D010C01105D000D000F8101010D000F59010C011059000D000F8901010D000F55010C011055000D000F9101010D000F100101000101010C011001000C031001000C051001000C071001000C091001000D000FAD01010D000FA901010C0110A901000D000FB501010D000FA501010C0110A501000D000FBD01010D000FA101010C0110A101000D000FC501010D000F9D01010C01109D01000D000FCD01010D000F9901010C01109901000D000FD501010D000F10010100010101070008DD010009018580808008DD0101050016E1010017028580808008E101020500161001010001E50101030E02E50100070008E9010009018580808008E90101050016ED010017028580808008ED01020500161001010001F10101030902F10100070008F5010009018580808008F50101050016F9010017028580808008F901020500161001010001FD0101030402FD01000700088102000901858080800881020105001685020017028580808008850202050016
- Name: '__llvm_covfun (1)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: FAD58DE7366495DB0900000018000000000000008F2950E06FBD46E801010001014F010402
- Name: __llvm_covmap
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 000000001D0000000000000006000000021A0000186272616E63682D6C6F676963616C2D6D697865642E637070000000
- Name: __llvm_prf_names
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_GNU_RETAIN ]
AddressAlign: 0x1
Content: 0E005F5A3466756E636969016D61696E
- Type: SectionHeaderTable
Sections:
- Name: .strtab
- Name: __llvm_covfun
- Name: '__llvm_covfun (1)'
- 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_B30B5C302CEDA0F0u
Type: STT_OBJECT
Section: __llvm_covfun
Binding: STB_WEAK
Size: 0x249
Other: [ STV_HIDDEN ]
- Name: __covrec_DB956436E78DD5FAu
Type: STT_OBJECT
Section: '__llvm_covfun (1)'
Binding: STB_WEAK
Size: 0x25
Other: [ STV_HIDDEN ]
...
83 changes: 83 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@




#include <stdio.h>
#include <stdlib.h>
// CHECK: |{{ +}}[[C4:4|1]]|void func(
void func(int a, int b) {
bool b0 = a <= b;
bool b1 = a == b;
bool b2 = a >= b;
bool b3 = a < b;
bool b4 = a > b;
bool b5 = a != b;

bool c = b0 && // BRCOV: Branch ([[@LINE]]:12): [True: [[C3:3|1]], False: 1]
b1 && // BRCOV: Branch ([[@LINE]]:12): [True: [[C2:2|1]], False: 1]
b2 && // BRCOV: Branch ([[@LINE]]:12): [True: [[C2]], False: 0]
b3 && // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: [[C2]]]
b4 && // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]
b5; // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]

bool d = b0 || // BRCOV: Branch ([[@LINE]]:12): [True: [[C3]], False: 1]
b1 || // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 1]
b2 || // BRCOV: Branch ([[@LINE]]:12): [True: 1, False: 0]
b3 || // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]
b4 || // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]
b5; // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]

bool e = (b0 && // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 1]
b5) || // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
(b1 && // BRCOV: Branch ([[@LINE]]:13): [True: [[C2]], False: 1]
b4) || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[C2]]]
(b2 && // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
b3) || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
(b3 && // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
b2) || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 0]
(b4 && // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
b1) || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 1]
(b5 && // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
b0); // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 1]

bool f = (b0 || // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 1]
b5) && // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: 0]
(b1 || // BRCOV: Branch ([[@LINE]]:13): [True: [[C2]], False: [[C2]]]
b4) && // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: 1]
(b2 || // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
b3) && // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 0]
(b3 || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
b2) && // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
(b4 || // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
b1) && // BRCOV: Branch ([[@LINE]]:13): [True: [[C2]], False: 0]
(b5 || // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
b0); // BRCOV: Branch ([[@LINE]]:13): [True: [[C2]], False: 0]

if (c) // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: [[C4]]]
printf("case0\n");
else
printf("case1\n");

if (d) // BRCOV: Branch ([[@LINE]]:7): [True: [[C4]], False: 0]
printf("case2\n");
else
printf("case3\n");

if (e) // BRCOV: Branch ([[@LINE]]:7): [True: 1, False: [[C3]]]
printf("case4\n");
else
printf("case5\n");

if (f) // BRCOV: Branch ([[@LINE]]:7): [True: [[C3]], False: 1]
printf("case6\n");
else
printf("case7\n");
}


int main(int argc, char *argv[])
{
func(atoi(argv[1]), atoi(argv[2]));
(void)0;
return 0;
}
53 changes: 53 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-macros-single.proftext
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Instrument block coverage
:single_byte_coverage
_Z4funcii
# Func Hash:
456046650042366162
# Num Counters:
19
# Counter Values:
3
1
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0

_Z5func2ii
# Func Hash:
14151920320560143107
# Num Counters:
10
# Counter Values:
3
3
2
1
0
3
0
3
1
0

main
# Func Hash:
24
# Num Counters:
1
# Counter Values:
3

69 changes: 69 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-macros-single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
--- !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: F0A0ED2C305C0BB33F010000D238C8100334540693E696313ECE8F5D15010101010101010101010101010101010101010101001501101911020C010C0011140015001A100101005C1C010C0011100101006224010C001210010100682C010C0012100101006E34010C0012100101007401010A000B01000A001001000A001501000A001A45000F00103D00140015350019001A2D001E001F10010104550201050F001701000F00170105060F00170301070F001F3C00100015440019001E014C0910001501540A100016015C0B1000160201050F001701000F0017010D060F00170301070F001F64001000156C0019001E017409100015017C0A1000160201050F001701000F00170115060F00170301070F001F8401001000158C010019001E019401091000150201050F001701000F0017011D060F00170301070F001F9C0100100015A4010019001E0201050F001701000F00170125060F0017
- Name: '__llvm_covfun (1)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: B01D983FC67363959E000000039B9E2C8DB865C493E696313ECE8F5D0D01010101010101010101010101000401241A07020C010E0014140018001D1001010365011C0B1000160405080F002624001000152C0018001D3400200025013C0A1000160305070F001F44001000154C0019001E0119060F0017011D050F00170154091000150205050F001705000F00170121060F00170401070F001F01000F001F5C00100015640019001E0201050F001701000F0017010D060F0017
- Name: '__llvm_covfun (2)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: FAD58DE7366495DB09000000180000000000000093E696313ECE8F5D01010001012F010502
- Name: __llvm_covmap
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 0000000016000000000000000600000002130000116272616E63682D6D6163726F732E6370700000
- Name: __llvm_prf_names
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_GNU_RETAIN ]
AddressAlign: 0x1
Content: 19005F5A3466756E636969015F5A3566756E63326969016D61696E
- Type: SectionHeaderTable
Sections:
- Name: .strtab
- Name: __llvm_covfun
- Name: '__llvm_covfun (1)'
- Name: '__llvm_covfun (2)'
- 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_B30B5C302CEDA0F0u
Type: STT_OBJECT
Section: __llvm_covfun
Binding: STB_WEAK
Size: 0x15B
Other: [ STV_HIDDEN ]
- Name: __covrec_956373C63F981DB0u
Type: STT_OBJECT
Section: '__llvm_covfun (1)'
Binding: STB_WEAK
Size: 0xBA
Other: [ STV_HIDDEN ]
- Name: __covrec_DB956436E78DD5FAu
Type: STT_OBJECT
Section: '__llvm_covfun (2)'
Binding: STB_WEAK
Size: 0x25
Other: [ STV_HIDDEN ]
...
52 changes: 52 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-macros.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@




#define COND1 (a == b)
#define COND2 (a != b)
#define COND3 (COND1 && COND2)
#define COND4 (COND3 ? COND2 : COND1)
#define MACRO1 COND3
#define MACRO2 MACRO1
#define MACRO3 MACRO2

#include <stdlib.h>

// CHECK: |{{ +}}[[C3:3|1]]|bool func(
bool func(int a, int b) {
bool c = COND1 && COND2; // BRCOV: | | | Branch ([[@LINE-12]]:15): [True: 1, False: [[C2:2|1]]]
// BRCOV: | | | Branch ([[@LINE-12]]:15): [True: 0, False: 1]
bool d = COND3; // BRCOV: | | | | | Branch ([[@LINE-14]]:15): [True: 1, False: [[C2]]]
// BRCOV: | | | | | Branch ([[@LINE-14]]:15): [True: 0, False: 1]
bool e = MACRO1; // BRCOV: | | | | | | | Branch ([[@LINE-16]]:15): [True: 1, False: [[C2]]]
// BRCOV: | | | | | | | Branch ([[@LINE-16]]:15): [True: 0, False: 1]
bool f = MACRO2; // BRCOV: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 1, False: [[C2]]]
// BRCOV: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 0, False: 1]
bool g = MACRO3; // BRCOV: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 1, False: [[C2]]]
// BRCOV: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 0, False: 1]
return c && d && e && f && g;
// BRCOV: | Branch ([[@LINE-1]]:10): [True: 0, False: [[C3]]]
// BRCOV: | Branch ([[@LINE-2]]:15): [True: 0, False: 0]
// BRCOV: | Branch ([[@LINE-3]]:20): [True: 0, False: 0]
// BRCOV: | Branch ([[@LINE-4]]:25): [True: 0, False: 0]
// BRCOV: | Branch ([[@LINE-5]]:30): [True: 0, False: 0]
}


bool func2(int a, int b) {
bool h = MACRO3 || COND4; // BRCOV: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 1, False: [[C2]]]
// BRCOV: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 0, False: 1]
// BRCOV: | | | | | | | Branch ([[@LINE-34]]:15): [True: 1, False: [[C2]]]
// BRCOV: | | | | | | | Branch ([[@LINE-34]]:15): [True: 0, False: 1]
// BRCOV: | | | Branch ([[@LINE-33]]:15): [True: 1, False: [[C2]]]
return h;
}


int main(int argc, char *argv[])
{
func(atoi(argv[1]), atoi(argv[2]));
func2(atoi(argv[1]), atoi(argv[2]));
(void)0;
return 0;
}
58 changes: 58 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-showBranchPercentage.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@





#include <stdio.h>
#include <stdlib.h>

extern void __llvm_profile_write_file(void);

int main(int argc, char *argv[])
{
int i = 0;
if (argc < 3) // CHECK: Branch ([[@LINE]]:7): [True: 16.67%, False: 83.33%]
{
(void)0;
return 0;
}

int a = atoi(argv[1]);
int b = atoi(argv[2]);

// CHECK: Branch ([[@LINE+4]]:8): [True: 20.00%, False: 80.00%]
// CHECK: Branch ([[@LINE+3]]:18): [True: 0.00%, False: 100.00%]
// CHECK: Branch ([[@LINE+2]]:29): [True: 0.00%, False: 100.00%]
// CHECK: Branch ([[@LINE+1]]:40): [True: 40.00%, False: 60.00%]
if ((a == 0 && b == 2) || b == 34 || a == b)
printf("case1\n");

b = (a != 0 || a == 2) ? b : b+2; // CHECK: Branch ([[@LINE]]:8): [True: 80.00%, False: 20.00%]
// CHECK: Branch ([[@LINE-1]]:18): [True: 0.00%, False: 100.00%]
b = (a != 0 && a == 1); // CHECK: Branch ([[@LINE]]:8): [True: 80.00%, False: 20.00%]
// CHECK: Branch ([[@LINE-1]]:18): [True: 25.00%, False: 75.00%]
for (i = 0; i < b; i++) { a = 2 + b + b; }
// CHECK: Branch ([[@LINE-1]]:15): [True: 16.67%, False: 83.33%]

b = a;

switch (a)
{
case 0: // CHECK: Branch ([[@LINE]]:5): [True: 20.00%, False: 80.00%]
printf("case0\n");
case 2: // CHECK: Branch ([[@LINE]]:5): [True: 20.00%, False: 80.00%]
printf("case2\n");
case 3: // CHECK: Branch ([[@LINE]]:5): [True: 0.00%, False: 100.00%]
printf("case3\n");
default: break; // CHECK: Branch ([[@LINE]]:5): [True: 60.00%, False: 40.00%]
}

i = 0;
do {
printf("loop\n");
} while (i++ < 10); // CHECK: Branch ([[@LINE]]:12): [True: 90.91%, False: 9.09%]

(void)b;

return 0;
}
49 changes: 49 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-templates-single.proftext
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Instrument block coverage
:single_byte_coverage
_Z4funcIbEiT_
# Func Hash:
11045778961
# Num Counters:
4
# Counter Values:
1
1
0
0

_Z4funcIfEiT_
# Func Hash:
11045778961
# Num Counters:
4
# Counter Values:
1
0
1
0

_Z4funcIiEiT_
# Func Hash:
11045778961
# Num Counters:
4
# Counter Values:
1
0
1
0

main
# Func Hash:
185286008276329560
# Num Counters:
7
# Counter Values:
1
1
1
0
1
1
1

81 changes: 81 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-templates-single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
--- !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: FAD58DE7366495DB5100000058242991A444920226ED9A40DAABBC6B0101000D011D0C090201010700130500140185808080080501050016090103060209000700170D00180185808080080D01050016110103040211000700171500180185808080081501050016190103010B
- Name: '__llvm_covfun (1)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 5427717259E0E43E38000000113661920200000026ED9A40DAABBC6B01010008010D0F06020101060007050008018580808008050105000D09000E028580808008090205000D0D000E0183808080080D01030102
- Name: '__llvm_covfun (2)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 4B7E22082F0551AA38000000113661920200000026ED9A40DAABBC6B01010008010D0F06020101060007050008018580808008050105000D09000E028580808008090205000D0D000E0183808080080D01030102
- Name: '__llvm_covfun (3)'
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: AC1440BC3DA3E41A38000000113661920200000026ED9A40DAABBC6B01010008010D0F06020101060007050008018580808008050105000D09000E028580808008090205000D0D000E0183808080080D01030102
- Name: __llvm_covmap
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 0000000019000000000000000600000002160000146272616E63682D74656D706C617465732E637070000000
- Name: __llvm_prf_names
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_GNU_RETAIN ]
AddressAlign: 0x1
Content: 2E006D61696E015F5A3466756E6349694569545F015F5A3466756E6349624569545F015F5A3466756E6349664569545F
- Type: SectionHeaderTable
Sections:
- Name: .strtab
- Name: __llvm_covfun
- Name: '__llvm_covfun (1)'
- Name: '__llvm_covfun (2)'
- Name: '__llvm_covfun (3)'
- 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: 0x6D
Other: [ STV_HIDDEN ]
- Name: __covrec_3EE4E05972712754u
Type: STT_OBJECT
Section: '__llvm_covfun (1)'
Binding: STB_WEAK
Size: 0x54
Other: [ STV_HIDDEN ]
- Name: __covrec_AA51052F08227E4Bu
Type: STT_OBJECT
Section: '__llvm_covfun (2)'
Binding: STB_WEAK
Size: 0x54
Other: [ STV_HIDDEN ]
- Name: __covrec_1AE4A33DBC4014ACu
Type: STT_OBJECT
Section: '__llvm_covfun (3)'
Binding: STB_WEAK
Size: 0x54
Other: [ STV_HIDDEN ]
...
38 changes: 38 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-templates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@





#include <stdio.h>
template<typename T>
void unused(T x) {
return;
}

template<typename T>
int func(T x) {
if(x) // BRCOV: | Branch ([[@LINE]]:6): [True: 0, False: 1]
return 0; // BRCOV: | Branch ([[@LINE-1]]:6): [True: 1, False: 0]
else // BRCOV: | Branch ([[@LINE-2]]:6): [True: 0, False: 1]
return 1;
int j = 1;
}

// CHECK-LABEL: _Z4funcIiEiT_:
// BRCOV: | | Branch ([[@LINE-8]]:6): [True: 0, False: 1]
// CHECK-LABEL: _Z4funcIbEiT_:
// BRCOV: | | Branch ([[@LINE-10]]:6): [True: 1, False: 0]
// CHECK-LABEL: _Z4funcIfEiT_:
// BRCOV: | | Branch ([[@LINE-12]]:6): [True: 0, False: 1]


int main() {
if (func<int>(0)) // BRCOV: | Branch ([[@LINE]]:7): [True: 1, False: 0]
printf("case1\n");
if (func<bool>(true)) // BRCOV: | Branch ([[@LINE]]:7): [True: 0, False: 1]
printf("case2\n");
if (func<float>(0.0)) // BRCOV: | Branch ([[@LINE]]:7): [True: 1, False: 0]
printf("case3\n");
(void)0;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Instrument block coverage
:single_byte_coverage
main
# Func Hash:
15239891155360101223
# Num Counters:
11
# Counter Values:
161
0
161
161
161
161
161
0
161
0
161

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--- !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: FAD58DE7366495DB9E0000006733DBEA42F87ED3C60E0B951FF3509D0101010D111A01060C130210020100010101070008050009008A8080800805000A0204090204008A8080800809000A020410030100010D01030A02030013001A20110D0013001A11001C001F11002000A180808008110021020410030100010D0107000D19000F00908080800819001000151D0018001D1501030502150007000D25000F018980808008250109000E290109000E1001010001210103000B
- Name: __llvm_covmap
Type: SHT_PROGBITS
Flags: [ SHF_GNU_RETAIN ]
AddressAlign: 0x8
Content: 00000000200000000000000006000000021D00001B73686F774C696E65457865637574696F6E436F756E74732E637070
- Name: __llvm_prf_names
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_GNU_RETAIN ]
AddressAlign: 0x1
Content: 04006D61696E
- Type: SectionHeaderTable
Sections:
- Name: .strtab
- Name: __llvm_covfun
- 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: 0xBA
Other: [ STV_HIDDEN ]
...
29 changes: 29 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE+2]]' href='#L[[@LINE+2]]'><pre>[[@LINE+2]]</pre></a></td><td class='skipped-line'></td><td class='code'><pre>// before
// HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE+1]]' href='#L[[@LINE+1]]'><pre>[[@LINE+1]]</pre></a></td><td class='skipped-line'></td><td class='code'><pre>// before
// before any coverage // WHOLE-FILE: [[@LINE]]| |// before
// FILTER-NOT: [[@LINE-1]]| |// before
// HTML: <td class='line-number'><a name='L[[@LINE+1]]' href='#L[[@LINE+1]]'><pre>[[@LINE+1]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() {
int main() { // TEXT: [[@LINE]]| [[C161:161|1]]|int main(
int x = 0; // TEXT: [[@LINE]]| [[C161]]| int x

if (x) { // TEXT: [[@LINE]]| [[C161]]| if (x)
x = 0; // TEXT: [[@LINE]]| 0| x = 0
} else { // TEXT: [[@LINE]]| [[C161]]| } else
x = 1; // TEXT: [[@LINE]]| [[C161]]| x = 1
} // TEXT: [[@LINE]]| [[C161]]| }

for (int i = 0; i < 100; ++i) { // TEXT: [[@LINE]]| [[C16K2:16\.2k|1]]| for (
x = 1; // TEXT: [[@LINE]]| [[C16K1:16\.1k|1]]| x = 1
} // TEXT: [[@LINE]]| [[C16K1]]| }

x = x < 10 ? x + 1 : x - 1; // TEXT: [[@LINE]]| [[C161]]| x =
x = x > 10 ? // TEXT: [[@LINE]]| [[C161]]| x =
x - 1: // TEXT: [[@LINE]]| 0| x
x + 1; // TEXT: [[@LINE]]| [[C161]]| x

return 0; // TEXT: [[@LINE]]| [[C161]]| return
} // TEXT: [[@LINE]]| [[C161]]|}
// after coverage // WHOLE-FILE: [[@LINE]]| |// after
// FILTER-NOT: [[@LINE-1]]| |// after
// HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE-2]]' href='#L[[@LINE-2]]'><pre>[[@LINE-2]]</pre></a></td><td class='skipped-line'></td><td class='code'><pre>// after
// HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE-3]]' href='#L[[@LINE-3]]'><pre>[[@LINE-3]]</pre></a></td><td class='skipped-line'></td><td class='code'><pre>// after
96 changes: 96 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/yaml.makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This is for developers' convenience and not expected to be in build steps.
#
# Usage:
# cd /path/to/llvm-project/llvm/test/tools/llvm-cov/Inputs
# PATH=/path/to/build/bin:$PATH make -f yaml.makefile

CFLAGS_COVMAP = -fcoverage-compilation-dir=. \
-mllvm -runtime-counter-relocation=true \
-mllvm -conditional-counter-update=true \
-mllvm -enable-name-compression=false \
-fprofile-instr-generate -fcoverage-mapping \
$(if $(filter mcdc-%, $*), $(CFLAGS_MCDC))

CFLAGS_MCDC = -fcoverage-mcdc

%.o: %.cpp
clang++ $< -c -o $@ $(CFLAGS_COVMAP)

%.o: %.c
clang $< -c -o $@ $(CFLAGS_COVMAP)

%-single.o: %.cpp
clang++ $< -c -o $@ \
-mllvm -enable-single-byte-coverage=true \
$(CFLAGS_COVMAP)

%-single.o: %.c
clang $< -c -o $@ \
-mllvm -enable-single-byte-coverage=true \
$(CFLAGS_COVMAP)

%.covmap.o: %.o
llvm-objcopy \
--only-section=__llvm_covfun \
--only-section=__llvm_covmap \
--only-section=__llvm_prf_names \
--strip-unneeded \
$< $@

%.yaml: %.covmap.o
obj2yaml $< > $@

%.exe: %.o
clang++ -fprofile-instr-generate $^ -o $@

ARGS_branch-logical-mixed := \
0 0; \
0 1; \
1 0; \
1 1

ARGS_branch-macros := \
0 1; \
1 0; \
1 1

ARGS_branch-showBranchPercentage := \
0 1; \
1 1; \
2 2; \
4 0; \
5 0; \
1

ARGS_showLineExecutionCounts := $(patsubst %,%;,$(shell seq 161))

ARGS_mcdc-const-folding := \
0 1; \
1 0; \
1 1; \
1 1

%.profdata: %.exe
-find -name '$*.*.profraw' | xargs rm -fv
@if [ "$(ARGS_$(patsubst %-single,%,$*))" = "" ]; then \
echo "Executing: $<"; \
LLVM_PROFILE_FILE=$*.%p%c.profraw ./$<; \
else \
LLVM_PROFILE_FILE=$*.%p%c.profraw; \
export LLVM_PROFILE_FILE; \
for xcmd in $(shell echo "$(ARGS_$(patsubst %-single,%,$*))" | tr ';[:blank:]' ' %'); do \
cmd=$$(echo "$$xcmd" | tr '%' ' '); \
echo "Executing series: $< $$cmd"; \
eval "./$< $$cmd"; \
done; \
fi
find -name '$*.*.profraw' | xargs llvm-profdata merge --sparse -o $@

%.proftext: %.profdata
llvm-profdata merge --text -o $@ $<

.PHONY: all
all: \
$(patsubst %.yaml,%.proftext, $(wildcard *.yaml)) \
$(wildcard *.yaml)
-find -name '*.profraw' | xargs rm -f
6 changes: 5 additions & 1 deletion llvm/test/tools/llvm-cov/branch-c-general.test
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@



// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// 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%
Expand Down Expand Up @@ -164,3 +164,7 @@
// HTML-INDEX: 79.07% (136/172)
// HTML-INDEX: <tr class='light-row-bold'>
// HTML-INDEX: Totals

// RUN: yaml2obj %S/Inputs/branch-c-general-single.yaml -o %t.o
// RUN: llvm-profdata merge %S/Inputs/branch-c-general-single.proftext -o %t.profdata
// RUN: llvm-cov show --show-branches=count %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs %S/Inputs/branch-c-general.c | FileCheck %S/Inputs/branch-c-general.c
90 changes: 0 additions & 90 deletions llvm/test/tools/llvm-cov/branch-logical-mixed.cpp

This file was deleted.

17 changes: 17 additions & 0 deletions llvm/test/tools/llvm-cov/branch-logical-mixed.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: llvm-profdata merge %S/Inputs/branch-logical-mixed.proftext -o %t.profdata
// RUN: llvm-cov show --show-branches=count %S/Inputs/branch-logical-mixed.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-logical-mixed.cpp -check-prefixes=CHECK,BRCOV
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-logical-mixed.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-logical-mixed.cpp
| FileCheck %s -check-prefix=REPORT

// RUN: yaml2obj %S/Inputs/branch-logical-mixed-single.yaml -o %t.o
// RUN: llvm-profdata merge %S/Inputs/branch-logical-mixed-single.proftext -o %t.profdata
// RUN: llvm-cov show --show-branches=count %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs | FileCheck %S/Inputs/branch-logical-mixed.cpp
// RUN: llvm-cov report --show-branch-summary %t.o -instr-profile %t.profdata -show-functions -path-equivalence=.,%S/Inputs %S/Inputs/branch-logical-mixed.cpp
| FileCheck %s -check-prefix=REPORT

// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// REPORT-NEXT: ---
// REPORT-NEXT: _Z4funcii 77 15 80.52% 60 2 96.67% 80 30 62.50%
// REPORT-NEXT: main 1 0 100.00% 5 0 100.00% 0 0 0.00%
// REPORT-NEXT: ---
// REPORT-NEXT: TOTAL 78 15 80.77% 65 2 96.92% 80 30 62.50%
60 changes: 0 additions & 60 deletions llvm/test/tools/llvm-cov/branch-macros.cpp

This file was deleted.

15 changes: 15 additions & 0 deletions llvm/test/tools/llvm-cov/branch-macros.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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
// 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

// RUN: yaml2obj %S/Inputs/branch-macros-single.yaml -o %t.o
// RUN: llvm-profdata merge %S/Inputs/branch-macros-single.proftext -o %t.profdata
// RUN: llvm-cov show --show-expansions --show-branches=count %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs | FileCheck %S/Inputs/branch-macros.cpp

// 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: 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%
8 changes: 4 additions & 4 deletions llvm/test/tools/llvm-cov/branch-noShowBranch.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

// CHECK-NOT: | Branch

// REPORT: Name Regions Miss Cover Lines Miss Cover
// REPORT: Name Regions Miss Cover Lines Miss Cover
// REPORT-NOT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// REPORT: ---
// 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: early_exits 20 4 80.00% 25 2 92.00% 16 6 62.50%
Expand All @@ -20,6 +20,6 @@
// 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 13 94.44% 174 38 78.16%
// REPORT: TOTAL 197 24 87.82% 234 8 96.58%
// REPORT-NOT: TOTAL 197 24 87.82% 234 13 94.44% 174 38 78.16%

Original file line number Diff line number Diff line change
@@ -1,63 +1,10 @@
// Test visualization of branch taken percentages

// RUN: llvm-profdata merge %S/Inputs/branch-showBranchPercentage.proftext -o %t.profdata
// RUN: llvm-cov show --show-branches=percent %S/Inputs/branch-showBranchPercentage.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
// RUN: llvm-cov show --show-branches=percent %S/Inputs/branch-showBranchPercentage.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-showBranchPercentage.c

#include <stdio.h>
#include <stdlib.h>

extern void __llvm_profile_write_file(void);

int main(int argc, char *argv[])
{
int i = 0;
if (argc < 3) // CHECK: Branch ([[@LINE]]:7): [True: 16.67%, False: 83.33%]
{
__llvm_profile_write_file();
return 0;
}

int a = atoi(argv[1]);
int b = atoi(argv[2]);

// CHECK: Branch ([[@LINE+4]]:8): [True: 20.00%, False: 80.00%]
// CHECK: Branch ([[@LINE+3]]:18): [True: 0.00%, False: 100.00%]
// CHECK: Branch ([[@LINE+2]]:29): [True: 0.00%, False: 100.00%]
// CHECK: Branch ([[@LINE+1]]:40): [True: 40.00%, False: 60.00%]
if ((a == 0 && b == 2) || b == 34 || a == b)
printf("case1\n");

b = (a != 0 || a == 2) ? b : b+2; // CHECK: Branch ([[@LINE]]:8): [True: 80.00%, False: 20.00%]
// CHECK: Branch ([[@LINE-1]]:18): [True: 0.00%, False: 100.00%]
b = (a != 0 && a == 1); // CHECK: Branch ([[@LINE]]:8): [True: 80.00%, False: 20.00%]
// CHECK: Branch ([[@LINE-1]]:18): [True: 25.00%, False: 75.00%]
for (i = 0; i < b; i++) { a = 2 + b + b; }
// CHECK: Branch ([[@LINE-1]]:15): [True: 16.67%, False: 83.33%]

b = a;

switch (a)
{
case 0: // CHECK: Branch ([[@LINE]]:5): [True: 20.00%, False: 80.00%]
printf("case0\n");
case 2: // CHECK: Branch ([[@LINE]]:5): [True: 20.00%, False: 80.00%]
printf("case2\n");
case 3: // CHECK: Branch ([[@LINE]]:5): [True: 0.00%, False: 100.00%]
printf("case3\n");
default: break; // CHECK: Branch ([[@LINE]]:5): [True: 60.00%, False: 40.00%]
}

i = 0;
do {
printf("loop\n");
} while (i++ < 10); // CHECK: Branch ([[@LINE]]:12): [True: 90.91%, False: 9.09%]

__llvm_profile_write_file();

return b;
}
// RUN: llvm-profdata merge %S/Inputs/branch-showBranchPercentage.proftext -o %t.profdata
// RUN: llvm-cov show --show-branches=percent %S/Inputs/branch-showBranchPercentage.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s -format html -o %t.html.dir
// RUN: llvm-cov show --show-branches=percent %S/Inputs/branch-showBranchPercentage.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -format html -o %t.html.dir

// Test html output.
// RUN: FileCheck -check-prefix=HTML -input-file=%t.html.dir/coverage/tmp/branch-showBranchPercentage.c.html %s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
// RUN: llvm-profdata merge %S/Inputs/branch-templates.proftext -o %t.profdata
// RUN: llvm-cov show --show-expansions --show-branches=count %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S %s | FileCheck %s -check-prefix=REPORT
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s -check-prefix=REPORTFILE
// RUN: llvm-cov show --show-expansions --show-branches=count %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-templates.cpp
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-templates.cpp | FileCheck %s -check-prefix=REPORT
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %s -check-prefix=REPORTFILE

#include <stdio.h>
template<typename T>
void unused(T x) {
return;
}
// RUN: yaml2obj %S/Inputs/branch-templates-single.yaml -o %t.o
// RUN: llvm-profdata merge %S/Inputs/branch-templates-single.proftext -o %t.profdata
// RUN: llvm-cov show --show-expansions --show-branches=count %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs | FileCheck %S/Inputs/branch-templates.cpp

template<typename T>
int func(T x) {
if(x) // CHECK: | Branch ([[@LINE]]:6): [True: 0, False: 1]
return 0; // CHECK: | Branch ([[@LINE-1]]:6): [True: 1, False: 0]
else // CHECK: | Branch ([[@LINE-2]]:6): [True: 0, False: 1]
return 1;
int j = 1;
}

// CHECK-LABEL: _Z4funcIiEiT_:
// CHECK: | | Branch ([[@LINE-8]]:6): [True: 0, False: 1]
// CHECK-LABEL: _Z4funcIbEiT_:
// CHECK: | | Branch ([[@LINE-10]]:6): [True: 1, False: 0]
// CHECK-LABEL: _Z4funcIfEiT_:
// CHECK: | | Branch ([[@LINE-12]]:6): [True: 0, False: 1]

extern "C" { extern void __llvm_profile_write_file(void); }
int main() {
if (func<int>(0)) // CHECK: | Branch ([[@LINE]]:7): [True: 1, False: 0]
printf("case1\n");
if (func<bool>(true)) // CHECK: | Branch ([[@LINE]]:7): [True: 0, False: 1]
printf("case2\n");
if (func<float>(0.0)) // CHECK: | Branch ([[@LINE]]:7): [True: 1, False: 0]
printf("case3\n");
__llvm_profile_write_file();
return 0;
}

// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// REPORT-NEXT: ---
// REPORT-NEXT: main 7 1 85.71% 10 1 90.00% 6 3 50.00%
// REPORT-NEXT: _Z4funcIiEiT_ 5 2 60.00% 7 3 57.14% 2 1 50.00%
Expand All @@ -54,8 +24,8 @@ int main() {
// respectively). This is returned by: FunctionCoverageSummary::get(const
// InstantiationGroup &Group, ...)

// REPORTFILE: Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover
// REPORTFILE: Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover
// REPORTFILE-NEXT: ---
// REPORTFILE-NEXT: branch-templates.cpp 12 3 75.00% 2 0 100.00% 17 4 76.47% 8 4 50.00%
// REPORTFILE-NEXT: ---
// REPORTFILE-NEXT: TOTAL 12 3 75.00% 2 0 100.00% 17 4 76.47% 8 4 50.00%
// REPORTFILE-NEXT: TOTAL 12 3 75.00% 2 0 100.00% 17 4 76.47% 8 4 50.00%
73 changes: 0 additions & 73 deletions llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp

This file was deleted.

50 changes: 50 additions & 0 deletions llvm/test/tools/llvm-cov/showLineExecutionCounts.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Basic handling of line counts.
// RUN: rm -rf %t*.dir
// RUN: llvm-profdata merge %S/Inputs/lineExecutionCounts.proftext -o %t.profdata

// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck -check-prefixes=TEXT,WHOLE-FILE %S/Inputs/showLineExecutionCounts.cpp
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main | FileCheck -check-prefixes=TEXT,FILTER %S/Inputs/showLineExecutionCounts.cpp

// Test -output-dir.
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -o %t.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -output-dir %t.filtered.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main
// RUN: FileCheck -check-prefixes=TEXT,WHOLE-FILE -input-file %t.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %S/Inputs/showLineExecutionCounts.cpp
// RUN: FileCheck -check-prefixes=TEXT,FILTER -input-file %t.filtered.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %S/Inputs/showLineExecutionCounts.cpp
//
// RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata 2>/dev/null -summary-only > %t.export-summary.json
// RUN: not grep '"name":"main"' %t.export-summary.json
//
// Test html output.
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.html.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.html.filtered.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main
// RUN: FileCheck -check-prefixes=HTML,HTML-WHOLE-FILE -input-file %t.html.dir/coverage/tmp/showLineExecutionCounts.cpp.html %S/Inputs/showLineExecutionCounts.cpp
// RUN: FileCheck -check-prefixes=HTML,HTML-FILTER -input-file %t.html.filtered.dir/coverage/tmp/showLineExecutionCounts.cpp.html %S/Inputs/showLineExecutionCounts.cpp
//
// Test index creation.
// RUN: FileCheck -check-prefix=TEXT-INDEX -input-file %t.dir/index.txt %s
// TEXT-INDEX: Filename
// TEXT-INDEX-NEXT: ---
// TEXT-INDEX-NEXT: {{.*}}showLineExecutionCounts.cpp
//
// RUN: FileCheck -check-prefix HTML-INDEX -input-file %t.html.dir/index.html %s
// HTML-INDEX-LABEL: <table>
// HTML-INDEX: <td class='column-entry-bold'>Filename</td>
// HTML-INDEX: <td class='column-entry-bold'>Function Coverage</td>
// HTML-INDEX: <td class='column-entry-bold'>Line Coverage</td>
// HTML-INDEX: <td class='column-entry-bold'>Region Coverage</td>
// HTML-INDEX: <a href='coverage{{.*}}showLineExecutionCounts.cpp.html'{{.*}}showLineExecutionCounts.cpp</a>
// HTML-INDEX: <td class='column-entry-green'>
// HTML-INDEX: 100.00% (1/1)
// HTML-INDEX: <td class='column-entry-yellow'>
// HTML-INDEX: 90.00% (18/20)
// HTML-INDEX: <td class='column-entry-red'>
// HTML-INDEX: 72.73% (8/11)
// HTML-INDEX: <tr class='light-row-bold'>
// HTML-INDEX: Totals

// Single byte
// RUN: yaml2obj %S/Inputs/showLineExecutionCounts-single.yaml -o %t.o
// RUN: llvm-profdata merge %S/Inputs/showLineExecutionCounts-single.proftext -o %t.profdata

// RUN: llvm-cov show %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs | FileCheck -check-prefixes=TEXT,WHOLE-FILE %S/Inputs/showLineExecutionCounts.cpp
// RUN: llvm-cov show %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs -name=main | FileCheck -check-prefixes=TEXT,FILTER %S/Inputs/showLineExecutionCounts.cpp