Skip to content

stdlib: define typealias CLongDouble for FreeBSD #61756

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
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
16 changes: 13 additions & 3 deletions stdlib/public/core/CTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ public typealias CLongDouble = Double
// which we don't yet have in Swift.
#if arch(x86_64) || arch(i386)
public typealias CLongDouble = Float80
#endif
// TODO: Fill in definitions for other OSes.
#if arch(s390x)
#elseif arch(s390x)
// On s390x '-mlong-double-64' option with size of 64-bits makes the
// Long Double type equivalent to Double type.
public typealias CLongDouble = Double
Expand All @@ -100,7 +98,19 @@ public typealias CLongDouble = Double
public typealias CLongDouble = Double
#endif
#elseif os(OpenBSD)
#if arch(x86_64)
public typealias CLongDouble = Float80
#else
#error("CLongDouble needs to be defined for this OpenBSD architecture")
#endif
#elseif os(FreeBSD)
#if arch(x86_64) || arch(i386)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference would be to swap the architectures here, but that is low priority.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to—I was just matching the Darwin and Linux branches.

public typealias CLongDouble = Float80
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong. FP80 is X86 only according to https://www.freebsd.org/cgi/man.cgi?query=arch&sektion=7&format=html. This should be similar to what we have for Darwin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks!

I think that's also true for OpenBSD:

$ for os in freebsd openbsd; do
        for arch in i386 x86_64 armv7 arm64; do
                target="${arch}-${os}"                                                         
                echo -n "${target}: "                                                          
                clang-15 -target "${target}" -E -dM - </dev/null | fgrep __LDBL_MANT_DIG__
        done
        echo
done

i386-freebsd: #define __LDBL_MANT_DIG__ 64
x86_64-freebsd: #define __LDBL_MANT_DIG__ 64
armv7-freebsd: #define __LDBL_MANT_DIG__ 53
arm64-freebsd: #define __LDBL_MANT_DIG__ 113

i386-openbsd: #define __LDBL_MANT_DIG__ 64
x86_64-openbsd: #define __LDBL_MANT_DIG__ 64
armv7-openbsd: #define __LDBL_MANT_DIG__ 53
arm64-openbsd: #define __LDBL_MANT_DIG__ 113

I've added an x86_64 || i386 conditional to the FreeBSD branch. @compnerd & @3405691582, would you like me to do the same for OpenBSD, or would you prefer I leave it alone (or just add a comment)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate PR for fixing O/BSD would be appreciated!

Copy link
Member

@3405691582 3405691582 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it is an error to attempt to build Swift on anything but amd64-openbsd so it's not strictly necessary to fix for this platform right now. It might be worthwhile doing, but it might be misleading if you see the conditional and yet get a cmake error trying to bring up the platform on the architecture though.

#else
#error("CLongDouble needs to be defined for this FreeBSD architecture")
#endif
#else
// TODO: define CLongDouble for other OSes
#endif

// FIXME: Is it actually UTF-32 on Darwin?
Expand Down