Navigation Menu

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-4471] Compiler crashes with "Command failed due to signal: Illegal instruction: 4" #47048

Closed
swift-ci opened this issue Apr 2, 2017 · 2 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 IRGen LLVM IR generation

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 2, 2017

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

Attachment: Download

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

md5: 709a9ac736e2101d3c529c6696f02c0e

Issue Description:

The following code crashes the compiler in the 3/31 and 4/1 nightly toolchain using Xcode 8.3.

protocol P: AnyObject {}
protocol Foo {
    // The compiler crash goes away if you remove the P constraint on this associated type
    associatedtype ObjectType: P
}

protocol UpcastHelper {
    associatedtype Sub: Foo
    associatedtype Super: Foo

    // ObjectIdentifier(object) == ObjectIdentifier(Self.cast(object))
    static func cast(_ object: Sub.ObjectType) -> Super.ObjectType
}


struct AnyFoo<Object: P>: Foo {

    typealias ObjectType = Object

    class Base {}

    final class Derived<Helper: UpcastHelper>: Base where Helper.Super == AnyFoo<Object> {

        init(_ foo: Helper.Sub) {
            self.foo = foo
        }

        let foo: Helper.Sub
    }

    init<Helper: UpcastHelper>
        (foo: Helper.Sub, helper: Helper.Type)
        where Helper.Super == AnyFoo<Object> {

            // This is the expression that causes the crash
            _ = Derived<Helper>(foo)
    }
}
@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2017

