Skip to content

Commit 443bc68

Browse files
committed
Actually improve recovery when parsing bogus expressions
The crashes fixed appeared at first to be related to IfConfigStmt parsing, but are in reality symptoms of being too lax in what we accept when parsing of sub-expressions fail. Optional type annotation parsing used to propagate failures before it was patched to ‘recover’ with an AnyPattern. Instead, we’ll just hit the error path for parsing in the main expressions because what is here now isn’t a reasonable thing to return. #selector parsing assumed that the current token it was at after consuming up to a right-brace wasn’t bogus. Instead, if we’ve got here, we may as well just return a loc we know is valid: PreviousLoc.
1 parent d3c2875 commit 443bc68

6 files changed

+7
-7
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ ParserResult<Expr> Parser::parseExprSelector() {
661661
if (Tok.is(tok::r_paren))
662662
rParenLoc = consumeToken();
663663
else
664-
rParenLoc = Tok.getLoc();
664+
rParenLoc = PreviousLoc;
665665
} else {
666666
parseMatchingToken(tok::r_paren, rParenLoc,
667667
diag::expr_selector_expected_rparen, lParenLoc);

lib/Parse/ParsePattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,8 @@ parseOptionalPatternTypeAnnotation(ParserResult<Pattern> result,
901901
return result;
902902

903903
Pattern *P;
904-
if (result.isNull()) // Recover by creating AnyPattern.
905-
P = new (Context) AnyPattern(Tok.getLoc());
904+
if (result.isNull())
905+
return nullptr;
906906
else
907907
P = result.get();
908908

validation-test/compiler_crashers/28522-anonymous-namespace-verifier-walktostmtpost-swift-stmt.swift renamed to validation-test/compiler_crashers_fixed/28522-anonymous-namespace-verifier-walktostmtpost-swift-stmt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
let f=[.A{#if8
1010
guard let:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
(t=#selector(

validation-test/compiler_crashers/28551-anonymous-namespace-verifier-walktostmtpost-swift-stmt.swift renamed to validation-test/compiler_crashers_fixed/28551-anonymous-namespace-verifier-walktostmtpost-swift-stmt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
#if#selector(struct r
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
#if#selector(var E{unsafeAddress{

0 commit comments

Comments
 (0)