Commit 7ac416ca authored by jgruber's avatar jgruber Committed by Commit Bot

[coverage] Ensure that closing braces of functions are never uncovered

Consider:

function f() {
  return;
}

This CL ensures that the closing brace is considered as covered by
introducing a special case for open-ended range rewrites when the
parent range is the function range itself.

Bug: v8:6000, v8:6661
Change-Id: I0be307759967e9f4df245a4f367326a37dda86fd
Reviewed-on: https://chromium-review.googlesource.com/597651Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47079}
parent 6fde541d
......@@ -184,6 +184,10 @@ class CoverageBlockIterator final {
return GetNextBlock();
}
// A range is considered to be at top level if its parent range is the
// function range.
bool IsTopLevel() const { return nesting_stack_.size() == 1; }
void DeleteBlock() {
DCHECK(!delete_current_);
DCHECK(IsActive());
......@@ -256,8 +260,16 @@ void RewritePositionSingletonsToRanges(CoverageFunction* function) {
} else if (block.end == kNoSourcePosition) {
// The current block ends at the next sibling block (if it exists) or the
// end of the parent block otherwise.
block.end = iter.HasSiblingOrChild() ? iter.GetSiblingOrChild().start
: parent.end;
if (iter.HasSiblingOrChild()) {
block.end = iter.GetSiblingOrChild().start;
} else if (iter.IsTopLevel()) {
// See https://crbug.com/v8/6661. Functions are special-cased because
// we never want the closing brace to be uncovered. This is mainly to
// avoid a noisy UI.
block.end = parent.end - 1;
} else {
block.end = parent.end;
}
}
}
}
......
......@@ -82,7 +82,7 @@ Running test: testPreciseCountCoverage
}
[3] : {
count : 0
endOffset : 73
endOffset : 72
startOffset : 71
}
]
......@@ -109,7 +109,7 @@ Running test: testPreciseCountCoverage
}
[1] : {
count : 0
endOffset : 208
endOffset : 207
startOffset : 206
}
]
......@@ -195,7 +195,7 @@ Running test: testPreciseCountCoverageIncremental
}
[3] : {
count : 0
endOffset : 73
endOffset : 72
startOffset : 71
}
]
......@@ -222,7 +222,7 @@ Running test: testPreciseCountCoverageIncremental
}
[1] : {
count : 0
endOffset : 208
endOffset : 207
startOffset : 206
}
]
......@@ -289,7 +289,7 @@ Running test: testPreciseCountCoverageIncremental
}
[3] : {
count : 0
endOffset : 73
endOffset : 72
startOffset : 71
}
]
......@@ -310,7 +310,7 @@ Running test: testPreciseCountCoverageIncremental
}
[2] : {
count : 0
endOffset : 175
endOffset : 174
startOffset : 173
}
]
......@@ -855,7 +855,7 @@ Running test: testPreciseBinaryCoverage
}
[3] : {
count : 0
endOffset : 73
endOffset : 72
startOffset : 71
}
]
......@@ -882,7 +882,7 @@ Running test: testPreciseBinaryCoverage
}
[1] : {
count : 0
endOffset : 208
endOffset : 207
startOffset : 206
}
]
......@@ -960,7 +960,7 @@ Running test: testPreciseBinaryCoverage
}
[1] : {
count : 0
endOffset : 175
endOffset : 174
startOffset : 173
}
]
......@@ -1053,7 +1053,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 224
endOffset : 223
startOffset : 222
}
]
......@@ -1069,7 +1069,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 176
endOffset : 175
startOffset : 172
}
]
......@@ -1085,7 +1085,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 172
endOffset : 171
startOffset : 166
}
]
......@@ -1101,7 +1101,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 166
endOffset : 165
startOffset : 158
}
]
......@@ -1152,7 +1152,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 172
endOffset : 171
startOffset : 166
}
]
......
......@@ -82,7 +82,7 @@ Running test: testPreciseCountCoverage
}
[3] : {
count : 0
endOffset : 73
endOffset : 72
startOffset : 71
}
]
......@@ -109,7 +109,7 @@ Running test: testPreciseCountCoverage
}
[1] : {
count : 0
endOffset : 208
endOffset : 207
startOffset : 206
}
]
......@@ -644,7 +644,7 @@ Running test: testPreciseBinaryCoverage
}
[3] : {
count : 0
endOffset : 73
endOffset : 72
startOffset : 71
}
]
......@@ -671,7 +671,7 @@ Running test: testPreciseBinaryCoverage
}
[1] : {
count : 0
endOffset : 208
endOffset : 207
startOffset : 206
}
]
......@@ -749,7 +749,7 @@ Running test: testPreciseBinaryCoverage
}
[1] : {
count : 0
endOffset : 175
endOffset : 174
startOffset : 173
}
]
......@@ -842,7 +842,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 224
endOffset : 223
startOffset : 222
}
]
......@@ -858,7 +858,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 176
endOffset : 175
startOffset : 172
}
]
......@@ -874,7 +874,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 172
endOffset : 171
startOffset : 166
}
]
......@@ -890,7 +890,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 166
endOffset : 165
startOffset : 158
}
]
......@@ -941,7 +941,7 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
count : 0
endOffset : 172
endOffset : 171
startOffset : 166
}
]
......
......@@ -18,7 +18,7 @@ f(); f(); f(); f(); f(); f(); // 0150
`,
[{"start":0,"end":199,"count":1},
{"start":0,"end":33,"count":4}, // TODO(jgruber): Invocation count is off.
{"start":25,"end":33,"count":16},
{"start":25,"end":32,"count":16},
{"start":50,"end":76,"count":2}] // TODO(jgruber): Invocation count is off.
);
......@@ -40,7 +40,7 @@ TestCoverage("Partial coverage collection",
}(); // 0400
`,
[{"start":52,"end":153,"count":0},
{"start":127,"end":153,"count":1}]
{"start":127,"end":152,"count":1}]
);
%DebugToggleBlockCoverage(false);
......@@ -69,7 +69,7 @@ TestCoverage(
`,
[{"start":0,"end":399,"count":1},
{"start":1,"end":351,"count":1},
{"start":161,"end":351,"count":0}]
{"start":161,"end":350,"count":0}]
);
TestCoverage(
......@@ -178,7 +178,7 @@ TestCoverage(
{"start":81,"end":253,"count":10},
{"start":163,"end":253,"count":0},
{"start":460,"end":553,"count":0},
{"start":761,"end":951,"count":0}]
{"start":761,"end":950,"count":0}]
);
TestCoverage(
......@@ -216,7 +216,7 @@ TestCoverage(
[{"start":0,"end":299,"count":1},
{"start":1,"end":201,"count":6}, // TODO(jgruber): Invocation count is off.
{"start":83,"end":153,"count":4},
{"start":153,"end":201,"count":1}]
{"start":153,"end":200,"count":1}]
);
TestCoverage(
......@@ -278,7 +278,7 @@ TestCoverage(
{"start":117,"end":303,"count":10},
{"start":213,"end":303,"count":0},
{"start":510,"end":603,"count":0},
{"start":811,"end":1001,"count":0}]
{"start":811,"end":1000,"count":0}]
);
TestCoverage(
......@@ -311,7 +311,7 @@ TestCoverage(
{"start":105,"end":303,"count":10},
{"start":213,"end":303,"count":0},
{"start":510,"end":603,"count":0},
{"start":811,"end":1001,"count":0}]
{"start":811,"end":1000,"count":0}]
);
TestCoverage(
......@@ -323,9 +323,9 @@ TestCoverage(
`,
[{"start":0,"end":149,"count":1},
{"start":1,"end":37,"count":1},
{"start":28,"end":37,"count":0},
{"start":28,"end":36,"count":0},
{"start":51,"end":122,"count":1},
{"start":81,"end":122,"count":0}]
{"start":81,"end":121,"count":0}]
);
TestCoverage(
......@@ -374,10 +374,10 @@ TestCoverage("try/catch/finally statements with early return",
[{"start":0,"end":449,"count":1},
{"start":1,"end":151,"count":1},
{"start":67,"end":70,"count":0},
{"start":89,"end":151,"count":0},
{"start":89,"end":150,"count":0},
{"start":201,"end":401,"count":1},
{"start":267,"end":270,"count":0},
{"start":319,"end":401,"count":0}]
{"start":319,"end":400,"count":0}]
);
TestCoverage(
......@@ -409,15 +409,15 @@ TestCoverage(
[{"start":0,"end":1099,"count":1},
{"start":1,"end":151,"count":1},
{"start":67,"end":70,"count":0},
{"start":89,"end":151,"count":0},
{"start":89,"end":150,"count":0},
{"start":201,"end":351,"count":1},
{"start":284,"end":351,"count":0},
{"start":284,"end":350,"count":0},
{"start":401,"end":701,"count":1},
{"start":569,"end":701,"count":0},
{"start":569,"end":700,"count":0},
{"start":561,"end":568,"count":0}, // TODO(jgruber): Sorting.
{"start":751,"end":1051,"count":1},
{"start":817,"end":820,"count":0},
{"start":861,"end":1051,"count":0}]
{"start":861,"end":1050,"count":0}]
);
TestCoverage(
......@@ -550,7 +550,7 @@ it.next(); it.next(); // 0250
{"start":64,"end":116,"count":1},
{"start":116,"end":121,"count":0},
{"start":124,"end":129,"count":1},
{"start":129,"end":201,"count":0}]
{"start":129,"end":200,"count":0}]
);
TestCoverage(
......@@ -569,9 +569,9 @@ try { // 0200
`,
[{"start":0,"end":499,"count":1},
{"start":12,"end":101,"count":3},
{"start":60,"end":101,"count":0},
{"start":60,"end":100,"count":0},
{"start":264,"end":353,"count":3},
{"start":312,"end":353,"count":0}]
{"start":312,"end":352,"count":0}]
);
TestCoverage("yield expressions (.return and try/catch/finally)",
......@@ -590,7 +590,7 @@ it.next(); it.return(); // 0450
{"start":11,"end":351,"count":3},
{"start":112,"end":254,"count":0},
{"start":254,"end":272,"count":1},
{"start":272,"end":351,"count":0}]
{"start":272,"end":350,"count":0}]
);
TestCoverage("yield expressions (.throw and try/catch/finally)",
......@@ -609,7 +609,7 @@ it.next(); it.throw(42); // 0550
{"start":11,"end":351,"count":3},
{"start":112,"end":154,"count":0},
{"start":154,"end":310,"count":1},
{"start":310,"end":351,"count":0}]
{"start":310,"end":350,"count":0}]
);
TestCoverage(
......@@ -628,7 +628,7 @@ it.next(); it.next(); it.next(); // 0300
{"start":65,"end":117,"count":1},
{"start":117,"end":122,"count":0},
{"start":125,"end":130,"count":1},
{"start":130,"end":201,"count":0}]
{"start":130,"end":200,"count":0}]
);
TestCoverage(
......@@ -647,9 +647,9 @@ try { // 0200
`,
[{"start":0,"end":499,"count":1},
{"start":12,"end":101,"count":3},
{"start":65,"end":101,"count":0},
{"start":65,"end":100,"count":0},
{"start":264,"end":353,"count":3},
{"start":317,"end":353,"count":0}]
{"start":317,"end":352,"count":0}]
);
TestCoverage(
......@@ -664,7 +664,7 @@ f(); // 0200
`,
[{"start":0,"end":299,"count":1},
{"start":0,"end":151,"count":3},
{"start":61,"end":151,"count":1}]
{"start":61,"end":150,"count":1}]
);
%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