Skip to content

Commit 7f0f2ac

Browse files
committed
1 parent 0c47c45 commit 7f0f2ac

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
@@ -4721,7 +4721,8 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47214721
if (!resultTan)
47224722
return llvm::make_error<DerivativeFunctionTypeError>(
47234723
this, DerivativeFunctionTypeError::Kind::NonDifferentiableResult,
4724-
std::make_pair(originalResultType, unsigned(originalResult.index)));
4724+
DerivativeFunctionTypeError::TypeAndIndex(
4725+
originalResultType, unsigned(originalResult.index)));
47254726

47264727
if (!originalResult.isSemanticResultParameter)
47274728
resultTanTypes.push_back(resultTan->getType());
@@ -4751,7 +4752,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47514752
this,
47524753
DerivativeFunctionTypeError::Kind::
47534754
NonDifferentiableDifferentiabilityParameter,
4754-
std::make_pair(paramType, i));
4755+
DerivativeFunctionTypeError::TypeAndIndex(paramType, i));
47554756

47564757
differentialParams.push_back(AnyFunctionType::Param(
47574758
paramTan->getType(), Identifier(), diffParam.getParameterFlags()));
@@ -4799,7 +4800,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47994800
this,
48004801
DerivativeFunctionTypeError::Kind::
48014802
NonDifferentiableDifferentiabilityParameter,
4802-
std::make_pair(paramType, i));
4803+
DerivativeFunctionTypeError::TypeAndIndex(paramType, i));
48034804

48044805
if (diffParam.isAutoDiffSemanticResult()) {
48054806
if (paramType->isVoid())

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
25902590
case PlatformKind::visionOSApplicationExtension:
25912591
break;
25922592

2593+
case PlatformKind::FreeBSD:
2594+
deprecatedAsUnavailableMessage = "";
2595+
break;
2596+
25932597
case PlatformKind::OpenBSD:
25942598
deprecatedAsUnavailableMessage = "";
25952599
break;
@@ -2637,6 +2641,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
26372641
return name == "xros" || name == "xros_app_extension" ||
26382642
name == "visionos" || name == "visionos_app_extension";
26392643

2644+
case PlatformKind::FreeBSD:
2645+
return name == "freebsd";
2646+
26402647
case PlatformKind::OpenBSD:
26412648
return name == "openbsd";
26422649

@@ -2708,6 +2715,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
27082715
// No deprecation filter on xrOS
27092716
return false;
27102717

2718+
case PlatformKind::FreeBSD:
2719+
// No deprecation filter on FreeBSD
2720+
return false;
2721+
27112722
case PlatformKind::OpenBSD:
27122723
// No deprecation filter on OpenBSD
27132724
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
@@ -1779,6 +1779,9 @@ class DeclAndTypePrinter::Implementation
17791779
case PlatformKind::visionOSApplicationExtension:
17801780
plat = "visionos_app_extension";
17811781
break;
1782+
case PlatformKind::FreeBSD:
1783+
plat = "freebsd";
1784+
break;
17821785
case PlatformKind::OpenBSD:
17831786
plat = "openbsd";
17841787
break;

0 commit comments

Comments
 (0)