[llvm] r370257 - Ignore object files that lack coverage information.
James Y Knight via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 13:35:51 PDT 2019
Author: jyknight
Date: Wed Aug 28 13:35:50 2019
New Revision: 370257
URL: http://llvm.org/viewvc/llvm-project?rev=370257&view=rev
Log:
Ignore object files that lack coverage information.
Before this change, if multiple binary files were presented, all of them must have been instrumented or the load would fail with coverage_map_error::no_data_found.
Patch by Dean Sturtevant.
Differential Revision: https://reviews.llvm.org/D66763
Added:
llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/
llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented (with props)
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.profdata (with props)
llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.raw (with props)
llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented (with props)
llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented.cc
llvm/trunk/test/tools/llvm-cov/multiple-objects-not-all-instrumented.test
Modified:
llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp
Modified: llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h?rev=370257&r1=370256&r2=370257&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h (original)
+++ llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h Wed Aug 28 13:35:50 2019
@@ -527,6 +527,7 @@ public:
/// 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<std::unique_ptr<CoverageMapping>>
load(ArrayRef<StringRef> ObjectFilenames, StringRef ProfileFilename,
ArrayRef<StringRef> Arches = None);
Modified: llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp?rev=370257&r1=370256&r2=370257&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp Wed Aug 28 13:35:50 2019
@@ -270,6 +270,16 @@ Expected<std::unique_ptr<CoverageMapping
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>(Error::success());
+ return make_error<CoverageMapError>(CME.get());
+ });
+}
+
Expected<std::unique_ptr<CoverageMapping>>
CoverageMapping::load(ArrayRef<StringRef> ObjectFilenames,
StringRef ProfileFilename, ArrayRef<StringRef> Arches) {
@@ -289,12 +299,21 @@ CoverageMapping::load(ArrayRef<StringRef
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<CoverageMapError>(coveragemap_error::no_data_found);
return load(Readers, *ProfileReader);
}
Added: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented?rev=370257&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented
------------------------------------------------------------------------------
svn:executable = *
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.cc?rev=370257&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.cc (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.cc Wed Aug 28 13:35:50 2019
@@ -0,0 +1,5 @@
+void f1() {}
+
+int main(int argc, char** argv) {
+ f1();
+}
Added: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.profdata
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.profdata?rev=370257&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.profdata
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.raw
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.raw?rev=370257&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/instrumented.raw
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented?rev=370257&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented
------------------------------------------------------------------------------
svn:executable = *
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented.cc?rev=370257&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented.cc (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/multiple_objects_not_all_instrumented/not_instrumented.cc Wed Aug 28 13:35:50 2019
@@ -0,0 +1 @@
+int main(int argc, char** argv) {}
Added: llvm/trunk/test/tools/llvm-cov/multiple-objects-not-all-instrumented.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/multiple-objects-not-all-instrumented.test?rev=370257&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/multiple-objects-not-all-instrumented.test (added)
+++ llvm/trunk/test/tools/llvm-cov/multiple-objects-not-all-instrumented.test Wed Aug 28 13:35:50 2019
@@ -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
More information about the llvm-commits
mailing list