From 43dc209cdad9642bc70d995ae628745140050182 Mon Sep 17 00:00:00 2001 From: Dario Rexin Date: Thu, 8 Jul 2021 15:56:31 -0700 Subject: [PATCH 1/2] Fix build on FreeBSD --- CMakeLists.txt | 2 + cmake/modules/SwiftConfigureSDK.cmake | 4 +- include/swift/AST/AutoDiff.h | 9 +- include/swift/AST/PlatformKinds.def | 1 + .../Differentiation/DifferentiationInvoker.h | 14 +- lib/AST/PlatformKind.cpp | 2 + lib/AST/Type.cpp | 8 +- lib/ClangImporter/ClangImporter.cpp | 15 +- lib/Driver/Driver.cpp | 2 +- lib/Driver/ToolChains.h | 10 + lib/Driver/UnixToolChains.cpp | 4 + lib/Frontend/Frontend.cpp | 2 + lib/Option/SanitizerOptions.cpp | 2 +- lib/PrintAsObjC/DeclAndTypePrinter.cpp | 3 + lib/SymbolGraphGen/AvailabilityMixin.cpp | 2 + lib/TBDGen/TBDGen.cpp | 2 + stdlib/cmake/modules/AddSwiftStdlib.cmake | 8 + .../private/OSLog/OSLogFloatFormatting.swift | 2 +- .../OpaqueIdentityFunctions.swift | 2 +- .../private/StdlibUnittest/SymbolLookup.swift | 2 +- .../FloatingPointDifferentiation.swift.gyb | 2 +- .../TgmathDerivatives.swift.gyb | 4 +- stdlib/public/Platform/CMakeLists.txt | 18 +- stdlib/public/Platform/Glibc.swift.gyb | 2 +- .../Platform/libc-freebsd.modulemap.gyb | 311 ++++++++++++++++++ stdlib/public/Platform/tgmath.swift.gyb | 14 +- stdlib/public/SwiftShims/SwiftStdint.h | 2 +- stdlib/public/core/BuiltinMath.swift | 2 +- stdlib/public/core/FloatingPoint.swift | 4 +- .../core/FloatingPointParsing.swift.gyb | 2 +- .../public/core/FloatingPointTypes.swift.gyb | 6 +- stdlib/public/core/IntegerTypes.swift.gyb | 2 +- stdlib/public/core/Mirrors.swift | 2 +- stdlib/public/core/Policy.swift | 2 +- stdlib/public/core/Runtime.swift | 2 +- stdlib/public/core/VarArgs.swift | 2 +- .../differentiable_stdlib_conformances.swift | 2 +- test/AutoDiff/stdlib/floating_point.swift.gyb | 4 +- .../stdlib/tgmath_derivatives.swift.gyb | 4 +- .../class_differentiation.swift | 4 +- .../AutoDiff/validation-test/reflection.swift | 3 + test/ClangImporter/Dispatch_test.swift | 1 + test/ClangImporter/cfuncs_parse.swift | 2 +- test/ClangImporter/clang_builtin_pcm.swift | 3 + test/Driver/Dependencies/only-skip-once.swift | 2 +- test/Driver/embed-bitcode.swift | 2 + test/Driver/frontend.swift | 1 + test/Driver/linker-autolink-extract.swift | 1 + test/Driver/subcommands.swift | 2 + test/IDE/complete_decl_attribute.swift | 1 + test/IRGen/abitypes.swift | 2 +- test/IRGen/static_initializer.sil | 3 + test/Index/Store/driver-index.swift | 2 +- test/LinkerSections/function_sections.swift | 2 +- test/Parse/enum.swift | 1 + test/Prototypes/CollectionTransformers.swift | 2 +- test/Reflection/box_descriptors.sil | 1 + test/Reflection/capture_descriptors.sil | 1 + .../typeref_decoding_concurrency.swift | 4 + .../typeref_decoding_imported.swift | 1 + ...stic_constant_propagation_floats_x86.swift | 1 + test/Sanitizers/tsan/actor_counters.swift | 1 + test/Sanitizers/tsan/basic_future.swift | 2 + test/Sanitizers/tsan/mainactor.swift | 2 + test/Sanitizers/tsan/tsan.swift | 7 +- test/lit.cfg | 13 + test/stdlib/DispatchTypes.swift | 1 + test/stdlib/FloatingPoint.swift.gyb | 16 +- test/stdlib/FloatingPointIR_FP80.swift | 1 + .../Inputs/FloatingPointConversion.swift.gyb | 4 +- test/stdlib/NumericParsing.swift.gyb | 2 +- test/stdlib/NumericParsing2.swift.gyb | 2 +- test/stdlib/POSIX.swift | 9 +- test/stdlib/PrintFloat.swift.gyb | 10 +- test/stdlib/VarArgs.swift | 2 +- test/stdlib/simd_diagnostics.swift | 2 +- test/stdlib/tgmath.swift.gyb | 10 +- .../lib/SwiftLang/SwiftDocSupport.cpp | 3 + .../swift-dependency-tool.cpp | 4 +- 79 files changed, 528 insertions(+), 88 deletions(-) create mode 100644 stdlib/public/Platform/libc-freebsd.modulemap.gyb diff --git a/CMakeLists.txt b/CMakeLists.txt index 59c0b044d8dca..549c6307ff722 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,6 +177,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUA set(SWIFT_USE_LINKER_default "lld") elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) set(SWIFT_USE_LINKER_default "") +elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + set(SWIFT_USE_LINKER_default "") else() set(SWIFT_USE_LINKER_default "gold") endif() diff --git a/cmake/modules/SwiftConfigureSDK.cmake b/cmake/modules/SwiftConfigureSDK.cmake index 8a32c12abb126..c10447b6df0e4 100644 --- a/cmake/modules/SwiftConfigureSDK.cmake +++ b/cmake/modules/SwiftConfigureSDK.cmake @@ -347,11 +347,11 @@ macro(configure_sdk_unix name architectures) message(FATAL_ERROR "unsupported arch for FreeBSD: ${arch}") endif() - if(CMAKE_HOST_SYSTEM_NAME NOT STREQUAL FreeBSD) + if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL FreeBSD) message(WARNING "CMAKE_SYSTEM_VERSION will not match target") endif() - string(REPLACE "[-].*" "" freebsd_system_version ${CMAKE_SYSTEM_VERSION}) + string(REGEX REPLACE "[-].*" "" freebsd_system_version ${CMAKE_SYSTEM_VERSION}) message(STATUS "FreeBSD Version: ${freebsd_system_version}") set(SWIFT_SDK_FREEBSD_ARCH_x86_64_TRIPLE "x86_64-unknown-freebsd${freebsd_system_version}") diff --git a/include/swift/AST/AutoDiff.h b/include/swift/AST/AutoDiff.h index 044af2b8089cc..e2d67dd48e4f5 100644 --- a/include/swift/AST/AutoDiff.h +++ b/include/swift/AST/AutoDiff.h @@ -416,7 +416,14 @@ class DerivativeFunctionTypeError Kind kind; /// The type and index of a differentiability parameter or result. - using TypeAndIndex = std::pair; + /// std::pair does not have a trivial copy constructor on FreeBSD for ABI reasons, + /// so we have to define our own type here instead + struct TypeAndIndex { + Type first; + unsigned second; + + TypeAndIndex(Type type, unsigned index) : first(type), second(index) {} + }; private: union Value { diff --git a/include/swift/AST/PlatformKinds.def b/include/swift/AST/PlatformKinds.def index 017f09b7abe44..7aaeadc2aabea 100644 --- a/include/swift/AST/PlatformKinds.def +++ b/include/swift/AST/PlatformKinds.def @@ -32,6 +32,7 @@ AVAILABILITY_PLATFORM(watchOSApplicationExtension, "application extensions for w AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS") AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst") AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst") +AVAILABILITY_PLATFORM(FreeBSD, "FreeBSD") AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD") AVAILABILITY_PLATFORM(Windows, "Windows") diff --git a/include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h b/include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h index 63b9eb6eb824b..418a72279ea53 100644 --- a/include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h +++ b/include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h @@ -71,8 +71,15 @@ struct DifferentiationInvoker { /// The parent `apply` instruction and the witness associated with the /// `IndirectDifferentiation` case. - std::pair - indirectDifferentiation; + /// + /// Note: This used to be a std::pair, but on FreeBSD std::pair can't be + /// used here, because it does not have a trivial copy constructor. + struct IndirectDifferentiation { + ApplyInst *applyInst; + SILDifferentiabilityWitness *witness; + }; + IndirectDifferentiation indirectDifferentiation; + Value(ApplyInst *applyInst, SILDifferentiabilityWitness *witness) : indirectDifferentiation({applyInst, witness}) {} @@ -111,7 +118,8 @@ struct DifferentiationInvoker { std::pair getIndirectDifferentiation() const { assert(kind == Kind::IndirectDifferentiation); - return value.indirectDifferentiation; + return std::make_pair(value.indirectDifferentiation.applyInst, + value.indirectDifferentiation.witness); } SILDifferentiabilityWitness *getSILDifferentiabilityWitnessInvoker() const { diff --git a/lib/AST/PlatformKind.cpp b/lib/AST/PlatformKind.cpp index 1684f363d8272..1a248b4578e9c 100644 --- a/lib/AST/PlatformKind.cpp +++ b/lib/AST/PlatformKind.cpp @@ -89,6 +89,8 @@ static bool isPlatformActiveForTarget(PlatformKind Platform, return Target.isWatchOS(); case PlatformKind::OpenBSD: return Target.isOSOpenBSD(); + case PlatformKind::FreeBSD: + return Target.isOSFreeBSD(); case PlatformKind::Windows: return Target.isOSWindows(); case PlatformKind::none: diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index da32af4b45498..1874ce3750de8 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -5489,7 +5489,8 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType( if (!resultTan) { return llvm::make_error( this, DerivativeFunctionTypeError::Kind::NonDifferentiableResult, - std::make_pair(originalResultType, /*index*/ 0)); + DerivativeFunctionTypeError::TypeAndIndex( + originalResultType, /*index*/ 0)); } auto resultTanType = resultTan->getType(); @@ -5522,7 +5523,8 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType( this, DerivativeFunctionTypeError::Kind:: NonDifferentiableDifferentiabilityParameter, - std::make_pair(paramType, i)); + DerivativeFunctionTypeError::TypeAndIndex( + paramType, 0)); } differentialParams.push_back(AnyFunctionType::Param( paramTan->getType(), Identifier(), diffParam.getParameterFlags())); @@ -5563,7 +5565,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType( this, DerivativeFunctionTypeError::Kind:: NonDifferentiableDifferentiabilityParameter, - std::make_pair(paramType, i)); + DerivativeFunctionTypeError::TypeAndIndex(paramType, i)); } if (diffParam.isInOut()) { hasInoutDiffParameter = true; diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 950af90c83db5..d247be159dcb2 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -622,7 +622,7 @@ importer::getNormalInvocationArguments( // using Glibc or a libc that respects that flag. This will cause some // source breakage however (specifically with strerror_r()) on Linux // without a workaround. - if (triple.isOSFuchsia() || triple.isAndroid()) { + if (triple.isOSFuchsia() || triple.isAndroid() || triple.isOSFreeBSD()) { // Many of the modern libc features are hidden behind feature macros like // _GNU_SOURCE or _XOPEN_SOURCE. invocationArgStrs.insert(invocationArgStrs.end(), { @@ -658,7 +658,7 @@ importer::getNormalInvocationArguments( } } - if (searchPathOpts.SDKPath.empty()) { + if (searchPathOpts.SDKPath.empty() && !triple.isOSFreeBSD()) { invocationArgStrs.push_back("-Xclang"); invocationArgStrs.push_back("-nostdsysteminc"); } else { @@ -2069,6 +2069,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts) deprecatedAsUnavailableMessage = ""; break; + case PlatformKind::FreeBSD: + deprecatedAsUnavailableMessage = ""; + break; + case PlatformKind::Windows: deprecatedAsUnavailableMessage = ""; break; @@ -2108,6 +2112,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const { case PlatformKind::OpenBSD: return name == "openbsd"; + case PlatformKind::FreeBSD: + return name == "freebsd"; + case PlatformKind::Windows: return name == "windows"; @@ -2175,6 +2182,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable( // No deprecation filter on OpenBSD return false; + case PlatformKind::FreeBSD: + // No deprecation filter on FreeBSD + return false; + case PlatformKind::Windows: // No deprecation filter on Windows return false; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index c06cf49827727..13907840195a9 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -342,7 +342,7 @@ Driver::buildToolChain(const llvm::opt::InputArgList &ArgList) { return std::make_unique(*this, target); return std::make_unique(*this, target); case llvm::Triple::FreeBSD: - return std::make_unique(*this, target); + return std::make_unique(*this, target); case llvm::Triple::OpenBSD: return std::make_unique(*this, target); case llvm::Triple::Win32: diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 6421de437072d..50fed7947ee35 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -173,6 +173,16 @@ class LLVM_LIBRARY_VISIBILITY OpenBSD : public GenericUnix { ~OpenBSD() = default; }; +class LLVM_LIBRARY_VISIBILITY FreeBSD : public GenericUnix { +protected: + std::string getDefaultLinker() const override; + +public: + FreeBSD(const Driver &D, const llvm::Triple &Triple) + : GenericUnix(D, Triple) {} + ~FreeBSD() = default; +}; + } // end namespace toolchains } // end namespace driver } // end namespace swift diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index 30905f6b72253..518d0ff2257c7 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -410,3 +410,7 @@ std::string toolchains::Cygwin::getDefaultLinker() const { std::string toolchains::OpenBSD::getDefaultLinker() const { return "lld"; } + +std::string toolchains::FreeBSD::getDefaultLinker() const { + return "lld"; +} diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index f2cc65f78281d..755a416ead2f6 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -775,6 +775,8 @@ static bool shouldImportConcurrencyByDefault(const llvm::Triple &target) { #if SWIFT_IMPLICIT_CONCURRENCY_IMPORT if (target.isOSOpenBSD()) return true; + if (target.isOSFreeBSD()) + return true; #endif return false; } diff --git a/lib/Option/SanitizerOptions.cpp b/lib/Option/SanitizerOptions.cpp index 94a02095c363c..0a64e8e8a810e 100644 --- a/lib/Option/SanitizerOptions.cpp +++ b/lib/Option/SanitizerOptions.cpp @@ -162,7 +162,7 @@ OptionSet swift::parseSanitizerArgValues( } // Check that we're one of the known supported targets for sanitizers. - if (!(Triple.isOSDarwin() || Triple.isOSLinux() || Triple.isOSWindows())) { + if (!(Triple.isOSDarwin() || Triple.isOSLinux() || Triple.isOSWindows() || Triple.isOSFreeBSD())) { SmallString<128> b; Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target, (A->getOption().getPrefixedName() + diff --git a/lib/PrintAsObjC/DeclAndTypePrinter.cpp b/lib/PrintAsObjC/DeclAndTypePrinter.cpp index f66cd6ab4d1ff..0ac2555383318 100644 --- a/lib/PrintAsObjC/DeclAndTypePrinter.cpp +++ b/lib/PrintAsObjC/DeclAndTypePrinter.cpp @@ -875,6 +875,9 @@ class DeclAndTypePrinter::Implementation case PlatformKind::watchOSApplicationExtension: plat = "watchos_app_extension"; break; + case PlatformKind::FreeBSD: + plat = "freebsd"; + break; case PlatformKind::OpenBSD: plat = "openbsd"; break; diff --git a/lib/SymbolGraphGen/AvailabilityMixin.cpp b/lib/SymbolGraphGen/AvailabilityMixin.cpp index ba0789b29fedc..2723cd2cc591f 100644 --- a/lib/SymbolGraphGen/AvailabilityMixin.cpp +++ b/lib/SymbolGraphGen/AvailabilityMixin.cpp @@ -56,6 +56,8 @@ StringRef getDomain(const AvailableAttr &AvAttr) { return { "tvOSAppExtension" }; case swift::PlatformKind::watchOSApplicationExtension: return { "watchOSAppExtension" }; + case swift::PlatformKind::FreeBSD: + return { "FreeBSD" }; case swift::PlatformKind::OpenBSD: return { "OpenBSD" }; case swift::PlatformKind::Windows: diff --git a/lib/TBDGen/TBDGen.cpp b/lib/TBDGen/TBDGen.cpp index 18df9736c3a27..53c768bdef964 100644 --- a/lib/TBDGen/TBDGen.cpp +++ b/lib/TBDGen/TBDGen.cpp @@ -238,6 +238,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) { switch(Ver.Platform) { case swift::PlatformKind::none: llvm_unreachable("cannot find platform kind"); + case swift::PlatformKind::FreeBSD: + llvm_unreachable("not used for this platform"); case swift::PlatformKind::OpenBSD: llvm_unreachable("not used for this platform"); case swift::PlatformKind::Windows: diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index 6953da2a438c8..65ae5227658b3 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -290,6 +290,10 @@ function(_add_target_variant_c_compile_flags) endif() endif() + if("${CFLAGS_SDK}" STREQUAL "FREEBSD") + list(APPEND result "-D_GNU_SOURCE") + endif() + if("${CFLAGS_SDK}" STREQUAL "WASI") list(APPEND result "-D_WASI_EMULATED_MMAN") endif() @@ -976,6 +980,10 @@ function(_add_swift_target_library_single target name) set_target_properties("${target}" PROPERTIES INSTALL_RPATH "$ORIGIN") + elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "FREEBSD") + set_target_properties("${target}" + PROPERTIES + INSTALL_RPATH "$ORIGIN") elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "CYGWIN") set_target_properties("${target}" PROPERTIES diff --git a/stdlib/private/OSLog/OSLogFloatFormatting.swift b/stdlib/private/OSLog/OSLogFloatFormatting.swift index 8397f849e5abb..eeaa63296b39c 100644 --- a/stdlib/private/OSLog/OSLogFloatFormatting.swift +++ b/stdlib/private/OSLog/OSLogFloatFormatting.swift @@ -350,7 +350,7 @@ extension OSLogFloatFormatting { // fprintf formatters promote Float to Double case is Float.Type: return "" case is Double.Type: return "" -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) // fprintf formatters use L for Float80 case is Float80.Type: return "L" #endif diff --git a/stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift b/stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift index 92c839ee86c46..556f98f9e5411 100644 --- a/stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift +++ b/stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift @@ -77,7 +77,7 @@ public func getFloat32(_ x: Float32) -> Float32 { return _opaqueIdentity(x) } @inline(never) public func getFloat64(_ x: Float64) -> Float64 { return _opaqueIdentity(x) } -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) @inline(never) public func getFloat80(_ x: Float80) -> Float80 { return _opaqueIdentity(x) } #endif diff --git a/stdlib/private/StdlibUnittest/SymbolLookup.swift b/stdlib/private/StdlibUnittest/SymbolLookup.swift index 5cab6a1ac5c1b..4bde3ee02df45 100644 --- a/stdlib/private/StdlibUnittest/SymbolLookup.swift +++ b/stdlib/private/StdlibUnittest/SymbolLookup.swift @@ -21,7 +21,7 @@ #error("Unsupported platform") #endif -#if canImport(Darwin) || os(OpenBSD) +#if canImport(Darwin) || os(FreeBSD) || os(OpenBSD) let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2) #elseif os(Linux) let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: 0) diff --git a/stdlib/public/Differentiation/FloatingPointDifferentiation.swift.gyb b/stdlib/public/Differentiation/FloatingPointDifferentiation.swift.gyb index 627dbd07863bb..7d49bb92db879 100644 --- a/stdlib/public/Differentiation/FloatingPointDifferentiation.swift.gyb +++ b/stdlib/public/Differentiation/FloatingPointDifferentiation.swift.gyb @@ -26,7 +26,7 @@ def Availability(bits): }% % if bits == 80: -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end % if bits == 16: #if !os(macOS) && !(os(iOS) && targetEnvironment(macCatalyst)) diff --git a/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb b/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb index d5ef6502aed4c..21d5cc95b88d5 100644 --- a/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb +++ b/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb @@ -135,7 +135,7 @@ func _${derivative_kind}Trunc ( % linear_map_kind = 'differential' if derivative_kind == 'jvp' else 'pullback' % for T in ['Float', 'Double', 'Float80']: % if T == 'Float80': -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end @inlinable @derivative(of: exp) @@ -276,7 +276,7 @@ func _${derivative_kind}Erfc(_ x: ${T}) -> (value: ${T}, ${linear_map_kind}: (${ // Binary functions %for T in ['Float', 'Float80']: % if T == 'Float80': -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end @inlinable @derivative(of: pow) diff --git a/stdlib/public/Platform/CMakeLists.txt b/stdlib/public/Platform/CMakeLists.txt index a7a60a063d9aa..13e69d18a07fc 100644 --- a/stdlib/public/Platform/CMakeLists.txt +++ b/stdlib/public/Platform/CMakeLists.txt @@ -84,6 +84,8 @@ foreach(sdk ${SWIFT_SDKS}) set(glibc_modulemap_source "bionic.modulemap.gyb") elseif(${sdk} STREQUAL OPENBSD) set(glibc_modulemap_source "libc-openbsd.modulemap.gyb") + elseif(${sdk} STREQUAL FREEBSD) + set(glibc_modulemap_source "libc-freebsd.modulemap.gyb") else() set(glibc_modulemap_source "glibc.modulemap.gyb") endif() @@ -119,12 +121,16 @@ foreach(sdk ${SWIFT_SDKS}) list(APPEND glibc_modulemap_target_list ${copy_glibc_modulemap_static}) endif() - set(glibc_header_out "${module_dir}/SwiftGlibc.h") - handle_gyb_source_single(glibc_header_target - SOURCE "SwiftGlibc.h.gyb" - OUTPUT "${glibc_header_out}" - FLAGS "-DCMAKE_SDK=${sdk}") - list(APPEND glibc_modulemap_target_list ${glibc_header_target}) + # FreeBSD uses a different module map that does not use this header, + # so we don't generate it + if(NOT ${sdk} STREQUAL FREEBSD) + set(glibc_header_out "${module_dir}/SwiftGlibc.h") + handle_gyb_source_single(glibc_header_target + SOURCE "SwiftGlibc.h.gyb" + OUTPUT "${glibc_header_out}" + FLAGS "-DCMAKE_SDK=${sdk}") + list(APPEND glibc_modulemap_target_list ${glibc_header_target}) + endif() # If this SDK is a target for a non-native host, except if it's for Android # with its own native sysroot, create a native modulemap without a sysroot diff --git a/stdlib/public/Platform/Glibc.swift.gyb b/stdlib/public/Platform/Glibc.swift.gyb index 2de990adfffaf..aabd9090786b3 100644 --- a/stdlib/public/Platform/Glibc.swift.gyb +++ b/stdlib/public/Platform/Glibc.swift.gyb @@ -36,7 +36,7 @@ public let FLT_RADIX = Double.radix %for type, prefix in [('Float', 'FLT'), ('Double', 'DBL'), ('Float80', 'LDBL')]: % if type == "Float80": -#if !os(Android) && (arch(i386) || arch(x86_64)) +#if !(os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end // Where does the 1 come from? C counts the usually-implicit leading // significand bit, but Swift does not. Neither is really right or wrong. diff --git a/stdlib/public/Platform/libc-freebsd.modulemap.gyb b/stdlib/public/Platform/libc-freebsd.modulemap.gyb new file mode 100644 index 0000000000000..835b2547d2163 --- /dev/null +++ b/stdlib/public/Platform/libc-freebsd.modulemap.gyb @@ -0,0 +1,311 @@ +//===--- libc-freebsd.modulemap.gyb ----------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +/// Partial modulemap for libc on FreeBSD based on 13.0-RELEASE-p1. +module SwiftGlibc [system] { + link "pthread" + link "util" + + // C standard library + module C { + module complex { + header "${GLIBC_INCLUDE_PATH}/complex.h" + export * + } + module ctype { + header "${GLIBC_INCLUDE_PATH}/ctype.h" + export * + } + module errno { + header "${GLIBC_INCLUDE_PATH}/errno.h" + export * + } + module fenv { + header "${GLIBC_INCLUDE_PATH}/fenv.h" + export * + } + module inttypes { + header "${GLIBC_INCLUDE_PATH}/inttypes.h" + export * + } + module locale { + header "${GLIBC_INCLUDE_PATH}/locale.h" + export * + } + module math { + link "m" + header "${GLIBC_INCLUDE_PATH}/math.h" + export * + } + module setjmp { + header "${GLIBC_INCLUDE_PATH}/setjmp.h" + export * + } + module signal { + header "${GLIBC_INCLUDE_PATH}/signal.h" + export * + } + + module stdio { + header "${GLIBC_INCLUDE_PATH}/stdio.h" + export * + } + module stdlib { + header "${GLIBC_INCLUDE_PATH}/stdlib.h" + export * + export stddef + } + module stdint { + header "${GLIBC_INCLUDE_PATH}/stdint.h" + export * + } + module string { + header "${GLIBC_INCLUDE_PATH}/string.h" + export * + } + module time { + header "${GLIBC_INCLUDE_PATH}/time.h" + export * + } + } + + // POSIX + module POSIX { + module cpio { + header "${GLIBC_INCLUDE_PATH}/cpio.h" + export * + } + module nl_types { + header "${GLIBC_INCLUDE_PATH}/nl_types.h" + export * + } + module ftw { + header "${GLIBC_INCLUDE_PATH}/ftw.h" + export * + } + module glob { + header "${GLIBC_INCLUDE_PATH}/glob.h" + export * + } + module langinfo { + header "${GLIBC_INCLUDE_PATH}/langinfo.h" + export * + } + module netdb { + header "${GLIBC_INCLUDE_PATH}/netdb.h" + export * + } + module ifaddrs { + header "${GLIBC_INCLUDE_PATH}/ifaddrs.h" + export * + } + module search { + header "${GLIBC_INCLUDE_PATH}/search.h" + export * + } + module spawn { + header "${GLIBC_INCLUDE_PATH}/spawn.h" + export * + } + module syslog { + header "${GLIBC_INCLUDE_PATH}/syslog.h" + export * + } + module tar { + header "${GLIBC_INCLUDE_PATH}/tar.h" + export * + } + module arpa { + module inet { + header "${GLIBC_INCLUDE_PATH}/arpa/inet.h" + export * + } + export * + } + module dirent { + header "${GLIBC_INCLUDE_PATH}/dirent.h" + export * + } + module dl { + header "${GLIBC_INCLUDE_PATH}/link.h" + export * + } + module dlfcn { + header "${GLIBC_INCLUDE_PATH}/dlfcn.h" + export * + } + module fcntl { + header "${GLIBC_INCLUDE_PATH}/fcntl.h" + export * + } + module fnmatch { + header "${GLIBC_INCLUDE_PATH}/fnmatch.h" + export * + } + module grp { + header "${GLIBC_INCLUDE_PATH}/grp.h" + export * + } + module ioctl { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/ioctl.h" + export * + } + module libgen { + header "${GLIBC_INCLUDE_PATH}/libgen.h" + export * + } + module net { + module if { + header "${GLIBC_INCLUDE_PATH}/net/if.h" + export * + } + } + module netinet { + module in { + header "${GLIBC_INCLUDE_PATH}/netinet/in.h" + export * + + exclude header "${GLIBC_INCLUDE_PATH}/netinet6/in6.h" + } + module tcp { + header "${GLIBC_INCLUDE_PATH}/netinet/tcp.h" + export * + } + } + module poll { + header "${GLIBC_INCLUDE_PATH}/poll.h" + export * + } + module pthread { + header "${GLIBC_INCLUDE_PATH}/pthread.h" + export * + } + module pwd { + header "${GLIBC_INCLUDE_PATH}/pwd.h" + export * + } + module regex { + header "${GLIBC_INCLUDE_PATH}/regex.h" + export * + } + module sched { + header "${GLIBC_INCLUDE_PATH}/sched.h" + export * + } + module semaphore { + header "${GLIBC_INCLUDE_PATH}/semaphore.h" + export * + } + module strings { + header "${GLIBC_INCLUDE_PATH}/strings.h" + export * + } + + module sys { + export * + + module file { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/file.h" + export * + } + module sem { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/sem.h" + export * + } + module shm { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/shm.h" + export * + } + module statvfs { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/statvfs.h" + export * + } + module ipc { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/ipc.h" + export * + } + module mman { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/mman.h" + export * + } + module msg { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/msg.h" + export * + } + module resource { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/resource.h" + export * + } + module select { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/select.h" + export * + } + module socket { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/socket.h" + export * + } + module stat { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/stat.h" + export * + } + module time { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/time.h" + export * + } + module times { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/times.h" + export * + } + module types { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/types.h" + export * + } + module event { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/event.h" + export * + } + module uio { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/uio.h" + export * + } + module un { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/un.h" + export * + } + module user { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/user.h" + export * + } + module utsname { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/utsname.h" + export * + } + module wait { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/wait.h" + export * + } + } + module termios { + header "${GLIBC_INCLUDE_PATH}/termios.h" + export * + } + module unistd { + header "${GLIBC_INCLUDE_PATH}/unistd.h" + export * + } + } +} + +module CUUID [system] { + header "${GLIBC_INCLUDE_PATH}/uuid.h" + export * +} diff --git a/stdlib/public/Platform/tgmath.swift.gyb b/stdlib/public/Platform/tgmath.swift.gyb index cf8c9fa88069b..558258ce9550c 100644 --- a/stdlib/public/Platform/tgmath.swift.gyb +++ b/stdlib/public/Platform/tgmath.swift.gyb @@ -222,7 +222,7 @@ def TypedBinaryFunctions(): // Note these do not have a corresponding LLVM intrinsic % for T, CT, f, ufunc in TypedUnaryFunctions(): % if T == 'Float80': -#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android)) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(FreeBSD)) % end @_transparent public func ${ufunc}(_ x: ${T}) -> ${T} { @@ -239,7 +239,7 @@ public func ${ufunc}(_ x: ${T}) -> ${T} { // Note these have a corresponding LLVM intrinsic % for T, ufunc in TypedUnaryIntrinsicFunctions(): % if T == 'Float80': -#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android)) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(FreeBSD)) % end @_transparent public func ${ufunc}(_ x: ${T}) -> ${T} { @@ -258,7 +258,7 @@ public func ${ufunc}(_ x: ${T}) -> ${T} { % for ufunc in UnaryIntrinsicFunctions: % for T, CT, f in OverlayFloatTypes(): % if T == 'Float80': -#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android)) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(FreeBSD)) % end @_transparent public func ${ufunc}(_ x: ${T}) -> ${T} { @@ -275,7 +275,7 @@ public func ${ufunc}(_ x: ${T}) -> ${T} { % for T, CT, f, bfunc in TypedBinaryFunctions(): % if T == 'Float80': -#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android)) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(FreeBSD)) % end @_transparent public func ${bfunc}(_ lhs: ${T}, _ rhs: ${T}) -> ${T} { @@ -290,7 +290,7 @@ public func ${bfunc}(_ lhs: ${T}, _ rhs: ${T}) -> ${T} { % # This is AllFloatTypes not OverlayFloatTypes because of the tuple return. % for T, CT, f in AllFloatTypes(): % if T == 'Float80': -#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(OpenBSD)) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(FreeBSD) || os(OpenBSD)) % else: // lgamma not available on Windows, apparently? #if !os(Windows) @@ -308,7 +308,7 @@ public func lgamma(_ x: ${T}) -> (${T}, Int) { % # This is AllFloatTypes not OverlayFloatTypes because of the tuple return. % for T, CT, f in AllFloatTypes(): % if T == 'Float80': -#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android)) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(FreeBSD)) % end @_transparent public func remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) { @@ -324,7 +324,7 @@ public func remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) { % for T, CT, f in OverlayFloatTypes(): % if T == 'Float80': -#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android)) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(FreeBSD)) % end @available(swift, deprecated: 4.2/*, obsoleted: 5.1*/, message: "use ${T}(nan: ${T}.RawSignificand).") diff --git a/stdlib/public/SwiftShims/SwiftStdint.h b/stdlib/public/SwiftShims/SwiftStdint.h index 7b83e90d72799..1d030dbbad58f 100644 --- a/stdlib/public/SwiftShims/SwiftStdint.h +++ b/stdlib/public/SwiftShims/SwiftStdint.h @@ -24,7 +24,7 @@ // Clang has been defining __INTxx_TYPE__ macros for a long time. // __UINTxx_TYPE__ are defined only since Clang 3.5. -#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) +#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) #include typedef int64_t __swift_int64_t; typedef uint64_t __swift_uint64_t; diff --git a/stdlib/public/core/BuiltinMath.swift b/stdlib/public/core/BuiltinMath.swift index 762da5135f640..d9437377d7554 100644 --- a/stdlib/public/core/BuiltinMath.swift +++ b/stdlib/public/core/BuiltinMath.swift @@ -113,7 +113,7 @@ public func _rint(_ x: Double) -> Double { // Float80 Intrinsics (80 bits) -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) @_transparent public func _cos(_ x: Float80) -> Float80 { return Float80(Builtin.int_cos_FPIEEE80(x._value)) diff --git a/stdlib/public/core/FloatingPoint.swift b/stdlib/public/core/FloatingPoint.swift index a62c2be9c2bbe..b870b725a8cd4 100644 --- a/stdlib/public/core/FloatingPoint.swift +++ b/stdlib/public/core/FloatingPoint.swift @@ -1514,7 +1514,7 @@ public protocol BinaryFloatingPoint: FloatingPoint, ExpressibleByFloatLiteral { /// - Parameter value: A floating-point value to be converted. init(_ value: Double) -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) /// Creates a new instance from the given value, rounded to the closest /// possible representation. /// @@ -1924,7 +1924,7 @@ extension BinaryFloatingPoint { significandBitPattern: UInt64(truncatingIfNeeded: value.significandBitPattern)) self = Self(value_) -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) case (15, 63): let value_ = value as? Float80 ?? Float80( sign: value.sign, diff --git a/stdlib/public/core/FloatingPointParsing.swift.gyb b/stdlib/public/core/FloatingPointParsing.swift.gyb index 20a9351cadfa9..047466ee1cbbe 100644 --- a/stdlib/public/core/FloatingPointParsing.swift.gyb +++ b/stdlib/public/core/FloatingPointParsing.swift.gyb @@ -41,7 +41,7 @@ internal func _isspace_clocale(_ u: UTF16.CodeUnit) -> Bool { % Self = floatName(bits) % if bits == 80: -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % elif bits == 16: #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) % end diff --git a/stdlib/public/core/FloatingPointTypes.swift.gyb b/stdlib/public/core/FloatingPointTypes.swift.gyb index d747b74a8cbb4..345e43f6fabc8 100644 --- a/stdlib/public/core/FloatingPointTypes.swift.gyb +++ b/stdlib/public/core/FloatingPointTypes.swift.gyb @@ -64,7 +64,7 @@ else: }% % if bits == 80: -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % elif bits == 16: #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) % end @@ -915,7 +915,7 @@ extension ${Self}: _ExpressibleByBuiltinIntegerLiteral, ExpressibleByIntegerLite } % if bits != 80: -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end % builtinFloatLiteralBits = 80 @@ -1121,7 +1121,7 @@ extension ${Self} { % That = src_type.stdlib_name % if srcBits == 80: -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % elif srcBits == 16: #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) % end diff --git a/stdlib/public/core/IntegerTypes.swift.gyb b/stdlib/public/core/IntegerTypes.swift.gyb index b4b2083b9df0d..8a51182324d3e 100644 --- a/stdlib/public/core/IntegerTypes.swift.gyb +++ b/stdlib/public/core/IntegerTypes.swift.gyb @@ -1128,7 +1128,7 @@ public struct ${Self} % (lower, upper) = getFtoIBounds(floatBits=FloatBits, intBits=int(bits), signed=signed) % if FloatType == 'Float80': -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % elif FloatType == 'Float16': #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) % end diff --git a/stdlib/public/core/Mirrors.swift b/stdlib/public/core/Mirrors.swift index 171adc99673f6..2ab9c247a650e 100644 --- a/stdlib/public/core/Mirrors.swift +++ b/stdlib/public/core/Mirrors.swift @@ -250,7 +250,7 @@ extension Int: _CustomPlaygroundQuickLookable { } } -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) extension Float80: CustomReflectable { /// A mirror that reflects the Float80 instance. public var customMirror: Mirror { diff --git a/stdlib/public/core/Policy.swift b/stdlib/public/core/Policy.swift index 5cd9435261271..271e7a3d857c5 100644 --- a/stdlib/public/core/Policy.swift +++ b/stdlib/public/core/Policy.swift @@ -109,7 +109,7 @@ public typealias StringLiteralType = String //===----------------------------------------------------------------------===// // Default types for unconstrained number literals //===----------------------------------------------------------------------===// -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) public typealias _MaxBuiltinFloatType = Builtin.FPIEEE80 #else public typealias _MaxBuiltinFloatType = Builtin.FPIEEE64 diff --git a/stdlib/public/core/Runtime.swift b/stdlib/public/core/Runtime.swift index 7df18bd78a232..f33ae6f08eb3c 100644 --- a/stdlib/public/core/Runtime.swift +++ b/stdlib/public/core/Runtime.swift @@ -367,7 +367,7 @@ internal func _float64ToString( } -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) // Returns a UInt64, but that value is the length of the string, so it's // guaranteed to fit into an Int. This is part of the ABI, so we can't diff --git a/stdlib/public/core/VarArgs.swift b/stdlib/public/core/VarArgs.swift index 1f875b777be33..8a76f2ab51186 100644 --- a/stdlib/public/core/VarArgs.swift +++ b/stdlib/public/core/VarArgs.swift @@ -411,7 +411,7 @@ extension Double: _CVarArgPassedAsDouble, _CVarArgAligned { } } -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) extension Float80: CVarArg, _CVarArgAligned { /// Transform `self` into a series of machine words that can be /// appropriately interpreted by C varargs. diff --git a/test/AutoDiff/stdlib/differentiable_stdlib_conformances.swift b/test/AutoDiff/stdlib/differentiable_stdlib_conformances.swift index 21fc2137c28d0..0f0d15d2d28f6 100644 --- a/test/AutoDiff/stdlib/differentiable_stdlib_conformances.swift +++ b/test/AutoDiff/stdlib/differentiable_stdlib_conformances.swift @@ -14,7 +14,7 @@ where T: Differentiable, T == T.TangentVector {} func testFloatingPointDifferentiableConformance() { assertSelfEqualsTangentVector(Float.self) assertSelfEqualsTangentVector(Double.self) - #if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android)) + #if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(FreeBSD)) assertSelfEqualsTangentVector(Float80.self) #endif } diff --git a/test/AutoDiff/stdlib/floating_point.swift.gyb b/test/AutoDiff/stdlib/floating_point.swift.gyb index de94184c4f62f..41318b58140fb 100644 --- a/test/AutoDiff/stdlib/floating_point.swift.gyb +++ b/test/AutoDiff/stdlib/floating_point.swift.gyb @@ -1,7 +1,7 @@ // RUN: %target-run-simple-swiftgyb(-Xfrontend -enable-experimental-forward-mode-differentiation) // REQUIRES: executable_test -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) typealias TestLiteralType = Float80 #else typealias TestLiteralType = Double @@ -31,7 +31,7 @@ func expectEqualWithTolerance(_ expected: TestLiteralType, _ actual: T, %for Self in ['Float', 'Double', 'Float80']: %if Self == 'Float80': -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) %end FloatingPointDerivativeTests.test("${Self}.+") { diff --git a/test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb b/test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb index e9b397a89256b..787a75f86a31b 100644 --- a/test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb +++ b/test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb @@ -11,7 +11,7 @@ #error("Unsupported platform") #endif -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) typealias TestLiteralType = Float80 #else typealias TestLiteralType = Double @@ -78,7 +78,7 @@ where T == T.TangentVector { %for T in ['Float', 'Float80']: %if T == 'Float80': -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) %end DerivativeTests.test("${op}_${T}") { diff --git a/test/AutoDiff/validation-test/class_differentiation.swift b/test/AutoDiff/validation-test/class_differentiation.swift index bc3f4b926eb4a..0d93606d0cd04 100644 --- a/test/AutoDiff/validation-test/class_differentiation.swift +++ b/test/AutoDiff/validation-test/class_differentiation.swift @@ -390,7 +390,7 @@ ClassTests.test("ClassMethods - generic") { } } -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) class SubSpecializeOverrideCustomDerivatives: Super { @differentiable(reverse, wrt: x) override func f(_ x: Tracked) -> Tracked { @@ -422,7 +422,7 @@ ClassTests.test("ClassMethods - generic") { expectEqual((1, 1), classValueWithGradient(SubOverride())) expectEqual((3, 3), classValueWithGradient(SubSpecializeOverride())) expectEqual((3, 3), classValueWithGradient(SubOverrideCustomDerivatives())) -#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(Android) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) expectEqual((3, 3), classValueWithGradient(SubSpecializeOverrideCustomDerivatives())) #endif } diff --git a/test/AutoDiff/validation-test/reflection.swift b/test/AutoDiff/validation-test/reflection.swift index e938506bab687..1139d99cc585a 100644 --- a/test/AutoDiff/validation-test/reflection.swift +++ b/test/AutoDiff/validation-test/reflection.swift @@ -2,6 +2,9 @@ // RUN: %empty-directory(%t) import _Differentiation +// SR-12893 +// XFAIL: freebsd + // RUN: %target-build-swift -Xfrontend -enable-anonymous-context-mangled-names %S/Inputs/AutoDiffTypes.swift -parse-as-library -emit-module -emit-library -module-name TypesToReflect -o %t/%target-library-name(TypesToReflect) // RUN: %target-build-swift -Xfrontend -enable-anonymous-context-mangled-names %S/Inputs/AutoDiffTypes.swift %S/Inputs/main.swift -emit-module -emit-executable -module-name TypesToReflect -o %t/TypesToReflect diff --git a/test/ClangImporter/Dispatch_test.swift b/test/ClangImporter/Dispatch_test.swift index 81a60f3d93768..4d58f4d82e1e9 100644 --- a/test/ClangImporter/Dispatch_test.swift +++ b/test/ClangImporter/Dispatch_test.swift @@ -4,6 +4,7 @@ // UNSUPPORTED: OS=linux-gnu // UNSUPPORTED: OS=linux-android // UNSUPPORTED: OS=openbsd +// UNSUPPORTED: OS=freebsd import Dispatch diff --git a/test/ClangImporter/cfuncs_parse.swift b/test/ClangImporter/cfuncs_parse.swift index 746dce15787b3..49dade07b7f3e 100644 --- a/test/ClangImporter/cfuncs_parse.swift +++ b/test/ClangImporter/cfuncs_parse.swift @@ -64,7 +64,7 @@ func test_pow() { pow(1.5, 2.5) } -#if !((os(Android) || os(Linux)) && arch(arm64)) +#if !((os(Android) || os(Linux)) && arch(arm64)) && !os(FreeBSD) // long doubles in AAPCS64 are 128 bits, which is not supported by // Swift, so don't test this. SR-9072. func test_powl() { diff --git a/test/ClangImporter/clang_builtin_pcm.swift b/test/ClangImporter/clang_builtin_pcm.swift index 4f4d90c8fa8b3..0adf69b5461d9 100644 --- a/test/ClangImporter/clang_builtin_pcm.swift +++ b/test/ClangImporter/clang_builtin_pcm.swift @@ -4,6 +4,9 @@ // RUN: %target-swift-frontend -typecheck -verify -module-cache-path %t/clang-module-cache %s // RUN: ls -lR %t/clang-module-cache | %FileCheck %s +// fails on FreeBSD because `size_t` is not in scope +// XFAIL: freebsd + // CHECK: _Builtin_intrinsics{{.*}}.pcm import _Builtin_intrinsics diff --git a/test/Driver/Dependencies/only-skip-once.swift b/test/Driver/Dependencies/only-skip-once.swift index 314c29f752b14..403e15e6fd53e 100644 --- a/test/Driver/Dependencies/only-skip-once.swift +++ b/test/Driver/Dependencies/only-skip-once.swift @@ -1,4 +1,4 @@ -// XFAIL: linux, openbsd, windows +// XFAIL: linux, freebsd, openbsd, windows // RUN: %empty-directory(%t) // RUN: cp -r %S/Inputs/only-skip-once/* %t diff --git a/test/Driver/embed-bitcode.swift b/test/Driver/embed-bitcode.swift index 1b21eedd0c01b..7ff10a66a1ca2 100644 --- a/test/Driver/embed-bitcode.swift +++ b/test/Driver/embed-bitcode.swift @@ -1,3 +1,5 @@ +// UNSUPPORTED: freebsd + // RUN: %target-swiftc_driver -driver-print-bindings -embed-bitcode %s 2>&1 | %FileCheck -check-prefix=CHECK-%target-object-format %s // CHECK-macho: "swift-frontend", inputs: ["{{.*}}embed-bitcode.swift"], output: {llvm-bc: "[[BC:.*\.bc]]"} // CHECK-macho: "swift-frontend", inputs: ["[[BC]]"], output: {object: "[[OBJECT:.*\.o]]"} diff --git a/test/Driver/frontend.swift b/test/Driver/frontend.swift index f0ee617810814..ace5c05e42cd8 100644 --- a/test/Driver/frontend.swift +++ b/test/Driver/frontend.swift @@ -1,5 +1,6 @@ // RUN: %swiftc_driver %s -### 2>&1 | %FileCheck %s // UNSUPPORTED: windows +// UNSUPPORTED: freebsd // CHECK: swift-frontend diff --git a/test/Driver/linker-autolink-extract.swift b/test/Driver/linker-autolink-extract.swift index 907607af0486d..1f210ed30bb36 100644 --- a/test/Driver/linker-autolink-extract.swift +++ b/test/Driver/linker-autolink-extract.swift @@ -1,6 +1,7 @@ // RUN: %swiftc_driver -driver-print-jobs -target x86_64-unknown-linux-gnu -g %s | %FileCheck -check-prefix DEBUG_LINUX %s // REQUIRES: autolink-extract +// UNSUPPORTED: freebsd // DEBUG_LINUX: bin/swift // DEBUG_LINUX-NEXT: bin/swift-autolink-extract diff --git a/test/Driver/subcommands.swift b/test/Driver/subcommands.swift index 14024c71579fb..1108193469621 100644 --- a/test/Driver/subcommands.swift +++ b/test/Driver/subcommands.swift @@ -1,6 +1,8 @@ // REQUIRES: shell // Check that 'swift' and 'swift repl' invoke the REPL. +// UNSUPPORTED: freebsd + // RUN: rm -rf %t.dir // RUN: mkdir -p %t.dir/usr/bin // RUN: %hardlink-or-copy(from: %swift_frontend_plain, to: %t.dir/usr/bin/swift) diff --git a/test/IDE/complete_decl_attribute.swift b/test/IDE/complete_decl_attribute.swift index 9b7fda53c7167..4537ddb4a82ef 100644 --- a/test/IDE/complete_decl_attribute.swift +++ b/test/IDE/complete_decl_attribute.swift @@ -39,6 +39,7 @@ struct MyStruct {} // AVAILABILITY1-NEXT: Keyword/None: macOSApplicationExtension[#Platform#]; name=macOSApplicationExtension{{$}} // AVAILABILITY1-NEXT: Keyword/None: macCatalyst[#Platform#]; name=macCatalyst // AVAILABILITY1-NEXT: Keyword/None: macCatalystApplicationExtension[#Platform#]; name=macCatalystApplicationExtension +// AVAILABILITY1-NEXT: Keyword/None: FreeBSD[#Platform#]; name=FreeBSD{{$}} // AVAILABILITY1-NEXT: Keyword/None: OpenBSD[#Platform#]; name=OpenBSD{{$}} // AVAILABILITY1-NEXT: Keyword/None: Windows[#Platform#]; name=Windows{{$}} // AVAILABILITY1-NEXT: End completions diff --git a/test/IRGen/abitypes.swift b/test/IRGen/abitypes.swift index 1b6e28275fdaa..e905d08855e70 100644 --- a/test/IRGen/abitypes.swift +++ b/test/IRGen/abitypes.swift @@ -1,7 +1,7 @@ // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/abi %s -emit-ir -enable-objc-interop | %FileCheck -check-prefix=%target-cpu-%target-os-abi %s // FIXME: rdar://problem/19648117 Needs splitting objc parts out -// XFAIL: linux, windows, openbsd +// XFAIL: linux, windows, openbsd, freebsd import gadget import Foundation diff --git a/test/IRGen/static_initializer.sil b/test/IRGen/static_initializer.sil index a7a1863049a32..834d6cc8ebc7d 100644 --- a/test/IRGen/static_initializer.sil +++ b/test/IRGen/static_initializer.sil @@ -2,6 +2,9 @@ // REQUIRES: CPU=x86_64 +// fails on FreeBSD because T18static_initializer16TestArrayStorageC_tailelems1c is [1 x i64] instead of [2 x i64] +// XFAIL: freebsd + // Generated from // var x : Int32 = 2 // public func f() -> Int32 { return x } diff --git a/test/Index/Store/driver-index.swift b/test/Index/Store/driver-index.swift index a45c4f0daaf48..0b274a9d6d774 100644 --- a/test/Index/Store/driver-index.swift +++ b/test/Index/Store/driver-index.swift @@ -1,2 +1,2 @@ // RUN: %swiftc_driver -driver-print-jobs -index-file -index-file-path %s %S/Inputs/SwiftModuleA.swift %s -o %t.output_for_index -index-store-path %t.index_store -module-name driver_index 2>&1 | %FileCheck %s -// CHECK: {{.*}}swift{{(-frontend)?(c\.exe")?}} -frontend -typecheck {{.*}}SwiftModuleA.swift{{"?}} -primary-file {{.*}}driver-index.swift{{"?}} {{.*}}-o {{.*}}.output_for_index{{"?}} {{.*}}-disable-typo-correction {{.*}}-index-store-path {{.*}}.index_store{{"?}} -index-system-modules +// CHECK: {{.*}}swift{{(-frontend)?c?(\.exe")?}} -frontend -typecheck {{.*}}SwiftModuleA.swift{{"?}} -primary-file {{.*}}driver-index.swift{{"?}} {{.*}}-o {{.*}}.output_for_index{{"?}} {{.*}}-disable-typo-correction {{.*}}-index-store-path {{.*}}.index_store{{"?}} -index-system-modules diff --git a/test/LinkerSections/function_sections.swift b/test/LinkerSections/function_sections.swift index eb01d59563ea7..5db63fa3ca9d5 100644 --- a/test/LinkerSections/function_sections.swift +++ b/test/LinkerSections/function_sections.swift @@ -1,4 +1,4 @@ -// REQUIRES: OS=linux-gnu || OS=linux-androideabi || OS=linux-android || OS=freebsd +// REQUIRES: OS=linux-gnu || OS=linux-androideabi || OS=linux-android // RUN: %empty-directory(%t) // RUN: %target-build-swift -Xfrontend -function-sections -emit-module -emit-library -static -parse-stdlib %S/Inputs/FunctionSections.swift // RUN: %target-build-swift -Xlinker --gc-sections -Xlinker -Map=%t/../../FunctionSections.map -I%t/../.. -L%t/../.. -lFunctionSections %S/Inputs/FunctionSectionsUse.swift diff --git a/test/Parse/enum.swift b/test/Parse/enum.swift index 83bee6d5464a3..12bc7589388dc 100644 --- a/test/Parse/enum.swift +++ b/test/Parse/enum.swift @@ -7,6 +7,7 @@ // Windows does not support FP80 // XFAIL: OS=windows-msvc +// XFAIL: OS=freebsd enum Empty {} diff --git a/test/Prototypes/CollectionTransformers.swift b/test/Prototypes/CollectionTransformers.swift index 84dcafe4c04c6..1df3f2f3594ce 100644 --- a/test/Prototypes/CollectionTransformers.swift +++ b/test/Prototypes/CollectionTransformers.swift @@ -200,7 +200,7 @@ import Darwin import Dispatch // FIXME: port to Linux. -// XFAIL: linux, windows, openbsd +// XFAIL: linux, windows, openbsd, freebsd // A wrapper for pthread_t with platform-independent interface. public struct _stdlib_pthread_t : Equatable, Hashable { diff --git a/test/Reflection/box_descriptors.sil b/test/Reflection/box_descriptors.sil index 1c0392b6972dc..1ab0a451557fc 100644 --- a/test/Reflection/box_descriptors.sil +++ b/test/Reflection/box_descriptors.sil @@ -7,6 +7,7 @@ // SR-12893 // XFAIL: openbsd +// XFAIL: freebsd sil_stage canonical diff --git a/test/Reflection/capture_descriptors.sil b/test/Reflection/capture_descriptors.sil index 8857015f81413..3a53d6b0c98d1 100644 --- a/test/Reflection/capture_descriptors.sil +++ b/test/Reflection/capture_descriptors.sil @@ -3,6 +3,7 @@ // SR-12893 // XFAIL: openbsd +// XFAIL: freebsd // RUN: %empty-directory(%t) // RUN: %target-build-swift %s -emit-module -emit-library -module-name capture_descriptors -o %t/capture_descriptors%{target-shared-library-suffix} -L%t/../../.. -lBlocksRuntime diff --git a/test/Reflection/typeref_decoding_concurrency.swift b/test/Reflection/typeref_decoding_concurrency.swift index 587e727a22d5a..1e5ff36b88c3c 100644 --- a/test/Reflection/typeref_decoding_concurrency.swift +++ b/test/Reflection/typeref_decoding_concurrency.swift @@ -7,6 +7,10 @@ // UNSUPPORTED: use_os_stdlib // UNSUPPORTED: back_deployment_runtime +// SR-12893 +// XFAIL: openbsd +// XFAIL: freebsd + // RUN: %empty-directory(%t) // RUN: %target-build-swift -Xfrontend -enable-anonymous-context-mangled-names %S/Inputs/ConcurrencyTypes.swift -parse-as-library -emit-module -emit-library -module-name TypesToReflect -o %t/%target-library-name(TypesToReflect) diff --git a/test/Reflection/typeref_decoding_imported.swift b/test/Reflection/typeref_decoding_imported.swift index 634f024c2a32b..5295ba9a88be4 100644 --- a/test/Reflection/typeref_decoding_imported.swift +++ b/test/Reflection/typeref_decoding_imported.swift @@ -2,6 +2,7 @@ // SR-12893 // XFAIL: openbsd +// XFAIL: freebsd // RUN: %empty-directory(%t) diff --git a/test/SILOptimizer/diagnostic_constant_propagation_floats_x86.swift b/test/SILOptimizer/diagnostic_constant_propagation_floats_x86.swift index c32c83d7d982a..4f442a1ac0975 100644 --- a/test/SILOptimizer/diagnostic_constant_propagation_floats_x86.swift +++ b/test/SILOptimizer/diagnostic_constant_propagation_floats_x86.swift @@ -3,6 +3,7 @@ // // REQUIRES: CPU=i386 || CPU=x86_64 // UNSUPPORTED: OS=windows-msvc +// UNSUPPORTED: OS=freebsd // // These are tests for diagnostics produced by constant propagation pass // on floating-point operations that are specific to x86 architectures, diff --git a/test/Sanitizers/tsan/actor_counters.swift b/test/Sanitizers/tsan/actor_counters.swift index 888a15b4eb7fb..97c224c1921fa 100644 --- a/test/Sanitizers/tsan/actor_counters.swift +++ b/test/Sanitizers/tsan/actor_counters.swift @@ -7,6 +7,7 @@ // UNSUPPORTED: use_os_stdlib // UNSUPPORTED: linux // UNSUPPORTED: windows +// UNSUPPORTED: freebsd @available(SwiftStdlib 5.5, *) actor Counter { diff --git a/test/Sanitizers/tsan/basic_future.swift b/test/Sanitizers/tsan/basic_future.swift index 4119994389778..07de03f08e602 100644 --- a/test/Sanitizers/tsan/basic_future.swift +++ b/test/Sanitizers/tsan/basic_future.swift @@ -6,6 +6,8 @@ // REQUIRES: tsan_runtime // UNSUPPORTED: use_os_stdlib +// XFAIL: freebsd + import Dispatch #if canImport(Darwin) diff --git a/test/Sanitizers/tsan/mainactor.swift b/test/Sanitizers/tsan/mainactor.swift index a52ee98b57087..673ea70f4ad3f 100644 --- a/test/Sanitizers/tsan/mainactor.swift +++ b/test/Sanitizers/tsan/mainactor.swift @@ -6,6 +6,8 @@ // REQUIRES: tsan_runtime // UNSUPPORTED: use_os_stdlib +// XFAIL: freebsd + import Dispatch /// @returns true iff the expected answer is actually the case, i.e., correct. diff --git a/test/Sanitizers/tsan/tsan.swift b/test/Sanitizers/tsan/tsan.swift index 6b51cf07034a0..93b221ff5049e 100644 --- a/test/Sanitizers/tsan/tsan.swift +++ b/test/Sanitizers/tsan/tsan.swift @@ -10,6 +10,8 @@ // don't support TSan. // UNSUPPORTED: remote_run +// XFAIL: freebsd + #if canImport(Darwin) import Darwin #elseif canImport(Glibc) @@ -46,7 +48,7 @@ var racey_x: Int; // TSan %deflake as part of the test. for _ in 1...5 { -#if os(macOS) || os(iOS) +#if os(macOS) || os(iOS) || os(FreeBSD) var t : pthread_t? #else var t : pthread_t = 0 @@ -57,7 +59,7 @@ for _ in 1...5 { return nil }, nil) -#if os(macOS) || os(iOS) +#if os(macOS) || os(iOS) || os(FreeBSD) threads.append(t!) #else threads.append(t) @@ -69,6 +71,7 @@ for t in threads { print("nil thread") continue } + print("Thread \(t)") pthread_join(t, nil) } diff --git a/test/lit.cfg b/test/lit.cfg index c90d75bbb9b0b..0ae010e2fa1d0 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -225,6 +225,13 @@ if platform.system() == 'OpenBSD': lit_config.fatal('No LLVM libs dir set.') config.environment['LD_LIBRARY_PATH'] = llvm_libs_dir +if platform.system() == 'FreeBSD': + llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) + if not llvm_libs_dir: + lit_config.fatal('No LLVM libs dir set.') + config.environment['LD_LIBRARY_PATH'] = llvm_libs_dir + + def append_to_env_path(directory): config.environment['PATH'] = \ os.path.pathsep.join((directory, config.environment['PATH'])) @@ -374,6 +381,12 @@ if run_os == 'openbsd' and run_cpu == 'amd64': target_arch = run_cpu run_cpu = 'x86_64' +# FreeBSD uses the amd64 cpu identifier, which is equivalent to +# x86_64, but Swift uses x86_64 only, so we set it to that +if run_os == 'freebsd' and run_cpu == 'amd64': + target_arch = run_cpu + run_cpu = 'x86_64' + run_ptrsize = '64' if ('64' in run_cpu or run_cpu == "s390x") else '32' if run_cpu == 'arm64_32': run_ptrsize = '32' diff --git a/test/stdlib/DispatchTypes.swift b/test/stdlib/DispatchTypes.swift index 536bd8ef83faa..a62f15c5919d2 100644 --- a/test/stdlib/DispatchTypes.swift +++ b/test/stdlib/DispatchTypes.swift @@ -4,6 +4,7 @@ // UNSUPPORTED: OS=linux-gnu // UNSUPPORTED: OS=linux-android // UNSUPPORTED: OS=openbsd +// UNSUPPORTED: OS=freebsd import Dispatch diff --git a/test/stdlib/FloatingPoint.swift.gyb b/test/stdlib/FloatingPoint.swift.gyb index 545d076fb5f88..b14a76fbe3abb 100644 --- a/test/stdlib/FloatingPoint.swift.gyb +++ b/test/stdlib/FloatingPoint.swift.gyb @@ -4,7 +4,7 @@ import Swift import StdlibUnittest -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) struct Float80Bits : Equatable, CustomStringConvertible { var signAndExponent: UInt16 @@ -54,7 +54,7 @@ extension Float80 { % ('Float80', 'Float80Bits') % ]: % if FloatTy == 'Float80': -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end func expectBitwiseEqual( _ expected: ${FloatTy}, _ actual: ${FloatTy}, @@ -474,7 +474,7 @@ func genericAbs(_ x: T) -> T { %for Self in ['Float', 'Double', 'Float80']: % if Self == 'Float80': -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end FloatingPoint.test("${Self}.round") { for rule in [FloatingPointRoundingRule.toNearestOrAwayFromZero, @@ -659,7 +659,7 @@ FloatingPoint.test("${Self}.nextUp, .nextDown/nan") { } %end -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) FloatingPoint.test("Float80/ExpressibleByIntegerLiteral") { expectEqual(positiveOne(), 1.0 as Float80) @@ -880,7 +880,7 @@ FloatingPoint.test("${FloatSelf}/{Comparable,Hashable,Equatable}") { % end % for Self in ['Float32', 'Float64', 'Float80']: -#if ${'!os(Windows) && (arch(i386) || arch(x86_64))' if Self == 'Float80' else 'true'} +#if ${'!(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64))' if Self == 'Float80' else 'true'} FloatingPoint.test("${Self}/Strideable") { // FIXME: the test data could probably be better chosen here, to // exercise more cases. Note: NaNs (and possibly Infs) are singular @@ -1073,7 +1073,7 @@ FloatingPoint.test("Float64/Literals") { } } -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) FloatingPoint.test("Float80/Literals") { do { @@ -1211,7 +1211,7 @@ FloatingPoint.test("Float64/quietNaN") { } } -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) FloatingPoint.test("Float80/quietNaN") { do { @@ -1306,7 +1306,7 @@ FloatingPoint.test("Float64/signalingNaN") { #endif -#if !os(Windows) && arch(x86_64) +#if !(os(Windows) || os(FreeBSD)) && arch(x86_64) FloatingPoint.test("Float80/signalingNaN") { do { diff --git a/test/stdlib/FloatingPointIR_FP80.swift b/test/stdlib/FloatingPointIR_FP80.swift index a5f0344ec054e..1de34d2588133 100644 --- a/test/stdlib/FloatingPointIR_FP80.swift +++ b/test/stdlib/FloatingPointIR_FP80.swift @@ -4,6 +4,7 @@ // REQUIRES: CPU=i386 || CPU=x86_64 // UNSUPPORTED: OS=windows-msvc +// UNSUPPORTED: OS=freebsd var globalFloat80 : Float80 = 0.0 diff --git a/test/stdlib/Inputs/FloatingPointConversion.swift.gyb b/test/stdlib/Inputs/FloatingPointConversion.swift.gyb index e95d1ca5b5f50..84007eef4bb17 100644 --- a/test/stdlib/Inputs/FloatingPointConversion.swift.gyb +++ b/test/stdlib/Inputs/FloatingPointConversion.swift.gyb @@ -20,7 +20,7 @@ var FloatingPointConversionFailures = TestSuite("FloatingPointToFloatingPointCon #if !os(macOS) && !(os(iOS) && targetEnvironment(macCatalyst)) % end % if Self == 'Float80': -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end % for other_type in all_floating_point_types(): @@ -31,7 +31,7 @@ var FloatingPointConversionFailures = TestSuite("FloatingPointToFloatingPointCon #if !os(macOS) && !(os(iOS) && targetEnvironment(macCatalyst)) % end % if OtherFloat == 'Float80': -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end % if OtherSignificandBits <= SelfSignificandBits: diff --git a/test/stdlib/NumericParsing.swift.gyb b/test/stdlib/NumericParsing.swift.gyb index 0fa62d260b115..8eb6c07a651a6 100644 --- a/test/stdlib/NumericParsing.swift.gyb +++ b/test/stdlib/NumericParsing.swift.gyb @@ -135,7 +135,7 @@ tests.test("FixedWidthInteger/maxUInt64") { % for Self in 'Float', 'Double', 'Float80': % if Self == 'Float80': -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end tests.test("${Self}/Basics") { diff --git a/test/stdlib/NumericParsing2.swift.gyb b/test/stdlib/NumericParsing2.swift.gyb index e0facb797606d..e93a8b69b336d 100644 --- a/test/stdlib/NumericParsing2.swift.gyb +++ b/test/stdlib/NumericParsing2.swift.gyb @@ -37,7 +37,7 @@ var tests = TestSuite("NumericParsing2") % for Self in 'Float', 'Double', 'Float80': % if Self == 'Float80': -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end tests.test("${Self}/Overflow/Underflow") { diff --git a/test/stdlib/POSIX.swift b/test/stdlib/POSIX.swift index 4452159554e9c..73e08476c5ac7 100644 --- a/test/stdlib/POSIX.swift +++ b/test/stdlib/POSIX.swift @@ -15,7 +15,12 @@ chdir(CommandLine.arguments[1]) var POSIXTests = TestSuite("POSIXTests") -let semaphoreName = "TestSem" +// POSIX requires names that begin with `/` to work, +// but lets implementations decide what to do with +// names that don't. For better compatibility, we +// use a name that starts with `/`. +let semaphoreName = "/TestSem" + #if os(Android) // In Android, the cwd is the root directory, which is not writable. let fn: String = { @@ -134,9 +139,11 @@ POSIXTests.test("ioctl(CInt, UInt, CInt): fail") { expectEqual(-1, fd) expectEqual(ENOENT, errno) +#if !os(FreeBSD) // A simple check to verify that ioctl is available let _ = ioctl(fd, 0, 0) expectEqual(EBADF, errno) +#endif } #if os(Linux) || os(Android) diff --git a/test/stdlib/PrintFloat.swift.gyb b/test/stdlib/PrintFloat.swift.gyb index 216216712b56e..d0c3090f4ae14 100644 --- a/test/stdlib/PrintFloat.swift.gyb +++ b/test/stdlib/PrintFloat.swift.gyb @@ -292,7 +292,7 @@ fileprivate let generatedCases_Double: [(Double, String)] = [ (0x1.63ed4a60c9c91p+324, "4.751595491707413e+97") ] -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) // Float80 found via Errol technique. // // As with Double, except for Float80. The original list in this @@ -348,7 +348,7 @@ let PrintTests = TestSuite("FloatingPointPrinting") #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) @available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) % elif FloatType == 'Float80': -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) % end // Verify that a particular value provides a specific description string. @@ -545,7 +545,7 @@ PrintTests.test("CustomStringConvertible") { hasDescription(Float(1.0)) hasDescription(Double(1.0)) -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) hasDescription(Float80(1.0)) #endif hasDescription(CFloat(1.0)) @@ -561,7 +561,7 @@ PrintTests.test("CustomDebugStringConvertible") { hasDebugDescription(Float(1.0)) hasDebugDescription(Double(1.0)) -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) hasDebugDescription(Float80(1.0)) #endif hasDebugDescription(CFloat(1.0)) @@ -979,7 +979,7 @@ PrintTests.test("Printable_Double") { } PrintTests.test("Printable_Float80") { -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) func asFloat80(_ f: Swift.Float80) -> Swift.Float80 { return f } // Sanity diff --git a/test/stdlib/VarArgs.swift b/test/stdlib/VarArgs.swift index 4407f4c355e9f..77601b46bd5e7 100644 --- a/test/stdlib/VarArgs.swift +++ b/test/stdlib/VarArgs.swift @@ -145,7 +145,7 @@ func test_varArgs6() { let i8 = Int8(1) let f32 = Float(1.1) let f64 = Double(2.2) -#if !os(Windows) && (arch(i386) || arch(x86_64)) +#if !(os(Windows) || os(FreeBSD)) && (arch(i386) || arch(x86_64)) let f80 = Float80(4.5) my_printf("a %g %d %g %d %Lg %d %g a\n", f32, i8, f64, i8, f80, i8, f32) my_printf("b %d %g %d %g %d %Lg %d %g b\n", i8, f32, i8, f64, i8, f80, i8, f32) diff --git a/test/stdlib/simd_diagnostics.swift b/test/stdlib/simd_diagnostics.swift index 16d48b7bbac4d..29ea72198f8e5 100644 --- a/test/stdlib/simd_diagnostics.swift +++ b/test/stdlib/simd_diagnostics.swift @@ -1,7 +1,7 @@ // RUN: %target-typecheck-verify-swift // FIXME: No simd module on linux rdar://problem/20795411 -// XFAIL: linux, windows, openbsd +// XFAIL: linux, windows, openbsd, freebsd import simd diff --git a/test/stdlib/tgmath.swift.gyb b/test/stdlib/tgmath.swift.gyb index 8080936bcbe56..99be5efa7466f 100644 --- a/test/stdlib/tgmath.swift.gyb +++ b/test/stdlib/tgmath.swift.gyb @@ -27,7 +27,7 @@ #error("Unsupported platform") #endif -#if (arch(i386) || arch(x86_64)) && !os(Windows) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(FreeBSD)) typealias TestLiteralType = Float80 #else typealias TestLiteralType = Double @@ -81,7 +81,7 @@ internal protocol TGMath: BinaryFloatingPoint { %end static func _remquo(_ x: Self, _ y: Self) -> (Self, Int) static func _fma(_ x: Self, _ y: Self, _ z: Self) -> Self -#if !os(Windows) && !os(OpenBSD) +#if !(os(Windows) || os(FreeBSD) || os(OpenBSD)) static func _lgamma(_ x: Self) -> (Self, Int) #endif static func _modf(_ x: Self) -> (Self, Self) @@ -122,7 +122,7 @@ internal extension TGMath { expectEqualWithTolerance(0.4041169094348222983238250859191217675, Self._erf(0.375)) expectEqualWithTolerance(0.5958830905651777016761749140808782324, Self._erfc(0.375)) expectEqualWithTolerance(2.3704361844166009086464735041766525098, Self._tgamma(0.375)) -#if !os(Windows) && !os(OpenBSD) +#if !(os(Windows) || os(FreeBSD) || os(OpenBSD)) expectEqualWithTolerance( -0.11775527074107877445136203331798850, Self._lgamma(1.375).0, ulps: 16) expectEqual(1, Self._lgamma(1.375).1) #endif @@ -174,7 +174,7 @@ internal extension TGMath { %for T in ['Float', 'Double', 'CGFloat', 'Float80']: % if T == 'Float80': -#if (arch(i386) || arch(x86_64)) && !os(Windows) +#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(FreeBSD)) % elif T == 'CGFloat': #if _runtime(_ObjC) && canImport(CoreGraphics) import CoreGraphics @@ -189,7 +189,7 @@ extension ${T}: TGMath { %end static func _remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) { return remquo(x, y) } static func _fma(_ x: ${T}, _ y: ${T}, _ z: ${T}) -> ${T} { return fma(x, y, z) } -#if !os(Windows) && !os(OpenBSD) +#if !(os(Windows) || os(FreeBSD) || os(OpenBSD)) static func _lgamma(_ x: ${T}) -> (${T}, Int) { return lgamma(x) } #endif static func _modf(_ x: ${T}) -> (${T}, ${T}) { return modf(x) } diff --git a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp index c4c07bbab4401..a4d65f30a8e3d 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp @@ -660,6 +660,7 @@ static void reportAttributes(ASTContext &Ctx, static UIdent PlatformOSXAppExt("source.availability.platform.osx_app_extension"); static UIdent PlatformtvOSAppExt("source.availability.platform.tvos_app_extension"); static UIdent PlatformWatchOSAppExt("source.availability.platform.watchos_app_extension"); + static UIdent PlatformFreeBSD("source.availability.platform.freebsd"); static UIdent PlatformOpenBSD("source.availability.platform.openbsd"); static UIdent PlatformWindows("source.availability.platform.windows"); std::vector Scratch; @@ -690,6 +691,8 @@ static void reportAttributes(ASTContext &Ctx, PlatformUID = PlatformtvOSAppExt; break; case PlatformKind::watchOSApplicationExtension: PlatformUID = PlatformWatchOSAppExt; break; + case PlatformKind::FreeBSD: + PlatformUID = PlatformFreeBSD; break; case PlatformKind::OpenBSD: PlatformUID = PlatformOpenBSD; break; case PlatformKind::Windows: diff --git a/tools/swift-dependency-tool/swift-dependency-tool.cpp b/tools/swift-dependency-tool/swift-dependency-tool.cpp index c8c900bc472bf..6b2209d5b8e73 100644 --- a/tools/swift-dependency-tool/swift-dependency-tool.cpp +++ b/tools/swift-dependency-tool/swift-dependency-tool.cpp @@ -30,7 +30,7 @@ using namespace fine_grained_dependencies; // This introduces a redefinition where ever std::is_same_t // holds -#if !(defined(__linux__) || defined(_WIN64)) +#if !(defined(__linux__) || defined(_WIN64) || defined(__FreeBSD__)) LLVM_YAML_DECLARE_SCALAR_TRAITS(size_t, QuotingType::None) #endif LLVM_YAML_DECLARE_ENUM_TRAITS(swift::fine_grained_dependencies::NodeKind) @@ -89,7 +89,7 @@ LLVM_YAML_DECLARE_MAPPING_TRAITS( namespace llvm { namespace yaml { // This introduces a redefinition for Linux. -#if !(defined(__linux__) || defined(_WIN64)) +#if !(defined(__linux__) || defined(_WIN64) || defined(__FreeBSD__)) void ScalarTraits::output(const size_t &Val, void *, raw_ostream &out) { out << Val; } From 830bf45a594e8269e5ba03fb77d26763ce90e1d6 Mon Sep 17 00:00:00 2001 From: 3405691582 Date: Sat, 9 Jul 2022 14:43:20 -0400 Subject: [PATCH 2/2] Update #38335 with main. Bring drexin's FreeBSD support patch up to date with main. Resolved conflicts in prior merge commit and made some minor buildfixes. Still requires some other more general fixes outside this pr to have this build properly at HEAD but have verified only this builds OK with those fixes possibly TK including #59987 and bootstrapping disabled on FreeBSD 12.3. Note: I don't intend to support this platform as a priority. --- lib/Threading/Pthreads.cpp | 1 + stdlib/public/CommandLineSupport/CommandLine.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/Threading/Pthreads.cpp b/lib/Threading/Pthreads.cpp index a1a6f85d9de52..1e9887a7c6fb6 100644 --- a/lib/Threading/Pthreads.cpp +++ b/lib/Threading/Pthreads.cpp @@ -101,6 +101,7 @@ swift::threading_impl::thread_get_current_stack_bounds() { #if defined(__FreeBSD__) if (pthread_attr_init(&attr)) return {}; +#define pthread_getattr_np pthread_attr_get_np #endif if (!pthread_getattr_np(pthread_self(), &attr)) { diff --git a/stdlib/public/CommandLineSupport/CommandLine.cpp b/stdlib/public/CommandLineSupport/CommandLine.cpp index dd0f743dada8b..e72ba52ef2f37 100644 --- a/stdlib/public/CommandLineSupport/CommandLine.cpp +++ b/stdlib/public/CommandLineSupport/CommandLine.cpp @@ -36,6 +36,8 @@ #include #endif +#include + // Backing storage for overrides of `Swift.CommandLine.arguments`. static char **_swift_stdlib_ProcessOverrideUnsafeArgv = nullptr; static int _swift_stdlib_ProcessOverrideUnsafeArgc = 0;