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-14822] Crash while compiling an unwrapping code #57170

Closed
swift-ci opened this issue Jun 24, 2021 · 1 comment
Closed

[SR-14822] Crash while compiling an unwrapping code #57170

swift-ci opened this issue Jun 24, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14822
Radar None
Original Reporter moshegottlieb (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Reproducible on multiple environments (iOS, macOS).

Attaching a project file with a demo.

Tested on a Mac mini M1

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

md5: f3b3cfcc2bd6c7573fe0909c689aedb2

Issue Description:

The following minimal example makes the swift compiler bundled with Xcode 12.5.1 crash.

I've only encountered it while unwrapping an optional result value, but I guess there could be other cases.

 
import Foundation
 
extension String : Error {}
 
class Obj {
}
 
func crash(value:Obj?,completion:@escaping (Result<Obj?,Error>)->()){
    completion(Result {
        guard let value = value else
{             *throw* "Error"         }
 
         return value
 
     })
 
 }
 
  
 
 crash(value: nil) { result in
 
     do {
 
         let value = try result.get()
 
         guard let value = value else {             *throw* "Error"         }
    } catch
{         print("Error: \(error)")     }
}
 

Compiler crash log:

/Users/xxxx/Downloads/crash/crash/main.swift:27:19: warning: value 'value' was defined but never used; consider replacing with boolean test
        guard let value = value else {
              ~~~~^~~~~~~~
                                != nil
Stored value type does not match pointer operand type!
  store %T5crash3ObjC* %55, i64* %11, align 8, !dbg !215
 i64in function $s5crashys6ResultOyAA3ObjCSgs5Error_pGcfU_
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
<unknown>:0: note: Broken function found, compilation aborted!
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.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/xxxx/Downloads/crash/crash/main.swift -emit-module-path /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/arm64/main~partial.swiftmodule -emit-module-doc-path /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/arm64/main~partial.swiftdoc -emit-module-source-info-path /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/arm64/main~partial.swiftsourceinfo -serialize-diagnostics-path /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/arm64/main.dia -emit-dependencies-path /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/arm64/main.d -emit-reference-dependencies-path /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/arm64/main.swiftdeps -target arm64-apple-macos11.3 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -I /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Products/Debug -F /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Products/Debug -enable-testing -g -module-cache-path /Users/xxxx/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/xxxx/Downloads/crash -enable-anonymous-context-mangled-names -Xcc -I/Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-generated-files.hmap -Xcc -I/Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-own-target-headers.hmap -Xcc -I/Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-project-headers.hmap -Xcc -I/Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Products/Debug/include -Xcc -I/Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources-normal/arm64 -Xcc -I/Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources/arm64 -Xcc -I/Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources -Xcc -DDEBUG=1 -target-sdk-version 11.3 -module-name crash -o /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/arm64/main.o -index-store-path /Users/xxxx/Library/Developer/Xcode/DerivedData/crash-anqzepowswdhlfgorswkbmcmbale/Index/DataStore -index-system-modules 
1. Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)
2. Running pass 'Module Verifier' on function '@"$s5crashys6ResultOyAA3ObjCSgs5Error_pGcfU_"'
0  swift-frontend           0x00000001063986e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 52
1  swift-frontend           0x0000000106397858 llvm::sys::RunSignalHandlers() + 128
2  swift-frontend           0x0000000106398cb0 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000019860ec44 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001985c343c pthread_kill + 292
5  libsystem_c.dylib        0x000000019850b460 abort + 104
6  swift-frontend           0x00000001022d9d28 std::__1::__throw_length_error(char const*) + 0
7  swift-frontend           0x00000001063058c8 llvm::report_fatal_error(llvm::Twine const&, bool) + 252
8  swift-frontend           0x00000001063057cc llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9  swift-frontend           0x00000001062afef0 void llvm::VerifierSupport::CheckFailed<llvm::Instruction*, llvm::MDNode const*>(llvm::Twine const&, llvm::Instruction* const&, llvm::MDNode const* const&) + 0
10 swift-frontend           0x00000001062548c8 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1136
11 swift-frontend           0x0000000106253e80 llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 96
12 swift-frontend           0x000000010625a4f8 llvm::legacy::FunctionPassManager::run(llvm::Function&) + 336
13 swift-frontend           0x00000001025ee30c swift::performLLVMOptimizations(swift::IRGenOptions const&, llvm::Module*, llvm::TargetMachine*) + 1484
14 swift-frontend           0x00000001025ef228 swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef, swift::UnifiedStatsReporter*) + 2464
15 swift-frontend           0x00000001022e554c 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*) + 3084
16 swift-frontend           0x00000001022d758c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5556
17 swift-frontend           0x000000010226c460 main + 1136
18 libdyld.dylib            0x00000001985e1450 start + 4
error: Abort trap: 6 (in target 'crash' from project 'crash')
@typesanitizer
Copy link

I see the crash for Xcode 12.5 but it seems to be fixed on main and Xcode 13 beta. Please verify with a development toolchain snapshot from swift.org or the latest Xcode 13 beta release.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants