[DebugInfo] Avoid applying a misleading cleanup loc in case blocks

Switch cases without a trailing curly brace have ambiguous cleanup
locations. Here's what the current stepping behavior looks like:

  switch x {
    case ...:
      if true { foo() } // Step
      else    { bar() } // Step
  }

The second step can be misleading, because users might think that the
else branch is taken.

rdar://35628620
This commit is contained in:
Vedant Kumar
2018-01-12 16:04:08 -08:00
committed by Vedant Kumar
parent 810505b759
commit b27ed065b6
2 changed files with 19 additions and 2 deletions

View File

@@ -2317,7 +2317,13 @@ void PatternMatchEmission::emitCaseBody(CaseStmt *caseBlock) {
// Implicitly break out of the pattern match statement.
if (SGF.B.hasValidInsertionPoint()) {
SGF.emitBreakOutOf(CleanupLocation(caseBlock), PatternMatchStmt);
// Case blocks without trailing braces have ambiguous cleanup locations.
SILLocation cleanupLoc = getCompilerGeneratedLocation();
if (auto *braces = dyn_cast<BraceStmt>(caseBlock->getBody()))
if (braces->getNumElements() == 1 &&
dyn_cast_or_null<DoStmt>(braces->getElement(0).dyn_cast<Stmt *>()))
cleanupLoc = CleanupLocation(caseBlock);
SGF.emitBreakOutOf(cleanupLoc, PatternMatchStmt);
}
}