Skip to content

Commit f1c48da

Browse files
committed
Normalize version tuples in availability attributes coming from clang to use "."
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 0d2f8f2 commit f1c48da

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

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

70307030
StringRef message = avail->getMessage();
70317031

7032-
const auto &deprecated = avail->getDeprecated();
7032+
clang::VersionTuple deprecated = avail->getDeprecated();
7033+
70337034
if (!deprecated.empty()) {
70347035
if (platformAvailability.deprecatedAsUnavailableFilter &&
70357036
platformAvailability.deprecatedAsUnavailableFilter(
@@ -7041,8 +7042,14 @@ void ClangImporter::Implementation::importAttributes(
70417042
}
70427043
}
70437044

7044-
const auto &obsoleted = avail->getObsoleted();
7045-
const auto &introduced = avail->getIntroduced();
7045+
clang::VersionTuple obsoleted = avail->getObsoleted();
7046+
clang::VersionTuple introduced = avail->getIntroduced();
7047+
7048+
// Swift only allows "." separators.
7049+
obsoleted.UseDotAsSeparator();
7050+
introduced.UseDotAsSeparator();
7051+
deprecated.UseDotAsSeparator();
7052+
70467053
const auto &replacement = avail->getReplacement();
70477054

70487055
StringRef swiftReplacement = "";

test/IDE/Inputs/print_clang_header/header-to-print.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ struct Arkham;
3232
@protocol Soul;
3333

3434
typedef struct __attribute__((objc_bridge(id))) __MyLittleCFType *MyLittleCFType;
35+
36+
@interface MaybeAvailable
37+
-(void)method1 __attribute__((availability(macosx, introduced=10.1)));
38+
-(void)method2 __attribute__((availability(macosx, introduced=10_1)));
39+
-(void)method3 __attribute__((availability(macosx, deprecated=10_10)));
40+
-(void)method4 __attribute__((availability(macosx, introduced=10_1, deprecated=10_10, obsoleted=10_11)));
41+
@end

test/IDE/Inputs/print_clang_header/header-to-print.h.command-line-include.printed.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,22 @@ protocol Superproto {
2828

2929
class MyLittleCFType {
3030
}
31+
32+
class MaybeAvailable {
33+
@available(OSX 10.1, *)
34+
class func method1()
35+
@available(OSX 10.1, *)
36+
func method1()
37+
@available(OSX 10.1, *)
38+
class func method2()
39+
@available(OSX 10.1, *)
40+
func method2()
41+
@available(OSX, deprecated: 10.10)
42+
class func method3()
43+
@available(OSX, deprecated: 10.10)
44+
func method3()
45+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
46+
class func method4()
47+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
48+
func method4()
49+
}

test/IDE/Inputs/print_clang_header/header-to-print.h.module.printed.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,22 @@ protocol Superproto {
2525

2626
class MyLittleCFType : _CFObject {
2727
}
28+
29+
class MaybeAvailable {
30+
@available(OSX 10.1, *)
31+
class func method1()
32+
@available(OSX 10.1, *)
33+
func method1()
34+
@available(OSX 10.1, *)
35+
class func method2()
36+
@available(OSX 10.1, *)
37+
func method2()
38+
@available(OSX, deprecated: 10.10)
39+
class func method3()
40+
@available(OSX, deprecated: 10.10)
41+
func method3()
42+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
43+
class func method4()
44+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
45+
func method4()
46+
}

test/IDE/Inputs/print_clang_header/header-to-print.h.printed.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,22 @@ protocol Superproto {
2828

2929
class MyLittleCFType : _CFObject {
3030
}
31+
32+
class MaybeAvailable {
33+
@available(OSX 10.1, *)
34+
class func method1()
35+
@available(OSX 10.1, *)
36+
func method1()
37+
@available(OSX 10.1, *)
38+
class func method2()
39+
@available(OSX 10.1, *)
40+
func method2()
41+
@available(OSX, deprecated: 10.10)
42+
class func method3()
43+
@available(OSX, deprecated: 10.10)
44+
func method3()
45+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
46+
class func method4()
47+
@available(OSX, introduced: 10.1, deprecated: 10.10, obsoleted: 10.11)
48+
func method4()
49+
}

0 commit comments

Comments
 (0)