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-1096] swift2.2 generics property crash #43709

Closed
swift-ci opened this issue Mar 29, 2016 · 21 comments
Closed

[SR-1096] swift2.2 generics property crash #43709

swift-ci opened this issue Mar 29, 2016 · 21 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 regression run-time crash Bug → crash: Swift code crashed during execution swift 2.2

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1096
Radar rdar://problem/25476641
Original Reporter chocoyama (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode7.3 swift2.2
iPad2(iOS7.0.2) or iPhone4s(7.1.2)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, 2.2Regression, RunTimeCrash
Assignee @gparker42
Priority Medium

md5: 24f887963495e893276816ee185deeef

is duplicated by:

  • SR-1201 All generic class crash on iOS 7

Issue Description:

Hello. I'm sorry for my bad English.
Report the bug behavior of swift2.2.

Overview

VewController has property that has a GenericsClass property, crash at the time of execution.

Example

// 1. generics class, it has some property.
class SomeEntity<T> {
    let str = ""
}

// 2. SomeModel has SomeEntity as a property.
class SomeModel {
    let entity = SomeEntity<Int>()
}

// 3. ViewController has SomeModel as a property.
class ViewController: UIViewController {
    private let model = SomeModel() // <- crash!!!
}

StackTrace

* thread #&#8203;1: tid = 0x1aa2b, 0x0025cd64 libswiftCore.dylib`swift_initClassMetadata_UniversalStrategy + 440, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x52de4)
  * frame #&#8203;0: 0x0025cd64 libswiftCore.dylib`swift_initClassMetadata_UniversalStrategy + 440
    frame #&#8203;1: 0x0004e4c4 Test5`___lldb_unnamed_function2$$Test5 + 180
    frame #&#8203;2: 0x0025e07e libswiftCore.dylib`(anonymous namespace)::GenericCacheEntry* llvm::function_ref<(anonymous namespace)::GenericCacheEntry* ()>::callback_fn<swift_getGenericMetadata::$_1>(long) + 18
    frame #&#8203;3: 0x0025df72 libswiftCore.dylib`swift::MetadataCache<(anonymous namespace)::GenericCacheEntry>::addMetadataEntry(swift::EntryRef<(anonymous namespace)::GenericCacheEntry>, ConcurrentList<swift::MetadataCache<(anonymous namespace)::GenericCacheEntry>::EntryPair>&, llvm::function_ref<(anonymous namespace)::GenericCacheEntry* ()>) + 80
    frame #&#8203;4: 0x0025bf28 libswiftCore.dylib`swift::MetadataCache<(anonymous namespace)::GenericCacheEntry>::findOrAdd(void const* const*, unsigned long, llvm::function_ref<(anonymous namespace)::GenericCacheEntry* ()>) + 308
    frame #&#8203;5: 0x0025c024 libswiftCore.dylib`swift_getGenericMetadata2 + 66
    frame #&#8203;6: 0x0004e6f8 Test5`type metadata accessor for SomeEntity<Int> + 88 at ViewController.swift:0

CounterMeasure

If change as follows, problem will not occur:
・change SomeEntity to Struct

struct SomeEntity<T> {
    let str = ""
}

・SomeEntity has no propery

class SomeModel {
}

・change SomeModel property to lazy

class ViewController: UIViewController {
    private lazy var model: SomeModel = SomeModel()
}

・SomeModel initialization in ViewDidLoad

class ViewController: UIViewController {
    private var model = SomeModel?
    override func viewDidLoad() {
        super.viewDidLoad()
        model = SomeModel()
    }
}
@belkadan
Copy link
Contributor

@slavapestov, is this a dup of the earlier issue with the ivar offset?

@swift-ci
Copy link
Collaborator Author

Comment by Kazuhiro (JIRA)

It looks a different problem.
My app crashed even if I added a "Objective-C compatible stored property" prior to "Generics" stored property.

class SomeModel {
    let  str = "" // <- added
    let entity = SomeEntity<Int>()
}

@swift-ci
Copy link
Collaborator Author

Comment by neilwu (JIRA)

Yep, I have met the same crash running on iOS7.1.2 with swift 2.2.

let objectMirror = Mirror(reflecting: self)

I create a small demo show show this crash with EVReflection.
open the demo

@belkadan
Copy link
Contributor

belkadan commented Apr 1, 2016

Just to confirm, this code was working in 2.1?

@belkadan
Copy link
Contributor

belkadan commented Apr 1, 2016

Never mind, I see you added the "regression" label already.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 1, 2016

Comment by Kazuhiro (JIRA)

Yep. I confirmed it's working on iPad2(iOS7.0.2) with Xcode7.2.1 .

@gparker42
Copy link
Mannequin

gparker42 mannequin commented Apr 7, 2016

Can't reproduce. Please attach a complete demonstration project or storyboard and a crash log.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 7, 2016

Comment by TakuyaYokoyama (JIRA)

I have attached the relevant files. Please confirm.

@gparker42
Copy link
Mannequin

gparker42 mannequin commented Apr 9, 2016

Thanks, I'll take a look.

@gparker42
Copy link
Mannequin

gparker42 mannequin commented Apr 9, 2016

Reproduced on 32-bit iOS 7.1.2 as shown in the crash log. Doesn't reproduce on 64-bit. I haven't tried iOS 8.

Runtime is writing to read-only storage in _TEXT,_const. I haven't figured out what that storage is yet.

This feels similar to SR-1055 where libobjc is writing to ivar offset variables that swiftc made read-only.

@gparker42
Copy link
Mannequin

gparker42 mannequin commented Apr 9, 2016

Reduced test:

class C<T> { let i = 1 }
C<Int>()

The store is here:

      // To avoid dirtying memory, only write to the global ivar
      // offset if it's actually wrong.
      if (*_globalIvarOffsets[i] != fieldOffsets[i])
        *_globalIvarOffsets[i] = fieldOffsets[i];

_globalIvarOffsets[0] is 12 and fieldOffsets[0] is 8.

iOS 7 is the arclite path which may be relevant. 32-bit Swift object header is 3*sizeof(void*) = 12 instead of 2*sizeof(void*) = 8 which may be relevant.

@gparker42
Copy link
Mannequin

gparker42 mannequin commented Apr 9, 2016

Found the bug. HeapObject.h and SwiftObject.mm disagree about SwiftObject's contents on 32-bit.

@gparker42
Copy link
Mannequin

gparker42 mannequin commented Apr 9, 2016

Fixed in 41b12e7.

I'll try to remember to add a comment here when the fix ships in Xcode; unfortunately we don't yet have a good process for that notification.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 9, 2016

Comment by Kazuhiro (JIRA)

Thanks a lot!
I have an app supporting iOS7. I hope the fix will ship in Xcode as soon as possible 😃

@swift-ci
Copy link
Collaborator Author

Comment by TakuyaYokoyama (JIRA)

Thanks! I will continue to check this tickets.

@swift-ci
Copy link
Collaborator Author

Comment by tianyouhui (JIRA)

I'm sorry about when to explored to XCode?

@swift-ci
Copy link
Collaborator Author

Comment by Andrew Naylor (JIRA)

@gparker42 I noticed that 41b12e7 has been pulled into `master`, but not `swift-2.2`. Does this mean it won't be included in any further 2.2 releases? (It's absent from the 2.2.1 release).

