mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
runtime: Fix overflow of swift_unownedRetain reference counts
On 32bit platforms there are 7 bits reserved for the unowned retain count. This makes overflow a likely scenario. Implement overflow into the side table. rdar://33495003
This commit is contained in:
35
test/Interpreter/unowned_overflow.swift
Normal file
35
test/Interpreter/unowned_overflow.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
// RUN: %target-run-simple-swift | %FileCheck %s
|
||||
// REQUIRES: executable_test
|
||||
|
||||
class Owner {
|
||||
var children: [Child] = []
|
||||
|
||||
func addChild(_ c: Child) {
|
||||
children.append(c)
|
||||
}
|
||||
|
||||
func removeChildren() {
|
||||
children.removeAll()
|
||||
}
|
||||
|
||||
func test() {
|
||||
// Overflow of unowned ref count on 32bit.
|
||||
for _ in 0 ..< 500 {
|
||||
addChild(Child(self))
|
||||
}
|
||||
removeChildren()
|
||||
}
|
||||
}
|
||||
|
||||
class Child {
|
||||
unowned var owner: Owner
|
||||
|
||||
init(_ o: Owner) {
|
||||
owner = o
|
||||
}
|
||||
}
|
||||
|
||||
let o = Owner()
|
||||
o.test()
|
||||
print("success")
|
||||
// CHECK: success
|
||||
Reference in New Issue
Block a user