Skip to content

Commit 2dff8f3

Browse files
author
git apple-llvm automerger
committed
Merge commit '2210f3371635' from swift/release/6.2 into stable/20240723
2 parents 77f880d + 2210f33 commit 2dff8f3

21 files changed

+646
-56
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,8 @@ static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
10831083
return llvm::StringSwitch<llvm::StringRef>(Platform)
10841084
.Case("iOS", "ios")
10851085
.Case("macOS", "macos")
1086+
.Case("macOSX", "macos")
1087+
.Case("macosx", "macos")
10861088
.Case("tvOS", "tvos")
10871089
.Case("watchOS", "watchos")
10881090
.Case("iOSApplicationExtension", "ios_app_extension")
@@ -1117,6 +1119,26 @@ static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef Environm
11171119
.Case("library", llvm::Triple::Library)
11181120
.Default(llvm::Triple::UnknownEnvironment);
11191121
}
1122+
1123+
static llvm::Triple::OSType getOSType(llvm::StringRef Platform) {
1124+
using OSType = llvm::Triple::OSType;
1125+
return llvm::StringSwitch<OSType>(Platform)
1126+
.Case("ios", OSType::IOS)
1127+
.Case("macos", OSType::MacOSX)
1128+
.Case("maccatalyst", OSType::IOS)
1129+
.Case("tvos", OSType::TvOS)
1130+
.Case("watchos", OSType::WatchOS)
1131+
.Case("bridgeos", OSType::BridgeOS)
1132+
.Case("ios_app_extension", OSType::IOS)
1133+
.Case("maccatalyst_app_extension", OSType::IOS)
1134+
.Case("macos_app_extension", OSType::MacOSX)
1135+
.Case("tvos_app_extension", OSType::TvOS)
1136+
.Case("watchos_app_extension", OSType::WatchOS)
1137+
.Case("xros", OSType::XROS)
1138+
.Case("xros_app_extension", OSType::XROS)
1139+
.Default(OSType::UnknownOS);
1140+
}
1141+
11201142
}];
11211143
let HasCustomParsing = 1;
11221144
let InheritEvenIfAlreadyPresent = 1;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4006,6 +4006,9 @@ def warn_at_available_unchecked_use : Warning<
40064006
"%select{@available|__builtin_available}0 does not guard availability here; "
40074007
"use if (%select{@available|__builtin_available}0) instead">,
40084008
InGroup<DiagGroup<"unsupported-availability-guard">>;
4009+
def warn_availability_invalid_os_version
4010+
: Warning<"invalid %1 version '%0' in availability attribute">, InGroup<DiagGroup<"invalid-version-availability">>;
4011+
def note_availability_invalid_os_version_adjusted: Note<"implicitly treating version as '%0'">;
40094012

40104013
def warn_missing_sdksettings_for_availability_checking : Warning<
40114014
"%0 availability is ignored without a valid 'SDKSettings.json' in the SDK">,

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,10 +1816,14 @@ struct DarwinPlatform {
18161816
UnderlyingOSVersion.reset();
18171817
return Result;
18181818
}
1819+
bool isValidOSVersion() const {
1820+
return llvm::Triple::isValidVersionForOS(getOSFromPlatform(Platform),
1821+
getOSVersion());
1822+
}
18191823

18201824
VersionTuple getCanonicalOSVersion() const {
1821-
return llvm::Triple::getCanonicalVersionForOS(getOSFromPlatform(Platform),
1822-
getOSVersion());
1825+
return llvm::Triple::getCanonicalVersionForOS(
1826+
getOSFromPlatform(Platform), getOSVersion(), /*IsInValidRange=*/true);
18231827
}
18241828

18251829
void setOSVersion(const VersionTuple &Version) {
@@ -2544,6 +2548,9 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
25442548
}
25452549

