mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Small fixes for typed throws in withUnsafeTemporaryAllocation
This commit is contained in:
@@ -266,10 +266,7 @@ public func withUnsafeTemporaryAllocation<R: ~Copyable, E: Error>(
|
||||
}
|
||||
}
|
||||
|
||||
switch consume result {
|
||||
case .success(let resultValue): return resultValue
|
||||
case .failure(let error): throw error
|
||||
}
|
||||
return try result.get()
|
||||
}
|
||||
|
||||
/// Provides scoped access to a raw buffer pointer with the specified byte count
|
||||
@@ -299,10 +296,7 @@ public func _withUnprotectedUnsafeTemporaryAllocation<R: ~Copyable, E: Error>(
|
||||
}
|
||||
}
|
||||
|
||||
switch consume result {
|
||||
case .success(let resultValue): return resultValue
|
||||
case .failure(let error): throw error
|
||||
}
|
||||
return try result.get()
|
||||
}
|
||||
|
||||
/// Provides scoped access to a buffer pointer to memory of the specified type
|
||||
@@ -362,10 +356,7 @@ public func withUnsafeTemporaryAllocation<
|
||||
}
|
||||
}
|
||||
|
||||
switch consume result {
|
||||
case .success(let resultValue): return resultValue
|
||||
case .failure(let error): throw error
|
||||
}
|
||||
return try result.get()
|
||||
}
|
||||
|
||||
/// Provides scoped access to a buffer pointer to memory of the specified type
|
||||
@@ -399,8 +390,5 @@ public func _withUnprotectedUnsafeTemporaryAllocation<
|
||||
}
|
||||
}
|
||||
|
||||
switch consume result {
|
||||
case .success(let resultValue): return resultValue
|
||||
case .failure(let error): throw error
|
||||
}
|
||||
return try result.get()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s
|
||||
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
|
||||
// REQUIRES: optimized_stdlib
|
||||
|
||||
@_silgen_name("blackHole")
|
||||
func blackHole(_ value: UnsafeMutableRawPointer?) -> Void
|
||||
@@ -16,10 +16,10 @@ do {
|
||||
// CHECK: [[ONE_BYTE_PTR_RAW:%temp_alloc[0-9]*]] = alloca i8, align 1
|
||||
// CHECK: [[FIVE_BYTE_PTR_RAW:%temp_alloc[0-9]*]] = alloca [5 x i8], align 1
|
||||
// CHECK: [[ONE_KB_PTR_RAW:%temp_alloc[0-9]*]] = alloca [1024 x i8], align 8
|
||||
// CHECK: [[ONE_KB_RAND_PTR_RAW:%temp_alloc[0-9]*]] = alloca [1024 x i8], align 16
|
||||
// CHECK: [[INT_PTR_RAW:%temp_alloc[0-9]*]] = alloca [16 x i8], align 4
|
||||
// CHECK: [[INT_PTR_RAW2:%temp_alloc[0-9]*]] = alloca [16 x i8], align 4
|
||||
// CHECK: [[VOID_PTR_RAW:%temp_alloc[0-9]*]] = alloca [2 x i8], align 1
|
||||
// CHECK: [[ONE_KB_RAND_PTR_RAW:%temp_alloc[0-9]*]] = alloca [1024 x i8], align 16
|
||||
|
||||
// CHECK: ptrtoint ptr {{.*}} to [[WORD:i[0-9]+]]
|
||||
|
||||
@@ -49,14 +49,6 @@ withUnsafeTemporaryAllocation(byteCount: 1024, alignment: 8) { buffer in
|
||||
// CHECK: [[ONE_KB_PTR:%[0-9]+]] = ptrtoint ptr [[ONE_KB_PTR_RAW]] to [[WORD]]
|
||||
// CHECK: call swiftcc void @blackHole([[WORD]] [[ONE_KB_PTR]])
|
||||
|
||||
// MARK: Alignment unknown at compile-time
|
||||
|
||||
withUnsafeTemporaryAllocation(byteCount: 1024, alignment: Int.random(in: 0 ..< 16)) { buffer in
|
||||
blackHole(buffer.baseAddress)
|
||||
}
|
||||
// CHECK: [[ONE_KB_RAND_PTR:%[0-9]+]] = ptrtoint ptr [[ONE_KB_RAND_PTR_RAW]] to [[WORD]]
|
||||
// CHECK: call swiftcc void @blackHole([[WORD]] [[ONE_KB_RAND_PTR]])
|
||||
|
||||
// MARK: Typed buffers
|
||||
|
||||
withUnsafeTemporaryAllocation(of: Int32.self, capacity: 4) { buffer in
|
||||
@@ -77,3 +69,10 @@ withUnsafeTemporaryAllocation(of: Void.self, capacity: 2) { buffer in
|
||||
// CHECK: [[VOID_PTR:%[0-9]+]] = ptrtoint ptr [[VOID_PTR_RAW]] to [[WORD]]
|
||||
// CHECK: call swiftcc void @blackHole([[WORD]] [[VOID_PTR]])
|
||||
|
||||
// MARK: Alignment unknown at compile-time
|
||||
|
||||
withUnsafeTemporaryAllocation(byteCount: 1024, alignment: Int.random(in: 0 ..< 16)) { buffer in
|
||||
blackHole(buffer.baseAddress)
|
||||
}
|
||||
// CHECK: [[ONE_KB_RAND_PTR:%[0-9]+]] = ptrtoint ptr [[ONE_KB_RAND_PTR_RAW]] to [[WORD]]
|
||||
// CHECK: call swiftcc void @blackHole([[WORD]] [[ONE_KB_RAND_PTR]])
|
||||
|
||||
@@ -157,7 +157,7 @@ TemporaryAllocationTestSuite.test("typedAllocationIsAligned") {
|
||||
|
||||
// MARK: Typed throws
|
||||
enum HomeworkError: Error, Equatable {
|
||||
case dogAtIt
|
||||
case dogAteIt
|
||||
case forgot
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user