Skip to content

Trying to compile code containing too-short backtick-escaped identifiers crashes #86354

@ai0a

Description

@ai0a

Description

Trying to compile any code that includes i.e. `` fails an assertion when lexing the file. This is not a problem on swift 6.1.2, which provides a helpful error message, but for swift 6.2.1 and 6.2.3 it crashes.

Reproduction

``

Stack dump

error: compile command failed due to signal 6 (use -v to see invocation)
Assertion failed: (CurPtr - TokStart >= 3 && "escaped identifier must be longer than or equal 3 bytes"), function formEscapedIdentifierToken, file Lexer.cpp, line 300.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file crash.swift -target arm64-apple-macosx15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -color-diagnostics -Xcc -fcolor-diagnostics -empty-abi-descriptor -no-auto-bridging-header-chaining -module-name crash -in-process-plugin-server-path /Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/jv/42m31k4x31b227bbf4vyy2l80000gr/T/TemporaryDirectory.Cjt0Dn/crash-1.o
1.      Apple Swift version 6.2.3 (swift-6.2.3-RELEASE)
2.      Compiling with effective version 5.10
3.      While evaluating request ParseTopLevelDeclsRequest(source_file "crash.swift")
4.      While evaluating request ParseSourceFileRequest(source_file "crash.swift")
 #0 0x0000000105b9abd8 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1059eabd8)
 #1 0x0000000105b99304 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1059e9304)
 #2 0x0000000105b9b220 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1059eb220)
 #3 0x00000001998556a4 (/usr/lib/system/libsystem_platform.dylib+0x1804ad6a4)
 #4 0x000000019981b848 (/usr/lib/system/libsystem_pthread.dylib+0x180473848)
 #5 0x00000001997249e4 (/usr/lib/system/libsystem_c.dylib+0x18037c9e4)
 #6 0x0000000199723c18 (/usr/lib/system/libsystem_c.dylib+0x18037bc18)
 #7 0x0000000105c0f9d0 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x105a5f9d0)
 #8 0x00000001017c30d4 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1016130d4)
 #9 0x00000001017c25f0 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1016125f0)
#10 0x00000001017c2c1c (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x101612c1c)
#11 0x0000000101807b54 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x101657b54)
#12 0x000000010180ced0 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x10165ced0)
#13 0x000000010025023c (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1000a023c)
#14 0x0000000101810604 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x101660604)
#15 0x000000010180da20 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x10165da20)
#16 0x0000000101b546e4 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1019a46e4)
#17 0x0000000101b544fc (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1019a44fc)
#18 0x0000000101b2d190 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x10197d190)
#19 0x00000001014e95c8 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1013395c8)
#20 0x00000001014e94bc (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1013394bc)
#21 0x0000000100688d5c (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1004d8d5c)
#22 0x0000000100688dd4 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1004d8dd4)
#23 0x0000000100453d10 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1002a3d10)
#24 0x00000001004493a4 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1002993a4)
#25 0x0000000100448b60 (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x100298b60)
#26 0x00000001001e61dc (/Users/user/Library/Developer/Toolchains/swift-6.2.3-RELEASE.xctoolchain/usr/bin/swift-frontend+0x1000361dc)
#27 0x000000019947ab98

Expected behavior

A nice error message, like what an older version of swift gives:

crash.swift:1:1: error: expected expression
1 | ``
  | `- error: expected expression

Environment

Apple Swift version 6.2.3 (swift-6.2.3-RELEASE)
Target: arm64-apple-macosx15.0
Build config: +assertions

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions