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-10146] Segmentation fault for AnyObject keypath #52548

Closed
Agarunov opened this issue Mar 21, 2019 · 10 comments
Closed

[SR-10146] Segmentation fault for AnyObject keypath #52548

Agarunov opened this issue Mar 21, 2019 · 10 comments
Assignees
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 key paths Feature: key paths (both native and Objective-C)

Comments

@Agarunov
Copy link

Previous ID SR-10146
Radar None
Original Reporter @Agarunov
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift 5 Xcode 10.2 beta 4 (10P107d). Swift 4.2 Xcode 10.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, KeyPaths
Assignee @theblixguy
Priority Medium

md5: 1bc5e45397b672fb1fa208066a1fd75a

Issue Description:

Segfault for this code:

let kp = \AnyObject.accessibilityFrame
Command failed due to signal: Segmentation fault: 11
0  swift                    0x000000010d619eb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010d61968c SignalHandler(int) + 348
2  libsystem_platform.dylib 0x00007fff741c3b3d _sigtramp + 29
3  libsystem_platform.dylib 0xfd00000070001008 _sigtramp + 4226012392
4  swift                    0x000000010a012be5 swift::Lowering::SILGenBuilder::createUpcast(swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType) + 341
5  swift                    0x000000010a066a2f emitKeyPathRValueBase(swift::Lowering::SILGenFunction&, swift::AbstractStorageDecl*, swift::SILLocation, swift::SILValue, swift::CanType&, swift::SubstitutionMap) + 1631
6  swift                    0x000000010a0634a6 getOrCreateKeyPathGetter(swift::Lowering::SILGenModule&, swift::SILLocation, swift::AbstractStorageDecl*, swift::SubstitutionMap, swift::GenericEnvironment*, llvm::ArrayRef<std::__1::pair<swift::CanType, swift::SILType> >, swift::CanType, swift::CanType) + 4086
7  swift                    0x000000010a05dbc4 swift::Lowering::SILGenModule::emitKeyPathComponentForDecl(swift::SILLocation, swift::GenericEnvironment*, unsigned int&, bool&, swift::SubstitutionMap, swift::AbstractStorageDecl*, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::CanType, bool) + 980
8  swift                    0x000000010a051126 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 60518
9  swift                    0x000000010a0422e3 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 131
10 swift                    0x000000010a035d7c swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 268
11 swift                    0x0000000109fd56cd swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 141
12 swift                    0x000000010a0b86bf swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 8431
13 swift                    0x000000010a06ee91 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 433
14 swift                    0x0000000109fcc7e3 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 995
15 swift                    0x000000010a0c6265 (anonymous namespace)::SILGenType::emitType() + 261
16 swift                    0x0000000109fd798d swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 77
17 swift                    0x0000000109fd6b66 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1206
18 swift                    0x0000000109fd897c swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1228
19 swift                    0x0000000109479b0a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 30106
20 swift                    0x000000010946ec9e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6862
21 swift                    0x000000010940cdae main + 1246
22 libdyld.dylib            0x00007fff73fd8ed9 start + 1
@theblixguy
Copy link
Collaborator

Sorry, but could you provide the full code that leads to a crash or a reduced example code that leads to the same crash? The above code does not crash for me on 4.2 and 5.1.

@Agarunov
Copy link
Author

Add test project which leads to a crash in attachments

@theblixguy
Copy link
Collaborator

Hmm this is very strange - we are emitting SIL for a keypath that is not valid? This should actually be getting diagnosed. I am having trouble while debugging this (seems like this is specific to UIKit/AppDelegate but I am trying to figure out a way to compile this on the Mac), but in the meantime, maybe @jckarter has some clue as to why there's a crash here.

@Agarunov
Copy link
Author

For me this crash also reproducible in playgrounds

@theblixguy
Copy link
Collaborator

Could you post the code that crashes for you in the playgrounds?

@Agarunov
Copy link
Author

Add playground and crash log

@belkadan
Copy link
Contributor

Ooops. I don't think we ever intended to support key paths through AnyObject, since they represent arbitrary Objective-C messages rather than a specific property declaration. Joe?

@theblixguy
Copy link
Collaborator

Here's a reduced test case that also causes a crash:

import Foundation

class Foo: NSObject {
  @objc let bar: Int = 0
}

class Bar: Foo {
  func crash() {
    let keyPath = \AnyObject.bar
  }
}

The crash is in SILVerifier instead:

SIL verification failed: keypath value type should match value type of keypath pattern: leafTy == pattern->getValueType().subst(patternSubs)->getCanonicalType()

I have a fix for this, I'll create a PR shortly.

@theblixguy
Copy link
Collaborator

Here's a fix: #23497

@theblixguy
Copy link
Collaborator

Resolved on master by PR #23820 and also cherry-picked to the 5.1 branch.

@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 key paths Feature: key paths (both native and Objective-C)
Projects
None yet
Development

No branches or pull requests

4 participants