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-2845] Compiler crash in CompileSwift while emitting SIL #45439

Open
swift-ci opened this issue Oct 4, 2016 · 2 comments
Open

[SR-2845] Compiler crash in CompileSwift while emitting SIL #45439

swift-ci opened this issue Oct 4, 2016 · 2 comments
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

swift-ci commented Oct 4, 2016

Previous ID SR-2845
Radar None
Original Reporter xavierjurado (JIRA User)
Type Bug
Environment

Xcode 7.3.1 (7D1014), Local Swift Development Snapshot built from "swift-2.2.1-RELEASE" tag.

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

md5: cdebbe25fbf8772e2cb3a55cbb4eb764

Issue Description:

Compiler crashes in the CompileSwift step while building the following code:

class A {

}

class B {

    static func fake() -> Self {
        let fake = A()
        let bitcast = unsafeBitCast(fake, self)
        return bitcast
    }
}

Important note: this issue can not be reproduced with the default toolchain bundled by Xcode 7.3.1, but it keeps crashing with our development build created from the swift-2.2.1-RELEASE tag.

Crash:

TYPE MISMATCH IN ARGUMENT 1 OF APPLY AT expression at [/Users/xavi/Desktop/SwiftCrashers/SwiftCrashers/SelfCrash.swift:11:23 - line:11:47] RangeText="unsafeBitCast(fake, self)"
  argument value:   %0 = argument of bb0 : $@thick B.Type           // user: %1
  parameter type: @thick Self.Type
0  swift                    0x0000000109ace74b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x0000000109acda36 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x0000000109aced1f SignalHandler(int) + 287
3  libsystem_platform.dylib 0x00007fff9afb352a _sigtramp + 26
4  swift                    0x000000010a3da315 FirstTarget + 66429
5  swift                    0x0000000109acebe6 abort + 22
6  swift                    0x000000010790811a swift::Lowering::SILGenFunction::emitApply(swift::SILLocation, swift::Lowering::ManagedValue, llvm::ArrayRef<swift::Substitution>, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::ApplyOptions, llvm::Optional<swift::SILFunctionTypeRepresentation>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::Lowering::SGFContext) + 6426
7  swift                    0x000000010790ae13 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 5875
8  swift                    0x00000001079091da swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 58
9  swift                    0x000000010794cd36 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 86
10 swift                    0x00000001079476ac swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 316
11 swift                    0x0000000107937d55 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 213
12 swift                    0x0000000107937e4d swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 45
13 swift                    0x000000010799f576 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 550
14 swift                    0x000000010799f345 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
15 swift                    0x0000000107961521 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 353
16 swift                    0x00000001078fa2b3 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 1155
17 swift                    0x00000001079a4d61 (anonymous namespace)::SILGenType::emitType() + 1409
18 swift                    0x00000001079a475e swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
19 swift                    0x00000001078fea9b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 683
20 swift                    0x00000001078ffb30 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 848
21 swift                    0x0000000107900055 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 117
22 swift                    0x000000010767a937 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 13783
23 swift                    0x0000000107676523 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2803
24 swift                    0x000000010767146c main + 1532
25 libdyld.dylib            0x00007fff969275ad start + 1
26 libdyld.dylib            0x000000000000003c start + 1768786576

Stack dump:

0.  Program arguments: /Library/Developer/Toolchains/swift-LOCAL-2016-09-25-a.xctoolchain/usr/bin/swift -frontend -c /Users/xavi/Desktop/SwiftCrashers/SwiftCrashers/ViewController.swift /Users/xavi/Desktop/SwiftCrashers/SwiftCrashers/AppDelegate.swift -primary-file /Users/xavi/Desktop/SwiftCrashers/SwiftCrashers/SelfCrash.swift -target x86_64-apple-ios9.3 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk -I /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Products/Debug-iphonesimulator -F /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/xavi/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/SwiftCrashers-generated-files.hmap -Xcc -I/Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/SwiftCrashers-own-target-headers.hmap -Xcc -I/Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/SwiftCrashers-all-target-headers.hmap -Xcc -iquote -Xcc /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/SwiftCrashers-project-headers.hmap -Xcc -I/Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/DerivedSources/x86_64 -Xcc -I/Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/xavi/Desktop/SwiftCrashers -emit-module-doc-path /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/Objects-normal/x86_64/SelfCrash~partial.swiftdoc -Onone -module-name SwiftCrashers -emit-module-path /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/Objects-normal/x86_64/SelfCrash~partial.swiftmodule -serialize-diagnostics-path /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/Objects-normal/x86_64/SelfCrash.dia -emit-dependencies-path /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/Objects-normal/x86_64/SelfCrash.d -emit-reference-dependencies-path /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/Objects-normal/x86_64/SelfCrash.swiftdeps -o /Users/xavi/Library/Developer/Xcode/DerivedData/SwiftCrashers-abozamfkptcbmsgqbgmumrgnbluz/Build/Intermediates/SwiftCrashers.build/Debug-iphonesimulator/SwiftCrashers.build/Objects-normal/x86_64/SelfCrash.o 
1.  While emitting SIL for 'fake' at /Users/xavi/Desktop/SwiftCrashers/SwiftCrashers/SelfCrash.swift:9:5
@belkadan
Copy link
Contributor

belkadan commented Oct 5, 2016

Swift 3 version:

class A {
}

class B {
    static func fake() -> Self {
        let fake = A()
        let bitcast = unsafeBitCast(fake, to: self)
        return bitcast
    }
}

Output:

TYPE MISMATCH IN ARGUMENT 1 OF APPLY AT expression at [<stdin>:9:23 - line:9:51] RangeText="unsafeBitCast(fake, to: self)"
  argument value:   %0 = argument of bb0 : $@thick B.Type           // user: %1
  parameter type: @thick Self.Type

@slavapestov, does this look familiar?

(Xavi, note also that this code is, well, unsafe. It's very possible that using it will result in undefined behavior at run time.)

@swift-ci
Copy link
Collaborator Author

swift-ci commented Oct 6, 2016

Comment by Xavier Jurado (JIRA)

The snippet I posted is a simplified version of code that we use to fake dependencies in our test target, and it's is intended to crash if we interact with the returned object. In its original form it's an extension of NSObject that looks like this:

extension NSObject {

    // WARNING: It creates a fake object to fill dependencies that are NOT going to be used. Otherwise it will crash/
    static func fake() -> Self {
        return unsafeBitCast(OCMockObject.mockForClass(self as! AnyClass), self)
    }
}

Thanks for the warning, hope this makes more sense now 🙂

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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