@@ -568,7 +568,8 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
568568 }
569569
570570 auto Value = getStringLiteralIfNotInterpolated (
571- AttrLoc, (" '" + ArgumentKindStr + " '" ).str ());
571+ AttrLoc, (" '" + ArgumentKindStr + " '" ).str (),
572+ /* AllowMultiline=*/ true );
572573 consumeToken ();
573574 if (!Value) {
574575 AnyArgumentInvalid = true ;
@@ -1453,7 +1454,8 @@ bool Parser::parseExternAttribute(DeclAttributes &Attributes,
14531454 return std::nullopt ;
14541455 }
14551456 llvm::Optional<StringRef> importModuleName =
1456- getStringLiteralIfNotInterpolated (Loc, (" '" + AttrName + " '" ).str ());
1457+ getStringLiteralIfNotInterpolated (Loc, (" '" + AttrName + " '" ).str (),
1458+ /* AllowMultiline=*/ false );
14571459 consumeToken (tok::string_literal);
14581460
14591461 if (!importModuleName.has_value ()) {
@@ -3233,8 +3235,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
32333235 return makeParserSuccess ();
32343236 }
32353237
3236- AsmName =
3237- getStringLiteralIfNotInterpolated ( Loc, (" '" + AttrName + " '" ).str ());
3238+ AsmName = getStringLiteralIfNotInterpolated (
3239+ Loc, (" '" + AttrName + " '" ).str (), /* AllowMultiline= */ false );
32383240
32393241 consumeToken (tok::string_literal);
32403242
@@ -3305,7 +3307,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
33053307 }
33063308
33073309 auto Name = getStringLiteralIfNotInterpolated (
3308- Loc, (" '" + AttrName + " '" ).str ());
3310+ Loc, (" '" + AttrName + " '" ).str (), /* AllowMultiline= */ false );
33093311
33103312 consumeToken (tok::string_literal);
33113313
@@ -3392,7 +3394,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
33923394 }
33933395
33943396 auto Value = getStringLiteralIfNotInterpolated (
3395- Loc, (" '" + AttrName + " '" ).str ());
3397+ Loc, (" '" + AttrName + " '" ).str (), /* AllowMultiline= */ false );
33963398
33973399 consumeToken (tok::string_literal);
33983400
@@ -3455,8 +3457,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
34553457 // Parse the next string literal as the original module name.
34563458 auto ModuleNameLoc = Tok.getLoc ();
34573459 if (Tok.is (tok::string_literal)) {
3458- auto NameOp = getStringLiteralIfNotInterpolated (Tok. getLoc (),
3459- " original module name" );
3460+ auto NameOp = getStringLiteralIfNotInterpolated (
3461+ Tok. getLoc (), " original module name" , /* AllowMultiline= */ false );
34603462 if (NameOp.has_value ())
34613463 OriginalModuleName = *NameOp;
34623464 consumeToken ();
@@ -3545,7 +3547,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
35453547 diagnose (ColonLoc, diag::attr_private_import_expected_sourcefile_name);
35463548 return makeParserSuccess ();
35473549 }
3548- filename = getStringLiteralIfNotInterpolated (Loc, " _private" );
3550+ filename = getStringLiteralIfNotInterpolated (Loc, " _private" ,
3551+ /* AllowMultiline=*/ false );
35493552 if (!filename.has_value ()) {
35503553 diagnose (ColonLoc, diag::attr_private_import_expected_sourcefile_name);
35513554 return makeParserSuccess ();
@@ -3818,8 +3821,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
38183821 return makeParserSuccess ();
38193822 }
38203823
3821- llvm::Optional<StringRef> value =
3822- getStringLiteralIfNotInterpolated ( Tok.getLoc (), flag);
3824+ llvm::Optional<StringRef> value = getStringLiteralIfNotInterpolated (
3825+ Tok.getLoc (), flag, /* AllowMultiline= */ false );
38233826 if (!value)
38243827 return makeParserSuccess ();
38253828 Token stringTok = Tok;
@@ -4533,7 +4536,8 @@ bool Parser::parseConventionAttributeInternal(SourceLoc atLoc, SourceLoc attrLoc
45334536 diagnose (Tok, diag::convention_attribute_ctype_expected_string);
45344537 return true ;
45354538 }
4536- if (auto ty = getStringLiteralIfNotInterpolated (Tok.getLoc (), " (C type)" )) {
4539+ if (auto ty = getStringLiteralIfNotInterpolated (Tok.getLoc (), " (C type)" ,
4540+ /* AllowMultiline=*/ false )) {
45374541 cType = Located<StringRef>(ty.value (), Tok.getLoc ());
45384542 }
45394543 consumeToken (tok::string_literal);
@@ -7167,8 +7171,8 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
71677171 return makeParserError ();
71687172 }
71697173
7170- Filename =
7171- getStringLiteralIfNotInterpolated (Loc, " '#sourceLocation' " );
7174+ Filename = getStringLiteralIfNotInterpolated (Loc, " '#sourceLocation' " ,
7175+ /* AllowMultiline= */ false );
71727176 if (!Filename.has_value ())
71737177 return makeParserError ();
71747178 SourceLoc filenameLoc = consumeToken (tok::string_literal);
@@ -7186,6 +7190,11 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
71867190 }
71877191 SmallString<16 > buffer;
71887192 auto text = stripUnderscoresIfNeeded (Tok.getText (), buffer);
7193+ if (text.find_first_not_of (" 0123456789" ) != StringRef::npos) {
7194+ // Disallow non-decimal line numbers in Swift 6.
7195+ diagnose (Tok, diag::expected_line_directive_number)
7196+ .warnUntilSwiftVersion (6 );
7197+ }
71897198 if (text.getAsInteger (0 , StartLine)) {
71907199 diagnose (Tok, diag::expected_line_directive_number);
71917200 return makeParserError ();
@@ -7233,8 +7242,9 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
72337242 diagnose (Tok, diag::expected_line_directive_name);
72347243 return makeParserError ();
72357244 }
7236-
7237- Filename = getStringLiteralIfNotInterpolated (Loc, " '#line'" );
7245+
7246+ Filename = getStringLiteralIfNotInterpolated (Loc, " '#line'" ,
7247+ /* AllowMultiline=*/ false );
72387248 if (!Filename.has_value ())
72397249 return makeParserError ();
72407250 }
0 commit comments