Skip to content

Commit 3098a6f

Browse files
committed
Refactor getMinPlatformVersion
The definitions of how version numbers were extracted from target triples split between the minimum platform version and for determining the minimum inlining version. This resulted in inlinable and transparent functions not being imported correctly on non-Apple platforms where the version number is retained as part of the target triple. Specifically, `_checkExpectedExecutor` was found in the module, but didn't have the appropriate availability version assigned, resulting in it failing to import and the compiler silently omitting the check in SILGen when compiling for FreeBSD. This patch refactors the implementation of `getMinPlatformVersion` into a separate function that is used in both places so that they cannot get out of sync again.
1 parent 95dfa3d commit 3098a6f

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Basic/Feature.h"
2323
#include "swift/Basic/FunctionBodySkipping.h"
2424
#include "swift/Basic/LLVM.h"
25+
#include "swift/Basic/Platform.h"
2526
#include "swift/Basic/PlaygroundOption.h"
2627
#include "swift/Basic/Version.h"
2728
#include "swift/Config.h"
@@ -693,18 +694,7 @@ namespace swift {
693694
/// This is only implemented on certain OSs. If no target has been
694695
/// configured, returns v0.0.0.
695696
llvm::VersionTuple getMinPlatformVersion() const {
696-
if (Target.isMacOSX()) {
697-
llvm::VersionTuple OSVersion;
698-
Target.getMacOSXVersion(OSVersion);
699-
return OSVersion;
700-
} else if (Target.isiOS()) {
701-
return Target.getiOSVersion();
702-
} else if (Target.isWatchOS()) {
703-
return Target.getOSVersion();
704-
} else if (Target.isXROS()) {
705-
return Target.getOSVersion();
706-
}
707-
return llvm::VersionTuple(/*Major=*/0, /*Minor=*/0, /*Subminor=*/0);
697+
return getVersionForTriple(Target);
708698
}
709699

710700
/// Sets an implicit platform condition.

include/swift/Basic/Platform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ namespace swift {
8585
/// returned.
8686
StringRef getPlatformNameForTriple(const llvm::Triple &triple);
8787

88+
/// Returns the version tuple for a given target triple
89+
llvm::VersionTuple getVersionForTriple(const llvm::Triple &triple);
90+
8891
/// Returns the platform Kind for Darwin triples.
8992
DarwinPlatformKind getDarwinPlatformKind(const llvm::Triple &triple);
9093

lib/Basic/Platform.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,21 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
278278
llvm_unreachable("unsupported OS");
279279
}
280280

281+
llvm::VersionTuple swift::getVersionForTriple(const llvm::Triple &triple) {
282+
if (triple.isMacOSX()) {
283+
llvm::VersionTuple OSVersion;
284+
triple.getMacOSXVersion(OSVersion);
285+
return OSVersion;
286+
} else if (triple.isiOS()) {
287+
return triple.getiOSVersion();
288+
} else if (triple.isWatchOS()) {
289+
return triple.getOSVersion();
290+
} else if (triple.isXROS()) {
291+
return triple.getOSVersion();
292+
}
293+
return llvm::VersionTuple(/*Major=*/0, /*Minor=*/0, /*Subminor=*/0);
294+
}
295+
281296
StringRef swift::getMajorArchitectureName(const llvm::Triple &Triple) {
282297
if (Triple.isOSLinux()) {
283298
switch (Triple.getSubArch()) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ swift::CompilerInvocation::CompilerInvocation() {
5656
setTargetTriple(llvm::sys::getDefaultTargetTriple());
5757
}
5858

59-
/// Converts a llvm::Triple to a llvm::VersionTuple.
60-
static llvm::VersionTuple
61-
getVersionTuple(const llvm::Triple &triple) {
62-
if (triple.isMacOSX()) {
63-
llvm::VersionTuple OSVersion;
64-
triple.getMacOSXVersion(OSVersion);
65-
return OSVersion;
66-
}
67-
return triple.getOSVersion();
68-
}
69-
7059
void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
7160
StringRef mainExecutablePath, bool shared,
7261
llvm::SmallVectorImpl<char> &runtimeResourcePath) {
@@ -1623,7 +1612,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
16231612
// First, set up default minimum inlining target versions.
16241613
auto getDefaultMinimumInliningTargetVersion =
16251614
[&](const llvm::Triple &triple) -> llvm::VersionTuple {
1626-
const auto targetVersion = getVersionTuple(triple);
1615+
const auto targetVersion = getVersionForTriple(triple);
16271616

16281617
// In API modules, default to the version when Swift first became available.
16291618
if (Opts.LibraryLevel == LibraryLevel::API) {

0 commit comments

Comments
 (0)