Skip to content

Commit abd8d93

Browse files
authored
Merge pull request #12202 from rintaro/crasher-crasher-28843
[Parse] Fix crash case in parseStmtForeach
2 parents 0f73f98 + cd3bf03 commit abd8d93

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,15 +1770,17 @@ static bool isStmtForCStyle(Parser &P) {
17701770
auto HasLParen = P.consumeIf(tok::l_paren);
17711771

17721772
// Skip until we see ';', or something that ends control part.
1773-
while (P.Tok.isNot(tok::eof, tok::kw_in, tok::semi, tok::l_brace,
1774-
tok::r_brace, tok::r_paren) && !P.isStartOfStmt()) {
1773+
while (true) {
1774+
if (P.Tok.isAny(tok::eof, tok::kw_in, tok::l_brace, tok::r_brace,
1775+
tok::r_paren) || P.isStartOfStmt())
1776+
return false;
17751777
// If we saw newline before ';', consider it is a foreach statement.
17761778
if (!HasLParen && P.Tok.isAtStartOfLine())
17771779
return false;
1780+
if (P.Tok.is(tok::semi))
1781+
return true;
17781782
P.skipSingle();
17791783
}
1780-
1781-
return P.Tok.is(tok::semi);
17821784
}
17831785

17841786
///

test/Parse/recovery.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ func missingControllingExprInForEach() {
224224
let key = "\(name)"
225225
}
226226
}
227+
228+
for // expected-error {{expected pattern}} expected-error {{Sequence expression for for-each loop}}
229+
; // expected-error {{expected '{' to start the body of for-each loop}}
227230
}
228231

229232
func missingControllingExprInSwitch() {

validation-test/compiler_crashers/28843-startofcontrol-tok-getloc.swift renamed to validation-test/compiler_crashers_fixed/28843-startofcontrol-tok-getloc.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +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-
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
109
{for
1110
;

0 commit comments

Comments
 (0)