@@ -5620,11 +5620,13 @@ static void diagnoseOperatorFixityAttributes(Parser &P,
5620
5620
5621
5621
static unsigned skipUntilMatchingRBrace (Parser &P,
5622
5622
bool &HasPoundDirective,
5623
+ bool &HasPoundSourceLocation,
5623
5624
bool &HasOperatorDeclarations,
5624
5625
bool &HasNestedClassDeclarations,
5625
5626
bool &HasNestedTypeDeclarations,
5626
5627
bool &HasPotentialRegexLiteral) {
5627
5628
HasPoundDirective = false ;
5629
+ HasPoundSourceLocation = false ;
5628
5630
HasOperatorDeclarations = false ;
5629
5631
HasNestedClassDeclarations = false ;
5630
5632
HasNestedTypeDeclarations = false ;
@@ -5646,8 +5648,11 @@ static unsigned skipUntilMatchingRBrace(Parser &P,
5646
5648
5647
5649
HasNestedClassDeclarations |= P.Tok .is (tok::kw_class);
5648
5650
5649
- HasPoundDirective |= P.Tok .isAny (tok::pound_sourceLocation, tok::pound_line,
5650
- tok::pound_if, tok::pound_else, tok::pound_endif, tok::pound_elseif);
5651
+ HasPoundSourceLocation |= P.Tok .isAny (tok::pound_sourceLocation,
5652
+ tok::pound_line);
5653
+ HasPoundDirective |= HasPoundSourceLocation;
5654
+ HasPoundDirective |= P.Tok .isAny (tok::pound_if, tok::pound_else,
5655
+ tok::pound_endif, tok::pound_elseif);
5651
5656
5652
5657
HasNestedTypeDeclarations |= P.Tok .isAny (tok::kw_class, tok::kw_struct,
5653
5658
tok::kw_enum, tok::kw_typealias,
@@ -7085,16 +7090,22 @@ bool Parser::canDelayMemberDeclParsing(bool &HasOperatorDeclarations,
7085
7090
// we can't lazily parse.
7086
7091
CancellableBacktrackingScope BackTrack (*this );
7087
7092
bool HasPoundDirective;
7093
+ bool HasPoundSourceLocation;
7088
7094
bool HasNestedTypeDeclarations;
7089
7095
bool HasPotentialRegexLiteral;
7090
7096
skipUntilMatchingRBrace (*this ,
7091
7097
HasPoundDirective,
7098
+ HasPoundSourceLocation,
7092
7099
HasOperatorDeclarations,
7093
7100
HasNestedClassDeclarations,
7094
7101
HasNestedTypeDeclarations,
7095
7102
HasPotentialRegexLiteral);
7096
- if (!HasPoundDirective && !HasPotentialRegexLiteral)
7103
+ if (!HasPoundDirective && !HasPotentialRegexLiteral) {
7104
+ // If we didn't see any pound directive, we must not have seen
7105
+ // #sourceLocation either.
7106
+ ASSERT (!HasPoundSourceLocation);
7097
7107
BackTrack.cancelBacktrack ();
7108
+ }
7098
7109
return !BackTrack.willBacktrack ();
7099
7110
}
7100
7111
@@ -7690,17 +7701,20 @@ bool Parser::canDelayFunctionBodyParsing(bool &HasNestedTypeDeclarations) {
7690
7701
return false ;
7691
7702
7692
7703
// Skip until the matching right curly bracket; If it has a potential regex
7693
- // literal, we can't skip. We don't care others, so just ignore them;
7704
+ // literal, we can't skip. If there's a `#sourceLocation`, we also can't skip
7705
+ // since we rely on setting and restoring state in the parser. Other cases we
7706
+ // can handle.
7694
7707
CancellableBacktrackingScope BackTrack (*this );
7695
7708
consumeToken (tok::l_brace);
7696
7709
bool HasPoundDirectives;
7710
+ bool HasPoundSourceLocation;
7697
7711
bool HasOperatorDeclarations;
7698
7712
bool HasNestedClassDeclarations;
7699
7713
bool HasPotentialRegexLiteral;
7700
- skipUntilMatchingRBrace (*this , HasPoundDirectives, HasOperatorDeclarations ,
7701
- HasNestedClassDeclarations, HasNestedTypeDeclarations ,
7702
- HasPotentialRegexLiteral);
7703
- if (HasPotentialRegexLiteral)
7714
+ skipUntilMatchingRBrace (*this , HasPoundDirectives, HasPoundSourceLocation ,
7715
+ HasOperatorDeclarations, HasNestedClassDeclarations ,
7716
+ HasNestedTypeDeclarations, HasPotentialRegexLiteral);
7717
+ if (HasPoundSourceLocation || HasPotentialRegexLiteral)
7704
7718
return false ;
7705
7719
7706
7720
BackTrack.cancelBacktrack ();
0 commit comments