Infinite recursion in IRGen, of all places.

    frame #&#8203;82290: 0x000000010013dff5 swift`emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) [inlined] (anonymous namespace)::GenericArguments::collect(IGF=0x00007fff5fbfb478) at GenMeta.cpp:204 [opt]
    frame #&#8203;82291: 0x000000010013dee7 swift`emitNominalMetadataRef(IGF=0x00007fff5fbfb478, theDecl=0x0000000106081110, theType=<unavailable>) at GenMeta.cpp:388 [opt]
    frame #&#8203;82292: 0x000000010013bc94 swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) [inlined] (anonymous namespace)::EmitTypeMetadataRef::visitNominalType(swift::CanTypeWrapper<swift::NominalType>) at GenMeta.cpp:631 [opt]
    frame #&#8203;82293: 0x000000010013bc8c swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) [inlined] swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visitEnumType(T=<unavailable>) at TypeNodes.def:107 [opt]
    frame #&#8203;82294: 0x000000010013bc8c swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(this=0x00007fff5fbfa350, T=<unavailable>) at TypeNodes.def:107 [opt]
    frame #&#8203;82295: 0x00000001001292f0 swift`swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) [inlined] emitDirectTypeMetadataRef(type=<unavailable>) at GenMeta.cpp:1019 [opt]
    frame #&#8203;82296: 0x00000001001292e0 swift`swift::irgen::IRGenFunction::emitTypeMetadataRef(this=0x00007fff5fbfb478, type=<unavailable>) at GenMeta.cpp:1476 [opt]
    frame #&#8203;82297: 0x000000010015e560 swift`swift::irgen::MetadataPath::followComponent(IGF=<unavailable>, sourceKey=0x00007fff5fbfa4e0, source=<unavailable>, component=<unavailable>) at GenProto.cpp:2073 [opt]
    frame #&#8203;82298: 0x000000010015dc72 swift`swift::irgen::MetadataPath::follow(IGF=0x00007fff5fbfb478, sourceKey=LocalTypeDataKey @ 0x00007fff5fbfa4e0, source=0x0000000105a67b30, begin=<unavailable>, end=(Ptr = ""), cache=<unavailable>) at GenProto.cpp:1889 [opt]
    frame #&#8203;82299: 0x000000010015de13 swift`swift::irgen::MetadataPath::followFromWitnessTable(this=<unavailable>, IGF=<unavailable>, conformingType=<unavailable>, conformance=<unavailable>, source=<unavailable>, cache=<unavailable>) const at GenProto.cpp:1818 [opt]
    frame #&#8203;82300: 0x0000000100083266 swift`swift::irgen::emitArchetypeWitnessTableRef(IGF=<unavailable>, archetype=<unavailable>, protocol=<unavailable>) at GenArchetype.cpp:257 [opt]
    frame #&#8203;82301: 0x00000001001605a3 swift`swift::irgen::emitWitnessTableRef(IGF=0x00007fff5fbfb478, srcType=CanType @ r15, srcMetadataCache=0x00007fff5fbfa698, conformance=ProtocolConformanceRef @ 0x00007fff5fbfa650) at GenProto.cpp:2256 [opt]
    frame #&#8203;82302: 0x000000010016050f swift`swift::irgen::emitWitnessTableRef(IGF=<unavailable>, srcType=<unavailable>, conformance=<unavailable>) at GenProto.cpp:2239 [opt]
    frame #&#8203;82303: 0x000000010013e586 swift`void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<(anonymous namespace)::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::'lambda'(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) [inlined] (anonymous namespace)::GenericArguments::collect(reqtIndex=0)::'lambda'(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)::operator()(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) const at GenMeta.cpp:208 [opt]
    frame #&#8203;82304: 0x000000010013e577 swift`void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<(anonymous namespace)::GenericArguments::collect(callable=<unavailable>, params=<unavailable>, params=<unavailable>, params=<unavailable>)::'lambda'(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) at STLExtras.h:92 [opt]
    frame #&#8203;82305: 0x00000001001614a5 swift`swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap const&, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) [inlined] llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::operator(params=Optional<swift::ProtocolConformanceRef> @ 0x00007fbdb44324e0)(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) const at STLExtras.h:105 [opt]
    frame #&#8203;82306: 0x0000000100161482 swift`swift::irgen::GenericTypeRequirements::enumerateFulfillments(this=0x00007fff5fbfa880, IGM=<unavailable>, subs=0x00007fff5fbfa760, callback=<unavailable>)>) at GenProto.cpp:2558 [opt]
    frame #&#8203;82307: 0x000000010013dff5 swift`emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) [inlined] (anonymous namespace)::GenericArguments::collect(IGF=0x00007fff5fbfb478) at GenMeta.cpp:204 [opt]
    frame #&#8203;82308: 0x000000010013dee7 swift`emitNominalMetadataRef(IGF=0x00007fff5fbfb478, theDecl=0x0000000106081110, theType=<unavailable>) at GenMeta.cpp:388 [opt]
    frame #&#8203;82309: 0x000000010013bc94 swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) [inlined] (anonymous namespace)::EmitTypeMetadataRef::visitNominalType(swift::CanTypeWrapper<swift::NominalType>) at GenMeta.cpp:631 [opt]
    frame #&#8203;82310: 0x000000010013bc8c swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) [inlined] swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visitEnumType(T=<unavailable>) at TypeNodes.def:107 [opt]
    frame #&#8203;82311: 0x000000010013bc8c swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(this=0x00007fff5fbfaa10, T=<unavailable>) at TypeNodes.def:107 [opt]
    frame #&#8203;82312: 0x00000001001292f0 swift`swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) [inlined] emitDirectTypeMetadataRef(type=<unavailable>) at GenMeta.cpp:1019 [opt]
    frame #&#8203;82313: 0x00000001001292e0 swift`swift::irgen::IRGenFunction::emitTypeMetadataRef(this=0x00007fff5fbfb478, type=<unavailable>) at GenMeta.cpp:1476 [opt]
    frame #&#8203;82314: 0x000000010013df70 swift`emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) [inlined] (anonymous namespace)::GenericArguments::collect(IGF=0x00007fff5fbfb478) at GenMeta.cpp:199 [opt]
    frame #&#8203;82315: 0x000000010013dee7 swift`emitNominalMetadataRef(IGF=0x00007fff5fbfb478, theDecl=0x0000000106081510, theType=<unavailable>) at GenMeta.cpp:388 [opt]
    frame #&#8203;82316: 0x000000010013bc94 swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) [inlined] (anonymous namespace)::EmitTypeMetadataRef::visitNominalType(swift::CanTypeWrapper<swift::NominalType>) at GenMeta.cpp:631 [opt]
    frame #&#8203;82317: 0x000000010013bc8c swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(swift::CanType) [inlined] swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visitEnumType(T=<unavailable>) at TypeNodes.def:107 [opt]
    frame #&#8203;82318: 0x000000010013bc8c swift`llvm::Value* swift::CanTypeVisitor<(anonymous namespace)::EmitTypeMetadataRef, llvm::Value*>::visit<>(this=0x00007fff5fbfad00, T=<unavailable>) at TypeNodes.def:107 [opt]
    frame #&#8203;82319: 0x00000001001292f0 swift`swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) [inlined] emitDirectTypeMetadataRef(type=<unavailable>) at GenMeta.cpp:1019 [opt]
    frame #&#8203;82320: 0x00000001001292e0 swift`swift::irgen::IRGenFunction::emitTypeMetadataRef(this=0x00007fff5fbfb478, type=<unavailable>) at GenMeta.cpp:1476 [opt]
    frame #&#8203;82321: 0x000000010012b06f swift`swift::irgen::emitMetatypeRef(IGF=0x00007fff5fbfb478, type=<unavailable>, explosion=0x00007fff5fbfafb8) at GenMeta.cpp:2072 [opt]
    frame #&#8203;82322: 0x00000001001c2d69 swift`swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) [inlined] (anonymous namespace)::IRGenSILFunction::visitMetatypeInst(this=0x00007fff5fbfb478) at IRGenSIL.cpp:1732 [opt]
    frame #&#8203;82323: 0x00000001001c2d13 swift`swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(this=0x00007fff5fbfb478, V=0x0000000105b15ba0) at SILNodes.def:204 [opt]
    frame #&#8203;82324: 0x00000001001b98df swift`(anonymous namespace)::IRGenSILFunction::emitSILFunction() [inlined] swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(I=<unavailable>) at SILVisitor.h:100 [opt]
    frame #&#8203;82325: 0x00000001001b98d7 swift`(anonymous namespace)::IRGenSILFunction::emitSILFunction() at IRGenSIL.cpp:1651 [opt]

@huonw, @rjmccall, is this something you've been looking at? I don't even see any obvious recursion here.

@slavapestov
Copy link
Member

Works on master. I'll add a regression test.

@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 IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

4 participants