Commit 471fef04 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[coverage] change block range to avoid ambiguity.

By moving the block range end to left of closing bracket,
we can avoid ambiguity where an open-ended singleton range
could be both interpreted as inside the parent range, or
next to it.

R=verwaest@chromium.org

Bug: v8:8237
Change-Id: Ibc9412b31efe900b6d8bff0d8fa8c52ddfbf460a
Reviewed-on: https://chromium-review.googlesource.com/1254127Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56347}
parent 4130d616
......@@ -81,6 +81,11 @@ std::vector<CoverageBlock> GetSortedBlockData(SharedFunctionInfo* shared) {
std::vector<CoverageBlock> result;
if (coverage_info->SlotCount() == 0) return result;
if (FLAG_trace_block_coverage) {
PrintF("Collecting coverage data\n");
coverage_info->Print(shared->DebugName()->ToCString());
}
for (int i = 0; i < coverage_info->SlotCount(); i++) {
const int start_pos = coverage_info->StartSourcePosition(i);
const int until_pos = coverage_info->EndSourcePosition(i);
......
......@@ -375,7 +375,7 @@ void CoverageInfo::Print(std::unique_ptr<char[]> function_name) {
for (int i = 0; i < SlotCount(); i++) {
os << "{" << StartSourcePosition(i) << "," << EndSourcePosition(i) << "}"
<< std::endl;
<< ": " << BlockCount(i) << std::endl;
}
}
......
......@@ -5093,6 +5093,7 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
Expect(Token::LBRACE, CHECK_OK_CUSTOM(NullStatement));
{
BlockState block_state(zone(), &scope_);
// Scope starts before opening brace.
scope()->set_start_position(scanner()->location().beg_pos);
typename Types::Target target(this, body);
......@@ -5104,9 +5105,10 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
}
Expect(Token::RBRACE, CHECK_OK_CUSTOM(NullStatement));
int end_pos = end_position();
scope()->set_end_position(end_pos);
impl()->RecordBlockSourceRange(body, end_pos);
// Scope ends after closing brace.
scope()->set_end_position(scanner()->location().end_pos);
// Coverage range uses position before closing brace.
impl()->RecordBlockSourceRange(body, scanner()->location().beg_pos);
body->set_scope(scope()->FinalizeBlockScope());
}
return body;
......
......@@ -471,7 +471,7 @@ TestCoverage(
{"start":472,"end":503,"count":0},
{"start":626,"end":653,"count":0},
{"start":768,"end":803,"count":0},
{"start":867,"end":869,"count":0}]
{"start":867,"end":868,"count":0}]
);
TestCoverage(
......@@ -847,7 +847,7 @@ Util.escape("foo.bar"); // 0400
[{"start":0,"end":449,"count":1},
{"start":64,"end":351,"count":1},
{"start":112,"end":203,"count":0},
{"start":303,"end":350,"count":0}]
{"start":268,"end":350,"count":0}]
);
%DebugToggleBlockCoverage(false);
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt
// Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true);
TestCoverage(
"Repro for the bug",
`
function lib (n) { // 0000
if (n >= 0) { // 0050
if (n < 0) { // 0100
return; // 0150
} // 0200
} else if (foo()) { // 0250
} // 0300
} // 0350
function foo () { // 0400
console.log('foo') // 0450
return false // 0500
} // 0550
lib(1) // 0600
`,
[{"start":0,"end":649,"count":1},
{"start":0,"end":351,"count":1},
{"start":115,"end":205,"count":0},
{"start":253,"end":303,"count":0},
{"start":400,"end":551,"count":0}]
);
TestCoverage(
"Variant with omitted brackets",
`
function lib (n) { // 0000
if (n >= 0) { // 0050
if (n < 0) // 0100
return; // 0150
} // 0200
else if (foo()); // 0250
} // 0300
function foo () { // 0350
console.log('foo') // 0400
return false // 0450
} // 0500
lib(1) // 0550
`,
[{"start":0,"end":599,"count":1},
{"start":0,"end":301,"count":1},
{"start":156,"end":163,"count":0},
{"start":203,"end":268,"count":0},
{"start":350,"end":501,"count":0}]
);
%DebugToggleBlockCoverage(false);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment