mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[embedded] Fix an LLVMARCOpts crash by avoiding direct calls to swift_retain/swift_release
This commit is contained in:
@@ -131,7 +131,9 @@ public func swift_isUniquelyReferenced_nonNull_native(object: UnsafeMutablePoint
|
||||
|
||||
@_silgen_name("swift_retain")
|
||||
public func swift_retain(object: Builtin.RawPointer) -> Builtin.RawPointer {
|
||||
return swift_retain_n(object: object, n: 1)
|
||||
if Int(Builtin.ptrtoint_Word(object)) == 0 { return object }
|
||||
let o = UnsafeMutablePointer<HeapObject>(object)
|
||||
return swift_retain_n_(object: o, n: 1)._rawValue
|
||||
}
|
||||
|
||||
// Cannot use UnsafeMutablePointer<HeapObject>? directly in the function argument or return value as it causes IRGen crashes
|
||||
@@ -155,7 +157,9 @@ func swift_retain_n_(object: UnsafeMutablePointer<HeapObject>, n: UInt32) -> Uns
|
||||
|
||||
@_silgen_name("swift_release")
|
||||
public func swift_release(object: Builtin.RawPointer) {
|
||||
swift_release_n(object: object, n: 1)
|
||||
if Int(Builtin.ptrtoint_Word(object)) == 0 { return }
|
||||
let o = UnsafeMutablePointer<HeapObject>(object)
|
||||
swift_release_n_(object: o, n: 1)
|
||||
}
|
||||
|
||||
@_silgen_name("swift_release_n")
|
||||
|
||||
10
test/embedded/arc-crash.swift
Normal file
10
test/embedded/arc-crash.swift
Normal file
@@ -0,0 +1,10 @@
|
||||
// RUN: %target-swift-frontend -target armv7-apple-none-macho -assert-config Debug -Osize -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
|
||||
// RUN: %target-swift-frontend -target arm64-apple-none-macho -assert-config Debug -Osize -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
|
||||
|
||||
// REQUIRES: VENDOR=apple
|
||||
// REQUIRES: optimized_stdlib
|
||||
|
||||
public func test() {}
|
||||
test()
|
||||
|
||||
// CHECK: define {{.*}}i32 @main
|
||||
Reference in New Issue
Block a user