#include "llvm/ADT/SmallSet.h"
#include "llvm/ProfileData/CoverageMappingReader.h"
#include "llvm/ProfileData/InstrProfReader.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
using namespace coverage;
+#define DEBUG_TYPE "coverage-mapping"
+
CounterExpressionBuilder::CounterExpressionBuilder(unsigned NumCounterValues) {
Terms.resize(NumCounterValues);
}
/// Start a segment with no count specified.
void startSegment(unsigned Line, unsigned Col) {
+ DEBUG(dbgs() << "Top level segment at " << Line << ":" << Col << "\n");
Segments.emplace_back(Line, Col, /*IsRegionEntry=*/false);
}
Segments.emplace_back(Line, Col, IsRegionEntry);
S = Segments.back();
}
+ DEBUG(dbgs() << "Segment at " << Line << ":" << Col);
// Set this region's count.
- if (Region.Kind != coverage::CounterMappingRegion::SkippedRegion)
+ if (Region.Kind != coverage::CounterMappingRegion::SkippedRegion) {
+ DEBUG(dbgs() << " with count " << Region.ExecutionCount);
Segments.back().setCount(Region.ExecutionCount);
+ }
+ DEBUG(dbgs() << "\n");
}
/// Start a segment for the given region.
while (!ActiveRegions.empty() &&
ActiveRegions.back()->endLoc() <= Region.startLoc())
popRegion();
- // Add this region to the stack.
- ActiveRegions.push_back(&Region);
- startSegment(Region);
+ if (Segments.size() && Segments.back().Line == Region.LineStart &&
+ Segments.back().Col == Region.ColumnStart) {
+ if (Region.Kind != coverage::CounterMappingRegion::SkippedRegion)
+ Segments.back().addCount(Region.ExecutionCount);
+ } else {
+ // Add this region to the stack.
+ ActiveRegions.push_back(&Region);
+ startSegment(Region);
+ }
}
// Pop any regions that are left in the stack.
while (!ActiveRegions.empty())
--- /dev/null
+// RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -no-colors -filename-equivalence %s | FileCheck -check-prefix=CHECK -check-prefix=ALL %s
+// RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -no-colors -filename-equivalence -name=_Z4funcIbEiT_ %s | FileCheck -check-prefix=CHECK -check-prefix=FILTER %s
+
+// before coverage // WHOLE-FILE: | [[@LINE]]|// before
+ // FILTER-NOT: | [[@LINE-1]]|// before
+template<typename T> // ALL: | [[@LINE]]|template<typename T>
+int func(T x) { // ALL-NEXT: 2| [[@LINE]]|int func(T x) {
+ if(x) // ALL-NEXT: 2| [[@LINE]]| if(x)
+ return 0; // ALL-NEXT: 1| [[@LINE]]| return 0;
+ else // ALL-NEXT: 1| [[@LINE]]| else
+ return 1; // ALL-NEXT: 1| [[@LINE]]| return 1;
+ int j = 1; // ALL-NEXT: 0| [[@LINE]]| int j = 1;
+} // ALL-NEXT: 1| [[@LINE]]|}
+
+ // CHECK: {{^ *(\| )?}}_Z4funcIbEiT_:
+ // CHECK-NEXT: 1| [[@LINE-9]]|int func(T x) {
+ // CHECK-NEXT: 1| [[@LINE-9]]| if(x)
+ // CHECK-NEXT: 1| [[@LINE-9]]| return 0;
+ // CHECK-NEXT: 1| [[@LINE-9]]| else
+ // CHECK-NEXT: 0| [[@LINE-9]]| return 1;
+ // CHECK-NEXT: 0| [[@LINE-9]]| int j = 1;
+ // CHECK-NEXT: 1| [[@LINE-9]]|}
+
+ // ALL: {{^ *}}| _Z4funcIiEiT_:
+ // FILTER-NOT: {{^ *(\| )?}} _Z4funcIiEiT_:
+ // ALL-NEXT: 1| [[@LINE-19]]|int func(T x) {
+ // ALL-NEXT: 1| [[@LINE-19]]| if(x)
+ // ALL-NEXT: 0| [[@LINE-19]]| return 0;
+ // ALL-NEXT: 1| [[@LINE-19]]| else
+ // ALL-NEXT: 1| [[@LINE-19]]| return 1;
+ // ALL-NEXT: 0| [[@LINE-19]]| int j = 1;
+ // ALL-NEXT: 1| [[@LINE-19]]|}
+
+int main() { // ALL: 1| [[@LINE]]|int main() {
+ func<int>(0); // ALL-NEXT: 1| [[@LINE]]| func<int>(0);
+ func<bool>(true); // ALL-NEXT: 1| [[@LINE]]| func<bool>(true);
+ return 0; // ALL-NEXT: 1| [[@LINE]]| return 0;
+} // ALL-NEXT: 1| [[@LINE]]|}
+// after coverage // ALL-NEXT: | [[@LINE]]|// after
+ // FILTER-NOT: | [[@LINE-1]]|// after
+
+// llvm-cov doesn't work on big endian yet
+// XFAIL: powerpc64-, s390x, mips-, mips64-, sparc