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-9967] Runtime crash when calling generic structs with unowned properties #52371

Open
swift-ci opened this issue Feb 21, 2019 · 2 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself runtime The Swift Runtime

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9967
Radar None
Original Reporter scott (JIRA User)
Type Bug
Environment

Xcode 10.2 beta 3 (10P99q)
Swift compiler swiftlang-1001.0.63.8 clang-1001.0.44

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

md5: f92bd658577ff89456d76693b6af0dca

Issue Description:

The following code reliably crashes at runtime:

protocol BarProtocol {}

extension BarProtocol {
    var str: String { return "str" }
}

struct Foo<T: AnyObject>: BarProtocol {
    unowned let bar: T
}

class Bar {
    let str2 = "str2"

    var foo: BarProtocol {
        return Foo(bar: self)
    }
}

_ = Bar().foo.str

with the following stack trace:

0  swift                    0x000000010f514efa PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010f5146dc SignalHandler(int) + 348
2  libsystem_platform.dylib 0x00007fff7c49cb3d _sigtramp + 29
3  libsystem_platform.dylib 0x0000000000000001 _sigtramp + 2209756385
4  libobjc.A.dylib          0x00007fff7b1dcfaa objc_copyWeak + 18
5  libswiftCore.dylib       0x000000011202be3c swift_unknownObjectUnownedCopyInit + 76
6  libswiftCore.dylib       0x0000000110c94365 swift_unknownObjectUnownedCopyInit + 4274423157
7  libswiftCore.dylib       0x0000000110c940a3 swift_unknownObjectUnownedCopyInit + 4274422451
8  swift                    0x000000010bd9d13d llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 365
9  swift                    0x000000010bda37fc llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 1004
10 swift                    0x000000010b3867b1 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 54977
11 swift                    0x000000010b375ac7 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6823
12 swift                    0x000000010b31590d main + 1261
13 libdyld.dylib            0x00007fff7c2b1ed9 start + 1

Ways to make the crash go away:

  • Remove `Bar.str2` (the entire property)

  • Make the struct non-generic

  • Change the struct to a class

  • Removed `unowned` (to weak or strong)

We have seen a handful of reports of this happening with current tooling (Xcode 10.1) as well, but can't reliably reproduce.

@belkadan
Copy link
Contributor

@mikeash, does this sound familiar?

@mikeash
Copy link
Contributor

mikeash commented Feb 21, 2019

That's a new one for me. Pretty interesting crash. The reproducer crashes on a recent build from master. Looks like disagreement as to whether this reference should use Swift or ObjC unowned semantics.

@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 runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

3 participants