Skip to content

Commit 2a80c1a

Browse files
committed
1 parent d1c3071 commit 2a80c1a

File tree

13 files changed

+56
-10
lines changed

13 files changed

+56
-10
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
10561056
set(SWIFT_USE_LINKER_default "")
10571057
elseif(DISTRO_NAME STREQUAL "Amazon Linux 2023")
10581058
set(SWIFT_USE_LINKER_default "lld")
1059+
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
1060+
set(SWIFT_USE_LINKER_default "lld")
10591061
else()
10601062
get_gold_version(gold_version)
10611063
if(NOT gold_version)

include/swift/AST/AutoDiff.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,14 @@ class DerivativeFunctionTypeError
422422
Kind kind;
423423

424424
/// The type and index of a differentiability parameter or result.
425-
using TypeAndIndex = std::pair<Type, unsigned>;
425+
/// std::pair does not have a trivial copy constructor on FreeBSD <= 14 for
426+
/// ABI reasons, so we have to define our own type here instead
427+
struct TypeAndIndex {
428+
Type first;
429+
unsigned second;
430+
431+
TypeAndIndex(Type type, unsigned index) : first(type), second(index) {}
432+
};
426433

427434
private:
428435
union Value {

include/swift/AST/PlatformKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ AVAILABILITY_PLATFORM(visionOSApplicationExtension, "application extensions for
3434
AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS")
3535
AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst")
3636
AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst")
37+
AVAILABILITY_PLATFORM(FreeBSD, "FreeBSD")
3738
AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD")
3839
AVAILABILITY_PLATFORM(Windows, "Windows")
3940

include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,17 @@ struct DifferentiationInvoker {
7171

7272
/// The parent `apply` instruction and the witness associated with the
7373
/// `IndirectDifferentiation` case.
74-
std::pair<ApplyInst *, SILDifferentiabilityWitness *>
75-
indirectDifferentiation;
74+
/// Note: This used to be a std::pair, but on FreeBSD <= 14, libc++ is
75+
/// configured with _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
76+
/// and hence does not have a trivial copy constructor
77+
struct IndirectDifferentiation {
78+
ApplyInst *applyInst;
79+
SILDifferentiabilityWitness *witness;
80+
};
81+
IndirectDifferentiation indirectDifferentiation;
82+
7683
Value(ApplyInst *applyInst, SILDifferentiabilityWitness *witness)
77-
: indirectDifferentiation({applyInst, witness}) {}
84+
: indirectDifferentiation({applyInst, witness}) {}
7885

7986
/// The witness associated with the `SILDifferentiabilityWitnessInvoker`
8087
/// case.
@@ -111,7 +118,8 @@ struct DifferentiationInvoker {
111118
std::pair<ApplyInst *, SILDifferentiabilityWitness *>
112119
getIndirectDifferentiation() const {
113120
assert(kind == Kind::IndirectDifferentiation);
114-
return value.indirectDifferentiation;
121+
return std::make_pair(value.indirectDifferentiation.applyInst,
122+
value.indirectDifferentiation.witness);
115123
}
116124

117125
SILDifferentiabilityWitness *getSILDifferentiabilityWitnessInvoker() const {

lib/AST/PlatformKind.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ swift::basePlatformForExtensionPlatform(PlatformKind Platform) {
116116
case PlatformKind::tvOS:
117117
case PlatformKind::watchOS:
118118
case PlatformKind::visionOS:
119+
case PlatformKind::FreeBSD:
119120
case PlatformKind::OpenBSD:
120121
case PlatformKind::Windows:
121122
case PlatformKind::none:
@@ -160,6 +161,8 @@ static bool isPlatformActiveForTarget(PlatformKind Platform,
160161
return Target.isXROS();
161162
case PlatformKind::OpenBSD:
162163
return Target.isOSOpenBSD();
164+
case PlatformKind::FreeBSD:
165+
return Target.isOSFreeBSD();
163166
case PlatformKind::Windows:
164167
return Target.isOSWindows();
165168
case PlatformKind::none:
@@ -292,6 +295,7 @@ bool swift::isPlatformSPI(PlatformKind Platform) {
292295
case PlatformKind::visionOS:
293296
case PlatformKind::visionOSApplicationExtension:
294297
case PlatformKind::OpenBSD:
298+
case PlatformKind::FreeBSD:
295299
case PlatformKind::Windows:
296300
case PlatformKind::none:
297301
return false;

lib/AST/Type.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4744,7 +4744,8 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47444744
if (!resultTan)
47454745
return llvm::make_error<DerivativeFunctionTypeError>(
47464746
this, DerivativeFunctionTypeError::Kind::NonDifferentiableResult,
4747-
std::make_pair(originalResultType, unsigned(originalResult.index)));
4747+
DerivativeFunctionTypeError::TypeAndIndex(
4748+
originalResultType, unsigned(originalResult.index)));
47484749

47494750
if (!originalResult.isSemanticResultParameter)
47504751
resultTanTypes.push_back(resultTan->getType());
@@ -4774,7 +4775,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47744775
this,
47754776
DerivativeFunctionTypeError::Kind::
47764777
NonDifferentiableDifferentiabilityParameter,
4777-
std::make_pair(paramType, i));
4778+
DerivativeFunctionTypeError::TypeAndIndex(paramType, i));
47784779

47794780
differentialParams.push_back(AnyFunctionType::Param(
47804781
paramTan->getType(), Identifier(), diffParam.getParameterFlags()));
@@ -4822,7 +4823,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
48224823
this,
48234824
DerivativeFunctionTypeError::Kind::
48244825
NonDifferentiableDifferentiabilityParameter,
4825-
std::make_pair(paramType, i));
4826+
DerivativeFunctionTypeError::TypeAndIndex(paramType, i));
48264827

48274828
if (diffParam.isAutoDiffSemanticResult()) {
48284829
if (paramType->isVoid())

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
25962596
case PlatformKind::visionOSApplicationExtension:
25972597
break;
25982598

2599+
case PlatformKind::FreeBSD:
2600+
deprecatedAsUnavailableMessage = "";
2601+
break;
2602+
25992603
case PlatformKind::OpenBSD:
26002604
deprecatedAsUnavailableMessage = "";
26012605
break;
@@ -2643,6 +2647,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
26432647
return name == "xros" || name == "xros_app_extension" ||
26442648
name == "visionos" || name == "visionos_app_extension";
26452649

2650+
case PlatformKind::FreeBSD:
2651+
return name == "freebsd";
2652+
26462653
case PlatformKind::OpenBSD:
26472654
return name == "openbsd";
26482655

@@ -2714,6 +2721,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
27142721
// No deprecation filter on xrOS
27152722
return false;
27162723

2724+
case PlatformKind::FreeBSD:
2725+
// No deprecation filter on FreeBSD
2726+
return false;
2727+
27172728
case PlatformKind::OpenBSD:
27182729
// No deprecation filter on OpenBSD
27192730
return false;

lib/IRGen/TBDGen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver,
244244
llvm_unreachable("cannot find platform kind");
245245
case swift::PlatformKind::OpenBSD:
246246
llvm_unreachable("not used for this platform");
247+
case swift::PlatformKind::FreeBSD:
248+
llvm_unreachable("not used for this platform");
247249
case swift::PlatformKind::Windows:
248250
llvm_unreachable("not used for this platform");
249251
case swift::PlatformKind::iOS:

lib/Option/SanitizerOptions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ OptionSet<SanitizerKind> swift::parseSanitizerArgValues(
168168
}
169169

170170
// Check that we're one of the known supported targets for sanitizers.
171-
if (!(Triple.isOSDarwin() || Triple.isOSLinux() || Triple.isOSWindows())) {
171+
if (!(Triple.isOSDarwin() || Triple.isOSLinux() || Triple.isOSWindows()
172+
|| Triple.isOSFreeBSD())) {
172173
SmallString<128> b;
173174
Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target,
174175
(A->getOption().getPrefixedName() +

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,9 @@ class DeclAndTypePrinter::Implementation
17951795
case PlatformKind::visionOSApplicationExtension:
17961796
plat = "visionos_app_extension";
17971797
break;
1798+
case PlatformKind::FreeBSD:
1799+
plat = "freebsd";
1800+
break;
17981801
case PlatformKind::OpenBSD:
17991802
plat = "openbsd";
18001803
break;

lib/SymbolGraphGen/AvailabilityMixin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ StringRef getDomain(const SemanticAvailableAttr &AvAttr) {
5454
return { "watchOSAppExtension" };
5555
case swift::PlatformKind::visionOSApplicationExtension:
5656
return { "visionOSAppExtension" };
57+
case swift::PlatformKind::FreeBSD:
58+
return { "FreeBSD" };
5759
case swift::PlatformKind::OpenBSD:
5860
return { "OpenBSD" };
5961
case swift::PlatformKind::Windows:

stdlib/public/SwiftShims/swift/shims/SwiftStdint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
// Clang has been defining __INTxx_TYPE__ macros for a long time.
2626
// __UINTxx_TYPE__ are defined only since Clang 3.5.
27-
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__)
27+
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__wasi__)
2828
#include <stdint.h>
2929
typedef int64_t __swift_int64_t;
3030
typedef uint64_t __swift_uint64_t;

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D,
688688
static UIdent PlatformOSXAppExt("source.availability.platform.osx_app_extension");
689689
static UIdent PlatformtvOSAppExt("source.availability.platform.tvos_app_extension");
690690
static UIdent PlatformWatchOSAppExt("source.availability.platform.watchos_app_extension");
691+
static UIdent PlatformFreeBSD("source.availability.platform.freebsd");
691692
static UIdent PlatformOpenBSD("source.availability.platform.openbsd");
692693
static UIdent PlatformWindows("source.availability.platform.windows");
693694
std::vector<SemanticAvailableAttr> Scratch;
@@ -739,6 +740,9 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D,
739740
case PlatformKind::OpenBSD:
740741
PlatformUID = PlatformOpenBSD;
741742
break;
743+
case PlatformKind::FreeBSD:
744+
PlatformUID = PlatformFreeBSD;
745+
break;
742746
case PlatformKind::Windows:
743747
PlatformUID = PlatformWindows;
744748
break;

0 commit comments

Comments
 (0)