Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14988] Regression: Swift 5.5 compiler crashes during SILGEN (5.4 ok) #57330

Open
mickeyl opened this issue Jul 30, 2021 · 9 comments
Open

[SR-14988] Regression: Swift 5.5 compiler crashes during SILGEN (5.4 ok) #57330

mickeyl opened this issue Jul 30, 2021 · 9 comments
Labels

Comments

@mickeyl
Copy link

@mickeyl mickeyl commented Jul 30, 2021

Previous ID SR-14988
Radar rdar://problem/81370792
Original Reporter @mickeyl
Type Bug
Environment

Xcode 13, 13.1, 13.2b2, macOS 12, all kinds of Mac hardware.

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 099d6c28511f05bdd280681cd08f3d29

Issue Description:

While compiling (`swift build`) https://github.com/Cornucopia-Swift/CornucopiaUDS/tree/ios15-weak-dance, I get the following swift compiler crash:

 /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/SerialAdapter/StreamCommandQueue.swift:241:54: warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
 let bytesWritten = active.pendingBytesToSend.withUnsafeBytes {
 ^
 /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/SerialAdapter/StreamCommandQueue.swift:241:54: warning: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
 let bytesWritten = active.pendingBytesToSend.withUnsafeBytes {
 ^
 Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
 Stack dump:
 0. Program arguments: /Applications/Xcode-13.0.0-Beta.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/CornucopiaUDS.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/Extensions/String+ConstructableViaMessage.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/Extensions/UnitSpeed+RPM.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/Protocols/ISOTP.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/Protocols/KWP.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/Protocols/NullProtocol.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/Protocols/Protocol.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/SerialAdapter/DefaultStringCommandProvider.swift -primary-file /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/SerialAdapter/GenericSerialAdapter.swift -primary-file /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/SerialAdapter/SerialAdapterCommands.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/SerialAdapter/StreamCommandQueue.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/Adapter.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/BusProtocol.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/DTC.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/DiagnosticSession.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/Error.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/Extensions.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/IDsAndTypes.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/Message.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/OBD2.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/OBD2DTC.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/OBD2Session.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/Pipeline.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/Protocols.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/UDS/Services.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/Units/UnitRPM.swift /Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/Units/UnitsAndScaling.swift /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/DerivedSources/resource_bundle_accessor.swift -emit-module-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/GenericSerialAdapter~partial.swiftmodule -emit-module-doc-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/GenericSerialAdapter~partial.swiftdoc -emit-module-source-info-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/GenericSerialAdapter~partial.swiftsourceinfo -emit-dependencies-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/GenericSerialAdapter.d -emit-reference-dependencies-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/GenericSerialAdapter.swiftdeps -emit-module-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/SerialAdapterCommands~partial.swiftmodule -emit-module-doc-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/SerialAdapterCommands~partial.swiftdoc -emit-module-source-info-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/SerialAdapterCommands~partial.swiftsourceinfo -emit-dependencies-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/SerialAdapterCommands.d -emit-reference-dependencies-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/SerialAdapterCommands.swiftdeps -target arm64-apple-macosx10.15.4 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-13.0.0-Beta.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -I /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug -I /Applications/Xcode-13.0.0-Beta.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-13.0.0-Beta.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -module-cache-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode-13.0.0-Beta.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -resource-dir /Applications/Xcode-13.0.0-Beta.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/Users/mickey/Documents/late/CornucopiaUDS/.build/checkouts/swift-crypto/Sources/CCryptoBoringSSLShims/include/module.modulemap -Xcc -I -Xcc /Users/mickey/Documents/late/CornucopiaUDS/.build/checkouts/swift-crypto/Sources/CCryptoBoringSSLShims/include -Xcc -fmodule-map-file=/Users/mickey/Documents/late/CornucopiaUDS/.build/checkouts/swift-crypto/Sources/CCryptoBoringSSL/include/module.modulemap -Xcc -I -Xcc /Users/mickey/Documents/late/CornucopiaUDS/.build/checkouts/swift-crypto/Sources/CCryptoBoringSSL/include -module-name CornucopiaUDS -target-sdk-version 12.0.0 -parse-as-library -o /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/GenericSerialAdapter.swift.o -o /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/CornucopiaUDS.build/SerialAdapter/SerialAdapterCommands.swift.o -index-store-path /Users/mickey/Documents/late/CornucopiaUDS/.build/arm64-apple-macosx/debug/index/store -index-system-modules
 1. Apple Swift version 5.5 (swiftlang-1300.0.27.6 clang-1300.0.27.2)
 2.
 3. While evaluating request IRGenRequest(IR Generation for file "/Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/SerialAdapter/GenericSerialAdapter.swift")
 4. While emitting IR SIL function "@$s13CornucopiaUDS0B0O20GenericSerialAdapterC4send7message17expectedResponses4thenyAC7MessageV_SiSgys6ResultOyAkC5ErrorOGctFyANySayAKGAPGcfU_Tf2nnni_n".
 for expression at [/Users/mickey/Documents/late/CornucopiaUDS/Sources/CornucopiaUDS/SerialAdapter/GenericSerialAdapter.swift:106:52 - line:143:13] RangeText="{ result in
switch result {
 case .failure(let error):
 let failure = UDS.MessageResult.failure(error)
 then(failure)
case .success(let responses):
 //TODO: Change the UDS.MessageHandler into a Result<Error, UDS.Message>, else we can't convey low level errors over to the next logical layer
 precondition(responses.count > 0, "Did not receive at least a single CAN frame")
let sid = self.canAutoFormat ? message.bytes[0] : message.bytes[1]
let responses = responses.filter { response in
 guard response.bytes[0] == UInt8(0x03) else
{ return true }
 guard response.bytes[1] == UDS.NegativeResponse else { return true }
guard response.bytes[2] == sid else
{ return true }
 guard response.bytes[3] == UDS.NegativeResponseCode.requestCorrectlyReceivedResponsePending.rawValue else { return true }
let transient = responses[0].bytes[1..<4].map
{ String(format: "0x%02X ", $0) }
.joined()
 logger.trace("Ignoring transient UDS response (transient)")
 return false
 }
 //FIXME: Ensure all headers are the same
 var bytes = [UInt8]()
 responses.forEach
{ response in bytes += response.bytes }
do
{ bytes = try self.busProtocolDecoder!.decode(bytes) let assembled: UDS.Message = .init(id: responses.first!.id, bytes: bytes) let success: UDS.MessageResult = .success(assembled) then(success) }
catch
{ let failure: UDS.MessageResult = .failure(error as! UDS.Error) then(failure) }
}
 "
 Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
 0 swift-frontend 0x0000000106e88d18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
 1 swift-frontend 0x0000000106e87e20 llvm::sys::RunSignalHandlers() + 128
 2 swift-frontend 0x0000000106e89358 SignalHandler(int) + 292
 3 libsystem_platform.dylib 0x00000001813074a4 _sigtramp + 56
 4 swift-frontend 0x000000010302d9d4 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::loadAsTake(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Explosion&) const + 140
 5 swift-frontend 0x000000010302d9d4 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::loadAsTake(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Explosion&) const + 140
 6 swift-frontend 0x000000010308f4d8 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 34984
 7 swift-frontend 0x00000001030821bc swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7732
 8 swift-frontend 0x0000000102f5d940 swift::irgen::IRGenerator::emitLazyDefinitions() + 1208
 9 swift-frontend 0x000000010305636c swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 8036
 10 swift-frontend 0x00000001030800b0 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188
 11 swift-frontend 0x0000000103060618 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 752
 12 swift-frontend 0x0000000103059e3c swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::_1::unique_ptr<swift::SILModule, std::_1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 236
 13 swift-frontend 0x0000000102c24f20 performCompileStepsPostSILGen(swift::CompilerInstance&, std::_1::unique_ptr<swift::SILModule, std::_1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2540
 14 swift-frontend 0x0000000102c181dc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6428
 15 swift-frontend 0x0000000102b72bc0 main + 932
 16 dyld 0x00000001090dd0fc start + 520
@typesanitizer
Copy link

@typesanitizer typesanitizer commented Jul 31, 2021

Could you please format the crash message correctly? It's very difficult to read/understand in its current state. (If you use the plain text editor, you should be able to put surrounding code blocks and paste directly, that should preserve newlines properly.)

@typesanitizer
Copy link

@typesanitizer typesanitizer commented Jul 31, 2021

Also, if you are able to share the project privately, you could attach it to a feedback filed through feedbackassistant.apple.com

@mickeyl
Copy link
Author

@mickeyl mickeyl commented Jul 31, 2021

I have adjusted the traceback. Moreover, it happens when compiling a FOSS project, which I have linked in the description.

@typesanitizer
Copy link

@typesanitizer typesanitizer commented Jul 31, 2021

@swift-ci create

@mickeyl
Copy link
Author

@mickeyl mickeyl commented Sep 15, 2021

Same with Xcode 13 RC.

@mickeyl
Copy link
Author

@mickeyl mickeyl commented Sep 21, 2021

Further investigation points to https://github.com/Cornucopia-Swift/CornucopiaUDS/blob/c426c866f771587e2b1bc45332a1ff56ce6c2d94/Sources/CornucopiaUDS/SerialAdapter/GenericSerialAdapter.swift#L117:

let sid = self.canAutoFormat ? message.bytes[0] : message.bytes[1]

Apparantly referring to `message` from within the closure makes the SIL generator crash. Moving this line outside the closure makes it work.

@mickeyl
Copy link
Author

@mickeyl mickeyl commented Nov 9, 2021

Same crash with 5.5.1

@mickeyl
Copy link
Author

@mickeyl mickeyl commented Nov 17, 2021

Same with 5.5.2-dev as per Xcode 13.2 beta 2.

@mickeyl
Copy link
Author

@mickeyl mickeyl commented Dec 8, 2021

Likewise with 5.5.2-dev as per Xcode 13.2 RC.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants