--- /dev/null
+// 1) Compile shared code into different object files and into an executable.
+
+// RUN: %clangxx_profgen -fcoverage-mapping %s -c -o %t.v1.o -D_VERSION_1
+// RUN: %clangxx_profgen -fcoverage-mapping %s -c -o %t.v2.o -D_VERSION_2
+// RUN: %clangxx_profgen -fcoverage-mapping %t.v1.o %t.v2.o -o %t.exe
+
+// 2) Collect profile data.
+
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.exe
+// RUN: llvm-profdata merge %t.profraw -o %t.profdata
+
+// 3) Generate coverage reports from the different object files and the exe.
+
+// RUN: llvm-cov show %t.v1.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V1-ONLY
+// RUN: llvm-cov show %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V2,V2-ONLY
+// RUN: llvm-cov show %t.v1.o -object %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2
+// RUN: llvm-cov show %t.exe -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2
+
+// 4) Verify that coverage reporting on the aggregate coverage mapping shows
+// hits for all code. (We used to arbitrarily pick a mapping from one binary
+// and prefer it over others.) When only limited coverage information is
+// available (just from one binary), don't try to guess any region counts.
+
+struct A {
+ A() {} // V1: [[@LINE]]{{ *}}|{{ *}}1
+ // V1-ONLY: [[@LINE+1]]{{ *}}|{{ *}}|
+ A(int) {} // V2-ONLY: [[@LINE-2]]{{ *}}|{{ *}}|
+ // V2: [[@LINE-1]]{{ *}}|{{ *}}1
+};
+
+#ifdef _VERSION_1
+
+void foo();
+
+void bar() {
+ A x; // V1: [[@LINE]]{{ *}}|{{ *}}1
+}
+
+int main() {
+ foo(); // V1: [[@LINE]]{{ *}}|{{ *}}1
+ bar();
+ return 0;
+}
+
+#endif // _VERSION_1
+
+#ifdef _VERSION_2
+
+void foo() {
+ A x{0}; // V2: [[@LINE]]{{ *}}|{{ *}}1
+}
+
+#endif // _VERSION_2
else
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
- // Don't load records for (filenames, function) pairs we've already seen.
- auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
- Record.Filenames.end());
- if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
- return Error::success();
-
CounterMappingContext Ctx(Record.Expressions);
std::vector<uint64_t> Counts;
assert(!Record.MappingRegions.empty() && "Function has no regions");
+ // This coverage record is a zero region for a function that's unused in
+ // some TU, but used in a different TU. Ignore it. The coverage maps from the
+ // the other TU will either be loaded (providing full region counts) or they
+ // won't (in which case we don't unintuitively report functions as uncovered
+ // when they have non-zero counts in the profile).
+ if (Record.MappingRegions.size() == 1 &&
+ Record.MappingRegions[0].Count.isZero() && Counts[0] > 0)
+ return Error::success();
+
FunctionRecord Function(OrigFuncName, Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
Function.pushRegion(Region, *ExecutionCount);
}
+ // Don't create records for (filenames, function) pairs we've already seen.
+ auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
+ Record.Filenames.end());
+ if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
+ return Error::success();
+
Functions.push_back(std::move(Function));
return Error::success();
}