Index: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp =================================================================== --- llvm/lib/ProfileData/Coverage/CoverageMapping.cpp +++ llvm/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -288,10 +288,23 @@ StringRef Arch = Arches.empty() ? StringRef() : Arches[File.index()]; auto CoverageReaderOrErr = BinaryCoverageReader::create(CovMappingBufOrErr.get(), Arch); - if (Error E = CoverageReaderOrErr.takeError()) - return std::move(E); - Readers.push_back(std::move(CoverageReaderOrErr.get())); - Buffers.push_back(std::move(CovMappingBufOrErr.get())); + if (Error E = CoverageReaderOrErr.takeError()) { + E = handleErrors(std::move(E), + [&](std::unique_ptr CME) -> Error { + if (CME->get() == coveragemap_error::no_data_found) + return Error::success(); + return Error(std::move(CME)); + }); + if (E) { + return std::move(E); + } + } else { + Readers.push_back(std::move(CoverageReaderOrErr.get())); + Buffers.push_back(std::move(CovMappingBufOrErr.get())); + } + } + if (Readers.empty()) { + return make_error(coveragemap_error::no_data_found); } return load(Readers, *ProfileReader); } Index: llvm/test/tools/llvm-cov/Inputs/empty_object/empty_object.cc =================================================================== --- /dev/null +++ llvm/test/tools/llvm-cov/Inputs/empty_object/empty_object.cc @@ -0,0 +1 @@ +const int foo = 1; Index: llvm/test/tools/llvm-cov/Inputs/empty_object/main.cc =================================================================== --- /dev/null +++ llvm/test/tools/llvm-cov/Inputs/empty_object/main.cc @@ -0,0 +1 @@ +int main() {} Index: llvm/test/tools/llvm-cov/empty_object.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-cov/empty_object.test @@ -0,0 +1,20 @@ +RUN: clang -std=c++11 -mllvm -enable-name-compression=false -fprofile-instr-generate -fcoverage-mapping %S/Inputs/empty_object/empty_object.cc -c -o %t.o + +It shouldn't fail if other valid object is provided. +RUN: llvm-cov report -instr-profile %S/Inputs/empty_object/merged.profdata \ +RUN: -object %S/Inputs/empty_object/main.covmapping \ +RUN: -object %t.o | FileCheck -check-prefix=REPORT %s + +REPORT: main.cc + +It should still fail if no other valid object is provided. +RUN: (! llvm-cov report -instr-profile %S/Inputs/empty_object/merged.profdata \ +RUN: -object %t.o) 2>&1 | FileCheck -check-prefix=FAIL %s +FAIL: No coverage data found + +Instructions for regenerating the test: + +clang -std=c++11 -mllvm -enable-name-compression=false -fprofile-instr-generate -fcoverage-mapping main.cc -o main +LLVM_PROFILE_FILE="main.raw" ./main +llvm-profdata merge main.raw -o merged.profdata +llvm-cov convert-for-testing ./main -o ./main.covmapping