mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Profiler] Avoid introducing empty unreachable regions
When computing the counter for the region following a labeled statement such as `if`, avoid adding a new empty region if the counter for such a region is known to be zero, i.e unreachable. This avoids adding spurious unreachable regions after an if statements where each branch returns, throws, or otherwise jumps to a parent statement. We will however still add the region if any code follows such a statement, making it non-empty. rdar://29390569
This commit is contained in:
@@ -814,7 +814,17 @@ private:
|
||||
if (ControlFlowAdjust)
|
||||
Count = &createCounter(CounterExpr::Sub(*Count, *ControlFlowAdjust));
|
||||
|
||||
RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
|
||||
if (Count->isSemanticallyZero()) {
|
||||
// If the counter is semantically zero, form an 'incomplete' region with
|
||||
// no starting location. This prevents forming unreachable regions unless
|
||||
// there is a following statement or expression to extend the region.
|
||||
RegionStack.emplace_back(ASTNode(), *Count, None, None);
|
||||
} else {
|
||||
// Otherwise, we have a non-zero counter, so form a new region starting
|
||||
// at the end of the previous scope. This ensures the user covers both
|
||||
// branches of a condition.
|
||||
RegionStack.emplace_back(ASTNode(), *Count, getEndLoc(Scope), None);
|
||||
}
|
||||
}
|
||||
|
||||
/// Push a region covering \c Node onto the stack.
|
||||
|
||||
Reference in New Issue
Block a user