25462550
assert(PlatformAndVersion && "Unable to infer Darwin variant");
2551+
if (!PlatformAndVersion->isValidOSVersion())
2552+
getDriver().Diag(diag::err_drv_invalid_version_number)
2553+
<< PlatformAndVersion->getAsString(Args, Opts);
25472554
// After the deployment OS version has been resolved, set it to the canonical
25482555
// version before further error detection and converting to a proper target
25492556
// triple.
@@ -2645,6 +2652,12 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
26452652
ZipperedOSVersion = PlatformAndVersion->getZipperedOSVersion();
26462653
setTarget(Platform, Environment, Major, Minor, Micro, ZipperedOSVersion);
26472654
TargetVariantTriple = PlatformAndVersion->getTargetVariantTriple();
2655+
if (TargetVariantTriple &&
2656+
!llvm::Triple::isValidVersionForOS(TargetVariantTriple->getOS(),
2657+
TargetVariantTriple->getOSVersion())) {
2658+
getDriver().Diag(diag::err_drv_invalid_version_number)
2659+
<< TargetVariantTriple->str();
2660+
}
26482661

26492662
if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
26502663
StringRef SDK = getSDKName(A->getValue());

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,8 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
23442344
IdentifierLoc *Platform = AL.getArgAsIdent(0);
23452345

23462346
IdentifierInfo *II = Platform->Ident;
2347-
if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty())
2347+
StringRef PrettyName = AvailabilityAttr::getPrettyPlatformName(II->getName());
2348+
if (PrettyName.empty())
23482349
S.Diag(Platform->Loc, diag::warn_availability_unknown_platform)
23492350
<< Platform->Ident;
23502351

@@ -2355,15 +2356,31 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
23552356
AvailabilityChange Introduced = AL.getAvailabilityIntroduced();
23562357
AvailabilityChange Deprecated = AL.getAvailabilityDeprecated();
23572358
AvailabilityChange Obsoleted = AL.getAvailabilityObsoleted();
2358-
if (II->getName() == "macos" || II->getName() == "macos_app_extension") {
2359-
// Canonicalize macOS availability versions.
2360-
Introduced.Version = llvm::Triple::getCanonicalVersionForOS(
2361-
llvm::Triple::MacOSX, Introduced.Version);
2362-
Deprecated.Version = llvm::Triple::getCanonicalVersionForOS(
2363-
llvm::Triple::MacOSX, Deprecated.Version);
2364-
Obsoleted.Version = llvm::Triple::getCanonicalVersionForOS(
2365-
llvm::Triple::MacOSX, Obsoleted.Version);
2359+
2360+
const llvm::Triple::OSType PlatformOS = AvailabilityAttr::getOSType(
2361+
AvailabilityAttr::canonicalizePlatformName(II->getName()));
2362+
2363+
auto reportAndUpdateIfInvalidOS = [&](auto &InputVersion) -> void {
2364+
const bool IsInValidRange =
2365+
llvm::Triple::isValidVersionForOS(PlatformOS, InputVersion);
2366+
// Canonicalize availability versions.
2367+
auto CanonicalVersion = llvm::Triple::getCanonicalVersionForOS(
2368+
PlatformOS, InputVersion, IsInValidRange);
2369+
if (!IsInValidRange) {
2370+
S.Diag(Platform->Loc, diag::warn_availability_invalid_os_version)
2371+
<< InputVersion.getAsString() << PrettyName;
2372+
S.Diag(Platform->Loc, diag::note_availability_invalid_os_version_adjusted)
2373+
<< CanonicalVersion.getAsString();
2374+
}
2375+
InputVersion = CanonicalVersion;
2376+
};
2377+
2378+
if (PlatformOS != llvm::Triple::OSType::UnknownOS) {
2379+
reportAndUpdateIfInvalidOS(Introduced.Version);
2380+
reportAndUpdateIfInvalidOS(Deprecated.Version);
2381+
reportAndUpdateIfInvalidOS(Obsoleted.Version);
23662382
}
2383+
23672384
bool IsUnavailable = AL.getUnavailableLoc().isValid();
23682385
bool IsStrict = AL.getStrictLoc().isValid();
23692386
StringRef Str;
@@ -2453,7 +2470,11 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
24532470
}
24542471

