Index: llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h =================================================================== --- llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h +++ llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h @@ -527,6 +527,7 @@ /// Load the coverage mapping from the given object files and profile. If /// \p Arches is non-empty, it must specify an architecture for each object. + /// Ignores non-instrumented object files unless all are not instrumented. static Expected> load(ArrayRef ObjectFilenames, StringRef ProfileFilename, ArrayRef Arches = None); Index: llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp =================================================================== --- llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp +++ llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -270,6 +270,16 @@ return std::move(Coverage); } +// If E is a no_data_found error, returns success. Otherwise returns E. +static Error handleMaybeNoDataFoundError(Error E) { + return handleErrors( + std::move(E), [](const CoverageMapError &CME) { + if (CME.get() == coveragemap_error::no_data_found) + return static_cast(Error::success()); + return make_error(CME.get()); + }); +} + Expected> CoverageMapping::load(ArrayRef ObjectFilenames, StringRef ProfileFilename, ArrayRef Arches) { @@ -289,12 +299,21 @@ CovMappingBufOrErr.get()->getMemBufferRef(); auto CoverageReadersOrErr = BinaryCoverageReader::create(CovMappingBufRef, Arch, Buffers); - if (Error E = CoverageReadersOrErr.takeError()) - return std::move(E); + if (Error E = CoverageReadersOrErr.takeError()) { + E = handleMaybeNoDataFoundError(std::move(E)); + if (E) + return std::move(E); + // E == success (originally a no_data_found error). + continue; + } for (auto &Reader : CoverageReadersOrErr.get()) Readers.push_back(std::move(Reader)); Buffers.push_back(std::move(CovMappingBufOrErr.get())); } + // If no readers were created, either no objects were provided or none of them + // had coverage data. Return an error in the latter case. + if (Readers.empty() && !ObjectFilenames.empty()) + return make_error(coveragemap_error::no_data_found); return load(Readers, *ProfileReader); } Index: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.cc =================================================================== --- llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.cc +++ llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.cc @@ -0,0 +1,5 @@ +void f1() {} + +int main(int argc, char** argv) { + f1(); +} Index: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented.cc =================================================================== --- llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented.cc +++ llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented.cc @@ -0,0 +1 @@ +int main(int argc, char** argv) {} Index: llvm/trunk/test/tools/llvm-cov/multiple-objects-not-all-instrumented.test =================================================================== --- llvm/trunk/test/tools/llvm-cov/multiple-objects-not-all-instrumented.test +++ llvm/trunk/test/tools/llvm-cov/multiple-objects-not-all-instrumented.test @@ -0,0 +1,12 @@ +RUN: llvm-cov export --format=lcov --instr-profile=%S/Inputs/multiple_objects_not_all_instrumented/instrumented.profdata \ +RUN: -object %S/Inputs/multiple_objects_not_all_instrumented/not_instrumented \ +RUN: -object %S/Inputs/multiple_objects_not_all_instrumented/instrumented | FileCheck -check-prefix=FN %s + +FN:1,_Z2f1v + +Instructions for regenerating the test: + +clang -std=c++11 not_instrumented.cc -o not_instrumented +clang -std=c++11 -mllvm -enable-name-compression=false -fprofile-instr-generate -fcoverage-mapping instrumented.cc -o instrumented +LLVM_PROFILE_FILE="instrumented.raw" ./instrumented +llvm-profdata merge instrumented.raw -o instrumented.profdata