Skip to content

Commit ae0162f

Browse files
committed
[Darwin] Get rid of trampoline hack for lgamma function.
Since swiftc pass-through -Xcc arguments to ClangImporter, we can unveil lgamma_r from _REENTRANT macro.
1 parent 243e359 commit ae0162f

File tree

3 files changed

+3
-41
lines changed

3 files changed

+3
-41
lines changed

stdlib/public/Platform/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ if(SWIFT_HOST_VARIANT MATCHES "${SWIFT_DARWIN_VARIANTS}")
1313
POSIXError.swift
1414
MachError.swift)
1515
set(swift_platform_flags
16-
SWIFT_COMPILE_FLAGS -Xfrontend -disable-objc-attr-requires-foundation-module
16+
SWIFT_COMPILE_FLAGS
17+
-Xfrontend -disable-objc-attr-requires-foundation-module
18+
-Xcc -D_REENTRANT # Required to unveil lgamma_r used in tgmath.
1719
API_NOTES_NON_OVERLAY)
1820
else()
1921
set(swift_platform_name swiftGlibc)

stdlib/public/Platform/Misc.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,6 @@ _swift_Platform_fcntlPtr(int fd, int cmd, void* ptr) {
4444
return fcntl(fd, cmd, ptr);
4545
}
4646

47-
#if defined(__APPLE__)
48-
#define _REENTRANT
49-
#include <math.h>
50-
51-
extern float
52-
_swift_Darwin_lgammaf_r(float x, int *psigngam) {
53-
return lgammaf_r(x, psigngam);
54-
}
55-
56-
extern double
57-
_swift_Darwin_lgamma_r(double x, int *psigngam) {
58-
return lgamma_r(x, psigngam);
59-
}
60-
61-
extern long double
62-
_swift_Darwin_lgammal_r(long double x, int *psigngam) {
63-
return lgammal_r(x, psigngam);
64-
}
65-
#endif
66-
6747
#if defined(__FreeBSD__)
6848
extern char **
6949
_swift_FreeBSD_getEnv() {

stdlib/public/Platform/tgmath.swift.gyb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -282,33 +282,13 @@ public func scalbn(x: ${T}, _ n: Int) -> ${T} {
282282

283283
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
284284
% for T, CT, f in AllFloatTypes():
285-
#if os(Linux) || os(FreeBSD)
286285
@_transparent
287286
@warn_unused_result
288287
public func lgamma(x: ${T}) -> (${T}, Int) {
289288
var sign = CInt(0)
290289
let value = lgamma${f}_r(${CT}(x), &sign)
291290
return (${T}(value), Int(sign))
292291
}
293-
#else
294-
% # On Darwin platform,
295-
% # The real lgamma_r is not imported because it hides behind macro _REENTRANT.
296-
@warn_unused_result
297-
@_silgen_name("_swift_Darwin_lgamma${f}_r")
298-
func _swift_Darwin_lgamma${f}_r(_: ${CT},
299-
_: UnsafeMutablePointer<CInt>) -> ${CT}
300-
301-
@_transparent
302-
@warn_unused_result
303-
public func lgamma(x: ${T}) -> (${T}, Int) {
304-
var sign = CInt(0)
305-
let value = withUnsafeMutablePointer(&sign) {
306-
(signp: UnsafeMutablePointer<CInt>) -> ${CT} in
307-
return _swift_Darwin_lgamma${f}_r(${CT}(x), signp)
308-
}
309-
return (${T}(value), Int(sign))
310-
}
311-
#endif
312292

313293
% end
314294

0 commit comments

Comments
 (0)