[PATCH] D63689: llvm-cov don't fail the entire invocation if one of the provided object doesn't contain coverage info
Chuan Qiu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 22 18:38:31 PDT 2019
eagleonhill created this revision.
eagleonhill added reviewers: vsk, JustinBorb.
eagleonhill added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.
It's common for an object to not contain any profilable function, e.g. constants only. We use relevant objects to filter the coverage instrumenation and support multi-processing.
some random non-profilable object could fail the entire invocation.
This will make llvm-cov ignore if any objects is empty, however it still fail if all of the provided objects are empty.
https://reviews.llvm.org/D63689
Files:
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/test/tools/llvm-cov/Inputs/empty_object/empty_object.cc
llvm/test/tools/llvm-cov/Inputs/empty_object/main.cc
llvm/test/tools/llvm-cov/Inputs/empty_object/main.covmapping
llvm/test/tools/llvm-cov/Inputs/empty_object/merged.profdata
llvm/test/tools/llvm-cov/empty_object.test
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
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/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/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<CoverageMapError> 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<CoverageMapError>(coveragemap_error::no_data_found);
}
return load(Readers, *ProfileReader);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63689.206129.patch
Type: text/x-patch
Size: 3014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190623/b1d3de89/attachment.bin>
More information about the llvm-commits
mailing list