24552472
auto Major = Version.getMajor();
2456-
auto NewMajor = Major >= 9 ? Major - 7 : 0;
2473+
auto NewMajor = Major;
2474+
if (Major < 9)
2475+
NewMajor = 0;
2476+
else if (Major < 12)
2477+
NewMajor = Major - 7;
24572478
if (NewMajor >= 2) {
24582479
if (Version.getMinor()) {
24592480
if (Version.getSubminor())

clang/lib/Sema/SemaExprObjC.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5161,7 +5161,7 @@ ExprResult SemaObjC::ActOnObjCAvailabilityCheckExpr(
51615161
AtLoc, RParen, Context.BoolTy, Spec.getDomainName(), Context);
51625162
}
51635163

5164-
auto FindSpecVersion = [&](StringRef Platform)
5164+
auto FindSpecVersion = [&](StringRef Platform, const llvm::Triple::OSType &OS)
51655165
-> std::optional<ObjCAvailabilityCheckExpr::VersionAsWritten> {
51665166
auto Spec = llvm::find_if(AvailSpecs, [&](const AvailabilitySpec &Spec) {
51675167
return Spec.getPlatform() == Platform;
@@ -5175,18 +5175,16 @@ ExprResult SemaObjC::ActOnObjCAvailabilityCheckExpr(
51755175
}
51765176
if (Spec == AvailSpecs.end())
51775177
return std::nullopt;
5178-
if (Platform == "macos") {
5179-
return ObjCAvailabilityCheckExpr::VersionAsWritten{
5180-
llvm::Triple::getCanonicalVersionForOS(llvm::Triple::MacOSX,
5181-
Spec->getVersion()),
5182-
Spec->getVersion()};
5183-
}
5184-
return ObjCAvailabilityCheckExpr::VersionAsWritten{Spec->getVersion(),
5185-
Spec->getVersion()};
5178+
return ObjCAvailabilityCheckExpr::VersionAsWritten{
5179+
llvm::Triple::getCanonicalVersionForOS(
5180+
OS, Spec->getVersion(),
5181+
llvm::Triple::isValidVersionForOS(OS, Spec->getVersion())),
5182+
Spec->getVersion()};
51865183
};
51875184

51885185
auto MaybeVersion =
5189-
FindSpecVersion(Context.getTargetInfo().getPlatformName());
5186+
FindSpecVersion(Context.getTargetInfo().getPlatformName(),
5187+
Context.getTargetInfo().getTriple().getOS());
51905188
ObjCAvailabilityCheckExpr::VersionAsWritten Version;
51915189
if (MaybeVersion)
51925190
Version = *MaybeVersion;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// This test verifies IR generated for APIs protected with availability annotations with a common versions.
2+
// RUN: %clang_cc1 -fvisibility=hidden "-triple" "arm64-apple-ios26.0" -emit-llvm -o - %s | FileCheck %s
3+
// RUN: %clang_cc1 -fvisibility=hidden "-triple" "arm64-apple-tvos26" -emit-llvm -o - %s | FileCheck %s
4+
// RUN: %clang_cc1 -fvisibility=hidden "-triple" "arm64-apple-watchos26" -emit-llvm -o - %s | FileCheck %s
5+
// RUN: %clang_cc1 -fvisibility=hidden "-triple" "arm64-apple-ios18" -emit-llvm -o - %s | FileCheck -check-prefix=OLD %s
6+
7+
__attribute__((availability(ios,introduced=19)))
8+
void f0(void);
9+
10+
__attribute__((availability(ios,introduced=26)))
11+
void f1(void);
12+
13+
__attribute__((availability(ios,introduced=27)))
14+
void f2(void);
15+
16+
// OLD: declare extern_weak void @f0
17+
// OLD: declare extern_weak void @f1
18+
// OLD: declare extern_weak void @f2
19+
20+
// CHECK: declare void @f0
21+
// CHECK: declare void @f1
22+
// CHECK: declare extern_weak void @f2
23+
24+
void test() {
25+
f0();
26+
f1();
27+
f2();
28+
}

clang/test/Driver/darwin-infer-simulator-sdkroot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
//
4242
// RUN: rm -rf %t/SDKs/WatchOS3.0.sdk
4343
// RUN: mkdir -p %t/SDKs/WatchOS3.0.sdk
44-
// RUN: env SDKROOT=%t/SDKs/WatchOS3.0.sdk %clang %s -fuse-ld= -mlinker-version=400 -### 2>&1 \
44+
// RUN: env SDKROOT=%t/SDKs/WatchOS3.0.sdk %clang %s -fuse-ld= -arch arm64_32 -mlinker-version=400 -### 2>&1 \
4545
// RUN: | FileCheck --check-prefix=CHECK-WATCH %s
46-
// RUN: env WATCHOS_DEPLOYMENT_TARGET=3.0 %clang %s -fuse-ld= -isysroot %t/SDKs/WatchOS3.0.sdk -mlinker-version=400 -### 2>&1 \
46+
// RUN: env WATCHOS_DEPLOYMENT_TARGET=3.0 %clang %s -fuse-ld= -arch arm64_32 -isysroot %t/SDKs/WatchOS3.0.sdk -mlinker-version=400 -### 2>&1 \
4747
// RUN: | FileCheck --check-prefix=CHECK-WATCH %s
4848
//
4949
// CHECK-WATCH: clang
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// Verify invalid OSVersions are diagnosed.
2+
3+
// RUN: not %clang -target arm64-apple-ios20 -c %s 2>&1 | FileCheck %s --check-prefix=IOS
4+
// IOS: error: invalid version number in '-target arm64-apple-ios20'
5+
6+
// RUN: not %clang -target arm64-apple-watchos20 -c %s 2>&1 | FileCheck %s --check-prefix=WATCHOS
7+
// WATCHOS: error: invalid version number in '-target arm64-apple-watchos20'
8+
9+
// RUN: not %clang -target arm64-apple-macosx19 -c %s 2>&1 | FileCheck %s --check-prefix=MAC
10+
// MAC: error: invalid version number in '-target arm64-apple-macosx19'
11+
12+
// RUN: not %clang -target arm64-apple-ios22-macabi -c %s 2>&1 | FileCheck %s --check-prefix=IOSMAC
13+
// IOSMAC: error: invalid version number in '-target arm64-apple-ios22-macabi'
14+
15+
// RUN: not %clang -target arm64-apple-macosx16 -darwin-target-variant arm64-apple-ios22-macabi -c %s 2>&1 | FileCheck %s --check-prefix=ZIPPERED
16+
// ZIPPERED: error: invalid version number in 'arm64-apple-ios22-macabi'
17+
18+
// RUN: not %clang -target arm64-apple-visionos5 -c %s 2>&1 | FileCheck %s --check-prefix=VISION
19+
// VISION: error: invalid version number in '-target arm64-apple-visionos5'
20+
21+
// RUN: not %clang -target arm64-apple-tvos21 -c %s 2>&1 | FileCheck %s --check-prefix=TV
22+
// TV: error: invalid version number in '-target arm64-apple-tvos21'

clang/test/Driver/darwin-ld-platform-version-macos.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@
4848
// RUN: -### %t.o 2>&1 \
4949
// RUN: | FileCheck --check-prefix=NOSDK %s
5050
// NOSDK: "-platform_version" "macos" "10.13.0" "10.13.0"
51+
52+
// RUN: %clang -target arm64-apple-macos26 -mlinker-version=520 \
53+
// RUN: -### %t.o 2>&1 \
54+
// RUN: | FileCheck --check-prefix=VERSION_BUMP %s
55+
// VERSION_BUMP: "-platform_version" "macos" "26.0.0" "26.0.0"

clang/test/Driver/darwin-ld-platform-version-watchos.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,54 @@
1717
// RUN: -### %t.o 2>&1 \
1818
// RUN: | FileCheck --check-prefix=SIMUL %s
1919

20+
// RUN: %clang -target arm64-apple-watchos6.3 -fuse-ld= \
21+
// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=400 \
22+
// RUN: -### %t.o 2>&1 \
23+
// RUN: | FileCheck --check-prefix=ARM64-LINKER-OLD %s
24+
25+
// RUN: %clang -target arm64e-apple-watchos6.3 -fuse-ld= \
26+
// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=400 \
27+
// RUN: -### %t.o 2>&1 \
28+
// RUN: | FileCheck --check-prefix=ARM64-LINKER-OLD %s
29+
30+
// RUN: %clang -target arm64-apple-watchos26.1 -fuse-ld= \
31+
// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=400 \
32+
// RUN: -### %t.o 2>&1 \
33+
// RUN: | FileCheck --check-prefix=ARM64-LINKER-OLD-261 %s
34+
35+
// RUN: %clang -target arm64-apple-watchos6.3 -fuse-ld=lld \
36+
// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=0 \
37+
// RUN: -### %t.o -B%S/Inputs/lld 2>&1 \
38+
// RUN: | FileCheck --check-prefix=ARM64-LINKER-NEW %s
39+
40+
// RUN: %clang -target arm64e-apple-watchos6.3 -fuse-ld=lld \
41+
// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=0 \
42+
// RUN: -### %t.o -B%S/Inputs/lld 2>&1 \
43+
// RUN: | FileCheck --check-prefix=ARM64-LINKER-NEW %s
44+
45+
// RUN: %clang -target arm64-apple-watchos6.3 -fuse-ld= \
46+
// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 \
47+
// RUN: -### %t.o 2>&1 \
48+
// RUN: | FileCheck --check-prefix=ARM64-LINKER-NEW %s
49+
50+
// RUN: %clang -target arm64-apple-watchos26.1 -fuse-ld= \
51+
// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 \
52+
// RUN: -### %t.o 2>&1 \
53+
// RUN: | FileCheck --check-prefix=ARM64-LINKER-NEW-261 %s
54+
55+
// RUN: %clang -target arm64-apple-watchos6-simulator -fuse-ld= \
56+
// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 \
57+
// RUN: -### %t.o 2>&1 \
58+
// RUN: | FileCheck --check-prefix=ARM64-SIMUL %s
59+
2060
// LINKER-OLD: "-watchos_version_min" "5.2.0"
2161
// LINKER-NEW: "-platform_version" "watchos" "5.2.0" "6.0"
2262
// SIMUL: "-platform_version" "watchos-simulator" "6.0.0" "6.0"
63+
64+
// ARM64-LINKER-OLD: "-watchos_version_min" "26.0.0"
65+
// ARM64-LINKER-OLD-261: "-watchos_version_min" "26.1.0"
66+
67+
// ARM64-LINKER-NEW: "-platform_version" "watchos" "26.0.0" "6.0"
68+
// ARM64-LINKER-NEW-261: "-platform_version" "watchos" "26.1.0" "6.0"
69+
70+
// ARM64-SIMUL: "-platform_version" "watchos-simulator" "7.0.0" "6.0"

clang/test/ExtractAPI/availability.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void a(void) __attribute__((availability(macos, introduced=12.0)));
1717
// A-NEXT: ]
1818

1919
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix B
20-
void b(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0, obsoleted=20.0)));
20+
void b(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0, obsoleted=30.0)));
2121
// B-LABEL: "!testLabel": "c:@F@b"
2222
// B: "availability": [
2323
// B-NEXT: {
@@ -33,15 +33,15 @@ void b(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0
3333
// B-NEXT: "patch": 0
3434
// B-NEXT: },
3535
// B-NEXT: "obsoleted": {
36-
// B-NEXT: "major": 20,
36+
// B-NEXT: "major": 30,
3737
// B-NEXT: "minor": 0,
3838
// B-NEXT: "patch": 0
3939
// B-NEXT: }
4040
// B-NEXT: }
4141
// B-NEXT: ]
4242

4343
// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix E
44-
void c(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0, obsoleted=20.0))) __attribute__((availability(ios, introduced=13.0)));
44+
void c(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0, obsoleted=30.0))) __attribute__((availability(ios, introduced=13.0)));
4545
// C-LABEL: "!testLabel": "c:@F@c"
4646
// C: "availability": [
4747
// C-NEXT: {
@@ -57,7 +57,7 @@ void c(void) __attribute__((availability(macos, introduced=11.0, deprecated=12.0
5757
// C-NEXT: "patch": 0
5858
// C-NEXT: },
5959
// C-NEXT: "obsoleted": {
60-
// C-NEXT: "major": 20,
60+
// C-NEXT: "major": 30,
6161
// C-NEXT: "minor": 0,
6262
// C-NEXT: "patch": 0
6363
// C-NEXT: }

0 commit comments

Comments
 (0)