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-242] CompilerCrash: Segmentation fault when protocol adopts subscript of UInt32 #42864

Closed
swift-ci opened this issue Dec 16, 2015 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-242
Radar None
Original Reporter wittedhaddock (JIRA User)
Type Bug
Status Closed
Resolution Cannot Reproduce
Environment

XC Version 7.1 (7B91b)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: 545f280c44ec4ba7bb035d81f9465adc

Issue Description:

I have the following function implementation that takes a value parameter of generic type T:

    private class func unpackArray<T: BytePressByteArray where T.Generator.Element == UInt8>(value: T, withLength length: UInt) throws -> [AnyObject] {
let range = Range(start: 0, end: UInt32(1))
let a = value[range]
}

BytePressByteArray is defined by

protocol BytePressByteArray: CollectionType {
    subscript(subRange: Range<UInt32>) -> ArraySlice<Self.Generator.Element> { get }
}

Whenever I change the Range generic from Range<Int> to Range<UInt32> (like above), the source editor crashes and all syntax highlighting temporarily disables.

Upon running, I receive the following stack trace with a thrown Segmentation Fault 11:

0  swift                    0x0000000109c1833b llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x0000000109c18a7b SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff960fa52a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fa4ec816e08 _sigtramp + 1450297592
4  swift                    0x0000000107ee1c9f (anonymous namespace)::SILGenConformance::visitAbstractStorageDecl(swift::AbstractStorageDecl*) + 31
5  swift                    0x0000000107ee166d swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 509
6  swift                    0x0000000107edf035 swift::Lowering::SILGenModule::getWitnessTable(swift::ProtocolConformance*) + 277
7  swift                    0x0000000107f2f0d0 SILGenExtension::emitExtension(swift::ExtensionDecl*) + 224
8  swift                    0x0000000107f2e9d5 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 21
9  swift                    0x0000000107eb6e0b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 779
10 swift                    0x0000000107eb79c0 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 928
11 swift                    0x0000000107eb7d6d swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 109
12 swift                    0x0000000107d0bb92 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 11442
13 swift                    0x0000000107d08cd3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
14 swift                    0x0000000107d05354 main + 2324
15 libdyld.dylib            0x00007fff87efd5ad start + 1
16 libdyld.dylib            0x000000000000003d start + 2014325393

If I remove the UInt32() in the function unpackArray and revert the UInt32 in the subscript implementation of BytePressByteArray to Int, there is no issue.

@drewcrawford
Copy link
Contributor

Can't repro in config

Xcode Version 7.2 (7C68)
OSX 10.11.2 (15C50)

Did this get fixed in 7.2?

Repro case:

import Foundation
class Foo {
    private class func unpackArray<T: BytePressByteArray where T.Generator.Element == UInt8>(value: T, withLength length: UInt) throws -> [AnyObject] {
        let range = Range(start: 0, end: UInt32(1))
        let a = value[range]
        abort()
    }
}

protocol BytePressByteArray: CollectionType {
    subscript(subRange: Range<UInt32>) -> ArraySlice<Self.Generator.Element> { get }
}

@drewcrawford
Copy link
Contributor

can't repro on snapshot 2015-12-10

@ahoppen
Copy link
Contributor

ahoppen commented Mar 28, 2016

Seems like the issue has been fixed in the meantime. Cannot reproduce in Swift 2.2 either

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants