File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -6193,18 +6193,24 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
6193
6193
6194
6194
const char *LastTokTextEnd = Tok.getText ().end ();
6195
6195
6196
- // Skip over trailing whitespace and a single \n to the start of the next
6197
- // line.
6196
+ // Skip over trailing whitespace and a single \r and/or \ n to the start of the
6197
+ // next line.
6198
6198
while (*LastTokTextEnd == ' ' || *LastTokTextEnd == ' \t ' )
6199
6199
++LastTokTextEnd;
6200
- SourceLoc nextLineStartLoc = Lexer::getSourceLoc (LastTokTextEnd);
6201
-
6202
- if (*LastTokTextEnd == ' \n ' )
6203
- nextLineStartLoc = nextLineStartLoc.getAdvancedLoc (1 );
6204
- else {
6200
+ bool hadCROrLF = false ;
6201
+ if (*LastTokTextEnd == ' \r ' ) {
6202
+ hadCROrLF = true ;
6203
+ ++LastTokTextEnd;
6204
+ }
6205
+ if (*LastTokTextEnd == ' \n ' ) {
6206
+ hadCROrLF = true ;
6207
+ ++LastTokTextEnd;
6208
+ }
6209
+ if (!hadCROrLF) {
6205
6210
diagnose (Tok.getLoc (), diag::extra_tokens_line_directive);
6206
6211
return makeParserError ();
6207
6212
}
6213
+ SourceLoc nextLineStartLoc = Lexer::getSourceLoc (LastTokTextEnd);
6208
6214
6209
6215
int LineOffset =
6210
6216
StartLine - SourceMgr.getLineAndColumnInBuffer (nextLineStartLoc).first ;
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %gyb %s -o %t/line-directive-crlf.swift
3
+ // RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/line-directive-crlf.swift
4
+
5
+ // https://github.com/apple/swift/issues/57553
6
+ func I57553() {
7
+ % print("#sourceLocation(file: \"issue-57553.swift\", line: 100)\r\n")
8
+ % print("#sourceLocation()\r\n")
9
+ % print("#sourceLocation(file: \"issue-57553.swift\", line: 200)\r")
10
+ % print("#sourceLocation()\r")
11
+ % print("#sourceLocation(file: \"issue-57553.swift\", line: 300)\n")
12
+ % print("#sourceLocation()\n")
13
+ }
You can’t perform that action at this time.
0 commit comments