This bug prevents my team from releasing anything using Swift 2.2 as we must support iPhone 4 and anything we build is crashing on launch.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 3, 2016

Comment by Rebecca (JIRA)

Still crashing with Xcode 7.3.1 (available just today) - do we know which version of Xcode the fix will be bundled in? @gparker42?

@belkadan
Copy link
Contributor

belkadan commented May 3, 2016

We actually did see this working in Xcode 7.3.1, so it's possible there's another variation of the issue. (Sorry!) rebecca (JIRA User), mind filing a new bug with your project? (and anyone else who is still seeing this with a clean build in Xcode 7.3.1)

@gparker42
Copy link
Mannequin

gparker42 mannequin commented May 3, 2016

We expect this to be fixed in Xcode 7.3.1 GM. It is not fixed in the 7.3.1 GM Seed (7D1012 iirc).

Please verify that you are using Xcode 7.3.1 GM (build 7D1014). Then press the option key and Project > Clean Build Folder and rebuild. If you still see a crash then please update this bug and file a new Radar bug with a crash log and a demonstration project of any size.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 9, 2016

Comment by TakuyaYokoyama (JIRA)

Thanks a lot!
We tried to build our app with Xcode7.3.1, and it is running without crashing!
We'll continue to develop with Xcode7.3.1.

@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 regression run-time crash Bug → crash: Swift code crashed during execution swift 2.2
Projects
None yet
Development

No branches or pull requests

3 participants