Skip to content

Commit fc55631

Browse files
committed
Reapply "Normalize version tuples in availability attributes coming from clang to use ".""
This reapplies f1c48da with the test split up so that the availability bits don't affect other platforms. Seen as @available attributes being printed with "_" in interface generation, but fixing it in the importer means they can't leak into anywhere else. rdar://problem/30451293
1 parent 461c764 commit fc55631

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7174,7 +7174,8 @@ void ClangImporter::Implementation::importAttributes(
71747174

71757175
StringRef message = avail->getMessage();
71767176

7177-
const auto &deprecated = avail->getDeprecated();
7177+
clang::VersionTuple deprecated = avail->getDeprecated();
7178+
71787179
if (!deprecated.empty()) {
71797180
if (platformAvailability.deprecatedAsUnavailableFilter &&
71807181
platformAvailability.deprecatedAsUnavailableFilter(
@@ -7186,8 +7187,14 @@ void ClangImporter::Implementation::importAttributes(
71867187
}
71877188
}
71887189

7189-
const auto &obsoleted = avail->getObsoleted();
7190-
const auto &introduced = avail->getIntroduced();
7190+
clang::VersionTuple obsoleted = avail->getObsoleted();
7191+
clang::VersionTuple introduced = avail->getIntroduced();
7192+
7193+
// Swift only allows "." separators.
7194+
obsoleted.UseDotAsSeparator();
7195+
introduced.UseDotAsSeparator();
7196+
deprecated.UseDotAsSeparator();
7197+
71917198
const auto &replacement = avail->getReplacement();
71927199

71937200
StringRef swiftReplacement = "";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@interface MaybeAvailable
2+
-(void)method1 __attribute__((availability(macosx, introduced=10.1)));
3+
-(void)method2 __attribute__((availability(macosx, introduced=10_1)));
4+
-(void)method3 __attribute__((availability(macosx, deprecated=10_10)));
5+
-(void)method4 __attribute__((availability(macosx, introduced=10_1, deprecated=10_10, obsoleted=10_11)));
6+
@end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class MaybeAvailable {
2+
@available(OSX 10.1, *)
3+
class func method1()
4+
@available(OSX 10.1, *)
5+
func method1()
6+
@available(OSX 10.1, *)
7+
class func method2()
8+
@available(OSX 10.1, *)
9+
func method2()
10+
@available(OSX, deprecated: 10.10)
11+
class func method3()
12+
@available(OSX, deprecated: 10.10)
13+
func method3()
14+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
15+
class func method4()
16+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
17+
func method4()
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class MaybeAvailable {
2+
@available(OSX 10.1, *)
3+
class func method1()
4+
@available(OSX 10.1, *)
5+
func method1()
6+
@available(OSX 10.1, *)
7+
class func method2()
8+
@available(OSX 10.1, *)
9+
func method2()
10+
@available(OSX, deprecated: 10.10)
11+
class func method3()
12+
@available(OSX, deprecated: 10.10)
13+
func method3()
14+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
15+
class func method4()
16+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
17+
func method4()
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module HeaderToPrintAvailability {
2+
header "header-to-print-availability.h"
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// REQUIRES: OS=macosx
2+
3+
// RUN: %empty-directory(%t)
4+
5+
// RUN: echo '#include "header-to-print-availability.h"' > %t.m
6+
// RUN: cp %S/Inputs/print_clang_header/header-to-print-availability.h %t/
7+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -source-filename %s -print-header -header-to-print %t/header-to-print-availability.h -print-regular-comments --cc-args %target-cc-options -isysroot %clang-importer-sdk-path -fsyntax-only %t.m -I %t > %t.txt
8+
// RUN: diff -u %S/Inputs/print_clang_header/header-to-print-availability.h.printed.txt %t.txt
9+
10+
// RUN: echo '@import HeaderToPrintAvailability;' > %t.module.m
11+
// Test header interface printing from a clang module.
12+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -source-filename %s -print-header -header-to-print %S/Inputs/print_clang_header/header-to-print-availability.h -print-regular-comments --cc-args %target-cc-options -isysroot %clang-importer-sdk-path -fsyntax-only %t.module.m -I %S/Inputs/print_clang_header > %t.module.txt
13+
// RUN: diff -u %S/Inputs/print_clang_header/header-to-print-availability.h.module.printed.txt %t.module.txt

0 commit comments

Comments
 (0)