Skip to content

Commit be17a5f

Browse files
committed
Merge #38335
1 parent 7312e9b commit be17a5f

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
@@ -1054,6 +1054,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
10541054
set(SWIFT_USE_LINKER_default "")
10551055
elseif(DISTRO_NAME STREQUAL "Amazon Linux 2023")
10561056
set(SWIFT_USE_LINKER_default "lld")
1057+
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
1058+
set(SWIFT_USE_LINKER_default "lld")
10571059
else()
10581060
get_gold_version(gold_version)
10591061
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:
@@ -278,6 +281,7 @@ bool swift::isPlatformSPI(PlatformKind Platform) {
278281
case PlatformKind::visionOS:
279282
case PlatformKind::visionOSApplicationExtension:
280283
case PlatformKind::OpenBSD:
284+
case PlatformKind::FreeBSD:
281285
case PlatformKind::Windows:
282286
case PlatformKind::none:
283287
return false;

lib/AST/Type.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4704,7 +4704,8 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47044704
if (!resultTan)
47054705
return llvm::make_error<DerivativeFunctionTypeError>(
47064706
this, DerivativeFunctionTypeError::Kind::NonDifferentiableResult,
4707-
std::make_pair(originalResultType, unsigned(originalResult.index)));
4707+
DerivativeFunctionTypeError::TypeAndIndex(
4708+
originalResultType, unsigned(originalResult.index)));
47084709

47094710
if (!originalResult.isSemanticResultParameter)
47104711
resultTanTypes.push_back(resultTan->getType());
@@ -4734,7 +4735,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47344735
this,
47354736
DerivativeFunctionTypeError::Kind::
47364737
NonDifferentiableDifferentiabilityParameter,
4737-
std::make_pair(paramType, i));
4738+
DerivativeFunctionTypeError::TypeAndIndex(paramType, i));
47384739

47394740
differentialParams.push_back(AnyFunctionType::Param(
47404741
paramTan->getType(), Identifier(), diffParam.getParameterFlags()));
@@ -4782,7 +4783,7 @@ AnyFunctionType::getAutoDiffDerivativeFunctionLinearMapType(
47824783
this,
47834784
DerivativeFunctionTypeError::Kind::
47844785
NonDifferentiableDifferentiabilityParameter,
4785-
std::make_pair(paramType, i));
4786+
DerivativeFunctionTypeError::TypeAndIndex(paramType, i));
47864787

47874788
if (diffParam.isAutoDiffSemanticResult()) {
47884789
if (paramType->isVoid())

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,6 +2562,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
25622562
case PlatformKind::visionOSApplicationExtension:
25632563
break;
25642564

2565+
case PlatformKind::FreeBSD:
2566+
deprecatedAsUnavailableMessage = "";
2567+
break;
2568+
25652569
case PlatformKind::OpenBSD:
25662570
deprecatedAsUnavailableMessage = "";
25672571
break;
@@ -2609,6 +2613,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
26092613
return name == "xros" || name == "xros_app_extension" ||
26102614
name == "visionos" || name == "visionos_app_extension";
26112615

2616+
case PlatformKind::FreeBSD:
2617+
return name == "freebsd";
2618+
26122619
case PlatformKind::OpenBSD:
26132620
return name == "openbsd";
26142621

@@ -2680,6 +2687,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
26802687
// No deprecation filter on xrOS
26812688
return false;
26822689

2690+
case PlatformKind::FreeBSD:
2691+
// No deprecation filter on FreeBSD
2692+
return false;
2693+
26832694
case PlatformKind::OpenBSD:
26842695
// No deprecation filter on OpenBSD
26852696
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
@@ -1782,6 +1782,9 @@ class DeclAndTypePrinter::Implementation
17821782
case PlatformKind::visionOSApplicationExtension:
17831783
plat = "visionos_app_extension";
17841784
break;
1785+
case PlatformKind::FreeBSD:
1786+
plat = "freebsd";
1787+
break;
17851788
case PlatformKind::OpenBSD:
17861789
plat = "openbsd";
17871790
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)