llvm/llvm/test/tools/llvm-cov/mcdc-maxbs.test

# Test not to trigger the assertion failure in llvm-cov with empty bitmap.
# REQUIRES: asserts

# mcdc-maxbs.o contains the record:
#
# sub:
#   Decision,File 0, 5:11 -> 5:59 = M:1, C:4
#   Branch,File 0, 5:12 -> 5:20 = #5, ((#0 - #1) - #5) [1,3,2]
#   Branch,File 0, 5:24 -> 5:32 = #6, (#5 - #6) [3,0,2]
#   Branch,File 0, 5:38 -> 5:46 = #7, (#4 - #7) [2,4,0]
#   Branch,File 0, 5:50 -> 5:58 = #8, (#7 - #8) [4,0,0]
#   Decision,File 1, 1:23 -> 1:47 = M:0, C:2
#   Branch,File 1, 1:23 -> 1:33 = #2, (#0 - #2) [1,2,0]
#   Branch,File 1, 1:37 -> 1:47 = #3, (#2 - #3) [2,0,0]
#
# With the previous implementation, `Decision M:0 C:2` was picked up as
# the last `Decision`.
# The size of the bitmap was reported as `1` in this case.
# Actually, the largest `Decision` is `M:1 C:4` and the size should be `3`
# (Idx=1, len=16 bits).
#
# When a corresponding bitmap was not emitted, the dummy zero-ed bitmap is
# allocated as `BitmapBytes` with `getMaxBitmapSize(Record) + 1`
# (in this case, `1 + 1`, less than `3`).
# It may overrun and would trigger `unexpected test vector`
# by trailing uninitialized garbage.

# RUN: llvm-profdata merge %S/Inputs/mcdc-maxbs.proftext -o %t.profdata
# RUN: llvm-cov report --show-mcdc-summary %S/Inputs/mcdc-maxbs.o -instr-profile %t.profdata

# Instructions for regenerating the test object:

cd %S/Inputs # or copy %S/Inputs/mcdc-maxbs.c into the working directory

clang -Os -fcoverage-mcdc -fprofile-instr-generate \
    -fcoverage-mapping -fcoverage-compilation-dir=. \
    -mllvm -enable-name-compression=false \
    mcdc-maxbs.c -c -o mcdc-maxbs.o

# Instructions for regenerating the test vector:

clang -fprofile-instr-generate mcdc-maxbs.o
rm -f default.prof*

# Doesn't crash if argc > 1
./a.out

llvm-profdata merge --sparse -o default.profdata default.profraw
llvm-profdata merge --text -o mcdc-maxbs.proftext default.profdata