Skip to content

runtime: Fix swift_deallocBox #12744

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

Merged
merged 1 commit into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stdlib/public/runtime/HeapObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ BoxPair::Return SWIFT_RT_ENTRY_IMPL(swift_allocBox)(const Metadata *type) {

void swift::swift_deallocBox(HeapObject *o) {
auto metadata = static_cast<const GenericBoxHeapMetadata *>(o->metadata);
// Move the object to the deallocating state (+1 -> +0).
o->refCounts.decrementFromOneNonAtomic();
SWIFT_RT_ENTRY_CALL(swift_deallocObject)(o, metadata->getAllocSize(),
metadata->getAllocAlignMask());
}
Expand Down
34 changes: 34 additions & 0 deletions test/Interpreter/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,37 @@ map({()})

map({(x: Int) -> Int in x})
// CHECK: Non-void overload

// This used to assert in runtime assert builds.
protocol Initializable {
init()
}

func f2<T: Initializable>(_ x: T) -> T? { return nil }

func c<T: Initializable>(_ x: T) {

({
guard var b = f2(x) else { print("success") ; return }
let c = { b = T() }
_ = (b, c)
})()

}
extension Bool : Initializable {
init() {
self = true
}
}
// CHECK: success
c(true)


func f() -> Bool? { return nil }

// CHECK: success
({
guard var b = f() else { print("success") ; return }
let c = { b = true }
_ = (b, c)
})()