Skip to content

Commit cb249e8

Browse files
committed
SIL Parser: abort parsing a sil_global if there is an error in an initializer instruction
Otherwise the parser ends up printing errors indefinitely.
1 parent 8d789bd commit cb249e8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7432,7 +7432,8 @@ bool SILParserState::parseSILGlobal(Parser &P) {
74327432
if (State.P.consumeIf(tok::equal) && State.P.consumeIf(tok::l_brace)) {
74337433
SILBuilder B(GV);
74347434
do {
7435-
State.parseSILInstruction(B);
7435+
if (State.parseSILInstruction(B))
7436+
return true;
74367437
} while (! State.P.consumeIf(tok::r_brace));
74377438
}
74387439
return false;

test/SIL/Parser/error_in_global.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-sil-opt -inline -verify %s
2+
3+
// Check that the parser doesn't end up in an infinite error loop in case there is an error in a sil_global
4+
5+
sil_stage canonical
6+
7+
import Builtin
8+
import Swift
9+
import SwiftShims
10+
11+
sil_global @referencing_object : $Int = {
12+
%initval = struct $Int_ ()
13+
// expected-error @-1 {{cannot find type 'Int_' in scope}}
14+
}
15+

0 commit comments

Comments
 (0)