aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/debug/debug-coverage.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/debug/debug-coverage.cc')
-rw-r--r--deps/v8/src/debug/debug-coverage.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/deps/v8/src/debug/debug-coverage.cc b/deps/v8/src/debug/debug-coverage.cc
index a71c9e572b..f8b716f7c9 100644
--- a/deps/v8/src/debug/debug-coverage.cc
+++ b/deps/v8/src/debug/debug-coverage.cc
@@ -171,6 +171,12 @@ class CoverageBlockIterator final {
return function_->blocks[read_index_ + 1];
}
+ CoverageBlock& GetPreviousBlock() {
+ DCHECK(IsActive());
+ DCHECK_GT(read_index_, 0);
+ return function_->blocks[read_index_ - 1];
+ }
+
CoverageBlock& GetParent() {
DCHECK(IsActive());
return nesting_stack_.back();
@@ -325,6 +331,30 @@ void MergeNestedRanges(CoverageFunction* function) {
}
}
+void FilterAliasedSingletons(CoverageFunction* function) {
+ CoverageBlockIterator iter(function);
+
+ iter.Next(); // Advance once since we reference the previous block later.
+
+ while (iter.Next()) {
+ CoverageBlock& previous_block = iter.GetPreviousBlock();
+ CoverageBlock& block = iter.GetBlock();
+
+ bool is_singleton = block.end == kNoSourcePosition;
+ bool aliases_start = block.start == previous_block.start;
+
+ if (is_singleton && aliases_start) {
+ // The previous block must have a full range since duplicate singletons
+ // have already been merged.
+ DCHECK_NE(previous_block.end, kNoSourcePosition);
+ // Likewise, the next block must have another start position since
+ // singletons are sorted to the end.
+ DCHECK_IMPLIES(iter.HasNext(), iter.GetNextBlock().start != block.start);
+ iter.DeleteBlock();
+ }
+ }
+}
+
void FilterUncoveredRanges(CoverageFunction* function) {
CoverageBlockIterator iter(function);
@@ -397,6 +427,15 @@ void CollectBlockCoverage(CoverageFunction* function, SharedFunctionInfo* info,
// Remove duplicate singleton ranges, keeping the max count.
MergeDuplicateSingletons(function);
+ // Remove singleton ranges with the same start position as a full range and
+ // throw away their counts.
+ // Singleton ranges are only intended to split existing full ranges and should
+ // never expand into a full range. Consider 'if (cond) { ... } else { ... }'
+ // as a problematic example; if the then-block produces a continuation
+ // singleton, it would incorrectly expand into the else range.
+ // For more context, see https://crbug.com/v8/8237.
+ FilterAliasedSingletons(function);
+
// Rewrite all singletons (created e.g. by continuations and unconditional
// control flow) to ranges.
RewritePositionSingletonsToRanges(function);