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-5413] Observing weak properties SegFaults during compilation #47987

Closed
swift-ci opened this issue Jul 9, 2017 · 4 comments
Closed

[SR-5413] Observing weak properties SegFaults during compilation #47987

swift-ci opened this issue Jul 9, 2017 · 4 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 SILGen Area → compiler: The SIL generation stage

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 9, 2017

Previous ID SR-5413
Radar rdar://problem/33216002
Original Reporter mgoszcz2 (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

macOS Version 10.12.5 (16F73)
Xcode Version 9.0 beta 2 (9M137d)
Swift Version 4.0 (swiftlang-900.0.45.6 clang-900.0.26)

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

md5: 6b7e9e33aa6561a2d27774d25702b6c5

duplicates:

  • SR-5408 Compiler segfault with key path literal referring to weak property

Issue Description:

The offending code:

import Foundation

class Foo: NSObject {}

class Bar: NSObject {
    @objc dynamic weak var foo: Foo? // Remove weak to stop the crash
}

class Main {
    var bar: Bar = Bar()
    var observation: NSKeyValueObservation?

    init() {
        observation = bar.observe(\.foo) { _, _ in }
    }
}

Crashes like so:
(also works on the trunk toolchain)

0  swift                    0x000000011345c31a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000011345b756 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fffeb583b3a _sigtramp + 26
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 346539232
4  swift                    0x00000001106e4b62 swift::Lowering::SILGenFunction::emitAnyHashableErasure(swift::SILLocation, swift::Lowering::ManagedValue, swift::Type, swift::ProtocolConformanceRef, swift::Lowering::SGFContext) + 450
5  swift                    0x000000011072622a (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 7450
6  swift                    0x00000001106e78e7 (anonymous namespace)::RValueEmitter::visitKeyPathExpr(swift::KeyPathExpr*, swift::Lowering::SGFContext) + 5399
7  swift                    0x000000011067c276 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3174
8  swift                    0x000000011067edb4 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 228
9  swift                    0x000000011067b722 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 274
10 swift                    0x000000011068191b (anonymous namespace)::ArgEmitter::emitShuffle(swift::TupleShuffleExpr*, swift::Lowering::AbstractionPattern) + 3931
11 swift                    0x000000011067f131 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1121
12 swift                    0x000000011067b722 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 274
13 swift                    0x000000011067a2c6 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus const&) && + 438
14 swift                    0x0000000110678beb (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>&, llvm::Optional<swift::ForeignErrorConvention>&, swift::ImportAsMemberStatus&, swift::Lowering::ApplyOptions&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1787
15 swift                    0x000000011067637d (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3949
16 swift                    0x00000001106d09d9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 105
17 swift                    0x000000011065345b swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 395
18 swift                    0x00000001106535a3 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::Lowering::SGFContext) && + 163
19 swift                    0x0000000110673788 swift::Lowering::SILGenFunction::emitInjectEnum(swift::SILLocation, swift::Lowering::ArgumentSource, swift::SILType, swift::EnumElementDecl*, swift::Lowering::SGFContext) + 2456
20 swift                    0x00000001106dc0d1 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 46945
21 swift                    0x00000001106db01a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 42666
22 swift                    0x00000001106e4fc4 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 500
23 swift                    0x000000011073cc15 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 1733
24 swift                    0x00000001106b33df swift::Lowering::SILGenFunction::emitClassConstructorInitializer(swift::ConstructorDecl*) + 3679
25 swift                    0x0000000110669612 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 3410
26 swift                    0x000000011074b340 (anonymous namespace)::SILGenType::emitType() + 896
27 swift                    0x000000011066e85a swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 74
28 swift                    0x000000011066db2b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1115
29 swift                    0x000000011066f502 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 930
30 swift                    0x000000010fe286a2 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 12306
31 swift                    0x000000010fe23e24 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7332
32 swift                    0x000000010fdd9ab8 main + 12248
33 libdyld.dylib            0x00007fffeb374235 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret crash.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name crash 
1.  While silgen constructor initializer SIL function "@_T05crash4MainCACycfc".
 for 'init' at crash.swift:13:5
Segmentation fault: 11
@belkadan
Copy link
Contributor

Can you be more specific for "works on the trunk toolchain"?

Note that even with this you won't get notified when the object is deallocated, because that setting to nil doesn't go through the property setter.

@swift-ci
Copy link
Collaborator Author

Comment by Maciej Goszczycki (JIRA)

Yes, sorry. I just meant that I tried the trunk toolchain today and the segfault is still there. Just in case it was specific to the Xcode Beta 2 Swift.

I don't think I wanted to be notified, in my original code I just do some work when the property changes to something non-nil and didn't want a strong reference.

@belkadan
Copy link
Contributor

Okay, thanks! It crashed for me too and I was wondering if someone had fixed it since I last updated.

@swift-ci create

@jckarter
Copy link
Member

I think this is a duplicate of SR-5408.

@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 SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

4 participants