swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-13641] Segmentation fault on static subscript with generic constraint #56077

Open rnapier opened 4 years ago

rnapier commented 4 years ago
Previous ID SR-13641
Radar rdar://problem/69845491
Original Reporter @rnapier
Type Bug
Environment Xcode 12.0.1. Swift 5.3. 10.15.7 (19H2)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: c50362df80be17cd867ceeaeb68a082b

Issue Description:

The following crashes the compiler with in Swift 5.3 at the "let v" line. This is slightly simplified based on code from https://stackoverflow.com/q/64154893/97337.

This doesn't crash if the `: UIViewController` constraint is not applied to subscript.

import UIKit
protocol PushNotificationPresenting: UIViewController {}

struct ViewControllerName {

    static var pushNotification: Identifier<PushNotificationPresenting> { .init(name: "PushNotificationViewController") }

   static subscript<T: UIViewController>(identifier: Identifier<T>) -> T? {
        get { nil }
    }

    struct Identifier<T> {
        let name: String
    }
}

let v = ViewControllerName[ViewControllerName.pushNotification]

Crash dump

Stack dump:
0.  Program arguments: /Applications/Xcode-12.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /tmp/test/test/AppDelegate.swift /tmp/test/test/SceneDelegate.swift -primary-file /tmp/test/test/ViewController.swift /tmp/test/test/ContentView.swift -emit-module-path /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/ViewController~partial.swiftmodule -emit-module-doc-path /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/ViewController~partial.swiftdoc -emit-module-source-info-path /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/ViewController~partial.swiftsourceinfo -serialize-diagnostics-path /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/ViewController.dia -emit-dependencies-path /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/ViewController.d -emit-reference-dependencies-path /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/ViewController.swiftdeps -target x86_64-apple-ios14.0-simulator -enable-objc-interop -sdk /Applications/Xcode-12.0.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk -I /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Products/Debug-iphonesimulator -F /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/rnapier/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /tmp/test -enable-anonymous-context-mangled-names -Xcc -I/Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-generated-files.hmap -Xcc -I/Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-own-target-headers.hmap -Xcc -I/Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-all-target-headers.hmap -Xcc -iquote -Xcc /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/test-project-headers.hmap -Xcc -I/Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources-normal/x86_64 -Xcc -I/Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources/x86_64 -Xcc -I/Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/DerivedSources -Xcc -DDEBUG=1 -target-sdk-version 14.0 -module-name test -o /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Build/Intermediates.noindex/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/ViewController.o -index-store-path /Users/rnapier/Library/Developer/Xcode/DerivedData/test-dthhutsfmixdgkfbohwjdhmccvqj/Index/DataStore -index-system-modules 
1.  Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
2.  While evaluating request IRGenSourceFileRequest(IR Generation for file "/tmp/test/test/ViewController.swift")
3.  While emitting IR SIL function "@globalinit_33_AB68D58C9E8144B07F324936B47C5F86_func0".
 for declaration 0x7fbcb0183358 (at /tmp/test/test/ViewController.swift:73:1)
0  swift                    0x0000000104aa2865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000104aa1865 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000104aa2e1f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6f58b5fd _sigtramp + 29
4  libsystem_platform.dylib 0x00007fbcaf173560 _sigtramp + 18446743787016191872
5  swift                    0x0000000100839fd1 swift::irgen::CallEmission::emitToExplosion(swift::irgen::Explosion&, bool) + 4161
6  swift                    0x0000000100a1a4bb (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 4187
7  swift                    0x00000001009f8c26 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8982
8  swift                    0x0000000100893cb7 swift::irgen::IRGenerator::emitLazyDefinitions() + 1207
9  swift                    0x00000001009cdac0 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1920
10 swift                    0x00000001009f6681 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 97
11 swift                    0x00000001009d1dec llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 940
12 swift                    0x00000001009ce03d swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 269
13 swift                    0x0000000100619d3a performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3002
14 swift                    0x0000000100609928 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 20712
15 swift                    0x000000010058ac07 main + 1255
16 libdyld.dylib            0x00007fff6f392cc9 start + 1
17 libdyld.dylib            0x000000000000004e start + 18446603338650145670
error: Segmentation fault: 11 (in target 'test' from project 'test')
typesanitizer commented 4 years ago

@swift-ci create