Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Swift compiler crashes when compiling function with incomplete error handling #81119

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

Open
NSSimpleApps opened this issue Apr 26, 2025 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software SILGen Area → compiler: The SIL generation stage

Comments

@NSSimpleApps
Copy link

Description

import Foundation

extension FileManager {
    func safeCreateDirectory(at URL: URL) throws(NSError) {
        do {
            try self.createDirectory(at: URL, withIntermediateDirectories: true)
        } catch let error as NSError {
            if error.code == NSFileWriteFileExistsError {
                return
            } else {
                throw error
            }
        }
    }
    func safeRemoveDirectory(atPath path: String) throws(NSError) {
        do {
            try self.removeItem(atPath: path)
        } catch let error as NSError {
            if error.code == NSFileNoSuchFileError {
                return
            } else {
                throw error
            }
        }
    }
}

Reproduction

Stack dump

$ swiftc test_filemanager.swift


error: compile command failed due to signal 11 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file test_filemanager.swift -target x86_64-apple-macosx15.0 -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -color-diagnostics -swift-version 6 -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name test_filemanager -disable-clang-spi -target-sdk-version 15.4 -target-sdk-name macosx15.4 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -in-process-plugin-server-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/7k/w6t7s2gj1zld4ny76qd58tph0000gn/T/TemporaryDirectory.BBiaAr/test_filemanager-1.o
1.	Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "test_filemanager.swift")
4.	While silgen emitFunction SIL function "@$sSo13NSFileManagerC16test_filemanagerE19safeCreateDirectory2aty10Foundation3URLV_tSo7NSErrorCYKF".
 for 'safeCreateDirectory(at:)' (at test_filemanager.swift:4:5)
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           0x0000000112df8708 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1  swift-frontend           0x0000000112df6039 llvm::sys::RunSignalHandlers() + 233
2  swift-frontend           0x0000000112df8cee SignalHandler(int) + 302
3  libsystem_platform.dylib 0x00007ff819cb625d _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603370148175296
5  swift-frontend           0x000000010ca5fff0 swift::Lowering::SILGenFunction::emitThrow(swift::SILLocation, swift::Lowering::ManagedValue, bool) + 3648
6  swift-frontend           0x000000010ca1d98b std::__1::__function::__func<swift::Lowering::SILGenFunction::emitCatchDispatch(swift::DoCatchStmt*, swift::Lowering::ManagedValue, llvm::ArrayRef<swift::CaseStmt*>, swift::Lowering::JumpDest)::$_1, std::__1::allocator<swift::Lowering::SILGenFunction::emitCatchDispatch(swift::DoCatchStmt*, swift::Lowering::ManagedValue, llvm::ArrayRef<swift::CaseStmt*>, swift::Lowering::JumpDest)::$_1>, void (swift::SILLocation)>::operator()(swift::SILLocation&&) + 443
7  swift-frontend           0x000000010ca180cb std::__1::__function::__func<(anonymous namespace)::PatternMatchEmission::emitDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, std::__1::function<void (swift::SILLocation)> const&)::$_0, std::__1::allocator<(anonymous namespace)::PatternMatchEmission::emitDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, std::__1::function<void (swift::SILLocation)> const&)::$_0>, void (swift::SILLocation)>::operator()(swift::SILLocation&&) + 75
8  swift-frontend           0x000000010ca199e3 void llvm::function_ref<void (std::__1::optional<swift::Lowering::ManagedValue>)>::callback_fn<(anonymous namespace)::PatternMatchEmission::emitIsDispatch(llvm::ArrayRef<(anonymous namespace)::RowToSpecialize>, swift::Lowering::ConsumableManagedValue, std::__1::function<void (llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, llvm::ArrayRef<(anonymous namespace)::SpecializedRow>, std::__1::function<void (swift::SILLocation)> const&)> const&, std::__1::function<void (swift::SILLocation)> const&)::$_2>(long, std::__1::optional<swift::Lowering::ManagedValue>) + 51
9  swift-frontend           0x000000010c977947 (anonymous namespace)::CheckedCastEmitter::emitConditional(swift::Lowering::ManagedValue, swift::CastConsumptionKind, swift::Lowering::SGFContext, llvm::function_ref<void (swift::Lowering::ManagedValue)>, llvm::function_ref<void (std::__1::optional<swift::Lowering::ManagedValue>)>, swift::ProfileCounter, swift::ProfileCounter) + 2599
10 swift-frontend           0x000000010ca17152 (anonymous namespace)::PatternMatchEmission::emitSpecializedDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, unsigned int&, unsigned int, std::__1::function<void (swift::SILLocation)> const&) + 20610
11 swift-frontend           0x000000010ca0f1c6 (anonymous namespace)::PatternMatchEmission::emitDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, std::__1::function<void (swift::SILLocation)> const&) + 3222
12 swift-frontend           0x000000010ca11787 swift::Lowering::SILGenFunction::emitCatchDispatch(swift::DoCatchStmt*, swift::Lowering::ManagedValue, llvm::ArrayRef<swift::CaseStmt*>, swift::Lowering::JumpDest) + 1527
13 swift-frontend           0x000000010ca5bf15 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 16453
14 swift-frontend           0x000000010ca59d22 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 7762
15 swift-frontend           0x000000010c9bd016 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 550
16 swift-frontend           0x000000010c8df2e5 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8869
17 swift-frontend           0x000000010c8e038d swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 221
18 swift-frontend           0x000000010c8dd030 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 480
19 swift-frontend           0x000000010ca79c52 SILGenExtension::visitFuncDecl(swift::FuncDecl*) + 210
20 swift-frontend           0x000000010ca755a8 SILGenExtension::emitExtension(swift::ExtensionDecl*) + 376
21 swift-frontend           0x000000010c8dcd58 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 200
22 swift-frontend           0x000000010c8e4845 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2325
23 swift-frontend           0x000000010ca574a8 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 200
24 swift-frontend           0x000000010c8e9d6c swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 812
25 swift-frontend           0x000000010bd22307 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1159
26 swift-frontend           0x000000010bd2682c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 3036
27 swift-frontend           0x000000010bd24a16 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4518
28 swift-frontend           0x000000010bc93b09 swift::mainEntry(int, char const**) + 3241
29 dyld                     0x00007ff8198d9530 start + 3056

Expected behavior

Crash free behaviour.

Environment

uname -a
Darwin comp 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:28:23 PDT 2025; root:xnu-11417.101.15~117/RELEASE_X86_64 x86_64
swiftc --version
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: x86_64-apple-macosx15.0

Additional information

No response

@NSSimpleApps NSSimpleApps added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Apr 26, 2025
@glessard
Copy link
Contributor

This still crashes with swift-6.2-DEVELOPMENT-SNAPSHOT-2025-04-24-a
It should be a diagnostic of an uncaught error (a catch { fatalError() } is missing.)

@glessard glessard added SILGen Area → compiler: The SIL generation stage and removed triage needed This issue needs more specific labels labels Apr 26, 2025
@glessard glessard changed the title Swift compiler crashes when compiling the code below Swift compiler crashes when compiling function with incomplete error handling May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

2 participants