Skip to content

Commit 658fdcd

Browse files
committed
stdlib: fix the #if guard for Builtin.unprotectedStackAlloc
rdar://107274878
1 parent d38e4e8 commit 658fdcd

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

stdlib/public/core/TemporaryAllocation.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ internal func _withUnsafeTemporaryAllocation<T, R>(
161161
#endif
162162
}
163163

164-
#if $BuiltinUnprotectedStackAlloc
165164
@_alwaysEmitIntoClient @_transparent
166165
internal func _withUnprotectedUnsafeTemporaryAllocation<T, R>(
167166
of type: T.Type,
@@ -181,11 +180,19 @@ internal func _withUnprotectedUnsafeTemporaryAllocation<T, R>(
181180
// notice and complain.)
182181
let result: R
183182

183+
#if $BuiltinUnprotectedStackAlloc
184184
let stackAddress = Builtin.unprotectedStackAlloc(
185185
capacity._builtinWordValue,
186186
MemoryLayout<T>.stride._builtinWordValue,
187187
alignment._builtinWordValue
188188
)
189+
#else
190+
let stackAddress = Builtin.stackAlloc(
191+
capacity._builtinWordValue,
192+
MemoryLayout<T>.stride._builtinWordValue,
193+
alignment._builtinWordValue
194+
)
195+
#endif
189196

190197
// The multiple calls to Builtin.stackDealloc() are because defer { } produces
191198
// a child function at the SIL layer and that conflicts with the verifier's
@@ -200,7 +207,6 @@ internal func _withUnprotectedUnsafeTemporaryAllocation<T, R>(
200207
throw error
201208
}
202209
}
203-
#endif
204210

205211
@_alwaysEmitIntoClient @_transparent
206212
internal func _fallBackToHeapAllocation<R>(
@@ -281,20 +287,16 @@ public func _withUnprotectedUnsafeTemporaryAllocation<R>(
281287
alignment: Int,
282288
_ body: (UnsafeMutableRawBufferPointer) throws -> R
283289
) rethrows -> R {
284-
return try _withUnsafeTemporaryAllocation(
290+
return try _withUnprotectedUnsafeTemporaryAllocation(
285291
of: Int8.self,
286292
capacity: byteCount,
287293
alignment: alignment
288294
) { pointer in
289-
#if $BuiltinUnprotectedStackAlloc
290295
let buffer = UnsafeMutableRawBufferPointer(
291296
start: .init(pointer),
292297
count: byteCount
293298
)
294299
return try body(buffer)
295-
#else
296-
return try withUnsafeTemporaryAllocation(byteCount: byteCount, alignment: alignment, body)
297-
#endif
298300
}
299301
}
300302

@@ -365,15 +367,11 @@ public func _withUnprotectedUnsafeTemporaryAllocation<T, R>(
365367
capacity: capacity,
366368
alignment: MemoryLayout<T>.alignment
367369
) { pointer in
368-
#if $BuiltinUnprotectedStackAlloc
369370
Builtin.bindMemory(pointer, capacity._builtinWordValue, type)
370371
let buffer = UnsafeMutableBufferPointer<T>(
371372
start: .init(pointer),
372373
count: capacity
373374
)
374375
return try body(buffer)
375-
#else
376-
return try withUnsafeTemporaryAllocation(of: type, capacity: capacity, body)
377-
#endif
378376
}
379377
}

0 commit comments

Comments
 (0)