Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / attr-availability.c
bloba5cc602a8fa9d460d068ace5e16b2c151212bf8a
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -fblocks -verify %s
2 // RUN: %clang_cc1 -D WARN_PARTIAL -Wpartial-availability -triple x86_64-apple-darwin9 -fsyntax-only -fblocks -verify %s
3 //
5 void f0(void) __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in macOS version 10.2 before it was introduced in version 10.4; attribute ignored}}
6 void f1(void) __attribute__((availability(ios,obsoleted=2.1,deprecated=3.0))); // expected-warning{{feature cannot be obsoleted in iOS version 2.1 before it was deprecated in version 3.0; attribute ignored}}
7 void f2(void) __attribute__((availability(ios,introduced=2.1,deprecated=2.1)));
9 void f3(void) __attribute__((availability(otheros,introduced=2.2))); // expected-warning{{unknown platform 'otheros' in availability macro}}
11 extern void
12 ATSFontGetName(const char *oName) __attribute__((availability(macosx,introduced=8.0,deprecated=9.0, message="use CTFontCopyFullName"))); // expected-note {{'ATSFontGetName' has been explicitly marked deprecated here}}
14 extern void
15 ATSFontGetPostScriptName(int flags) __attribute__((availability(macosx,introduced=8.0,obsoleted=9.0, message="use ATSFontGetFullPostScriptName"))); // expected-note {{'ATSFontGetPostScriptName' has been explicitly marked unavailable here}}
17 #if defined(WARN_PARTIAL)
18 // expected-note@+3 {{'PartiallyAvailable' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
19 #endif
20 extern void
21 PartiallyAvailable(void) __attribute__((availability(macosx,introduced=10.8)));
23 #ifdef WARN_PARTIAL
24 // expected-note@+2 2 {{'PartialEnum' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
25 #endif
26 enum __attribute__((availability(macosx,introduced=10.8))) PartialEnum {
27 kPartialEnumConstant,
30 void test_10095131(void) {
31 ATSFontGetName("Hello"); // expected-warning {{'ATSFontGetName' is deprecated: first deprecated in macOS 9.0 - use CTFontCopyFullName}}
32 ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in macOS 9.0 - use ATSFontGetFullPostScriptName}}
34 #if defined(WARN_PARTIAL)
35 // expected-warning@+2 {{is only available on macOS 10.8 or newer}} expected-note@+2 {{enclose 'PartiallyAvailable' in a __builtin_available check to silence this warning}}
36 #endif
37 PartiallyAvailable();
40 #ifdef WARN_PARTIAL
41 // FIXME: This note should point to the declaration with the availability
42 // attribute.
43 // expected-note@+2 {{'PartiallyAvailable' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
44 #endif
45 extern void PartiallyAvailable(void) ;
46 void with_redeclaration(void) {
47 #ifdef WARN_PARTIAL
48 // expected-warning@+4 {{'PartiallyAvailable' is only available on macOS 10.8 or newer}} expected-note@+4 {{__builtin_available}}
49 // expected-warning@+4 {{'PartialEnum' is only available on macOS 10.8 or newer}} expected-note@+4 {{__builtin_available}}
50 // expected-warning@+3 {{'kPartialEnumConstant' is only available on macOS 10.8 or newer}} expected-note@+3 {{__builtin_available}}
51 #endif
52 PartiallyAvailable();
53 enum PartialEnum p = kPartialEnumConstant;
56 __attribute__((availability(macos, unavailable))) // expected-warning {{attribute 'availability' is ignored}}
57 enum {
58 NSDataWritingFileProtectionWriteOnly = 0x30000000,
59 NSDataWritingFileProtectionCompleteUntilUserAuthentication = 0x40000000,
62 void f4(int) __attribute__((availability(ios,deprecated=3.0)));
63 void f4(int) __attribute__((availability(ios,introduced=4.0))); // expected-warning {{feature cannot be deprecated in iOS version 3.0 before it was introduced in version 4.0; attribute ignored}}
65 void f5(int) __attribute__((availability(ios,deprecated=3.0), // expected-warning {{feature cannot be deprecated in iOS version 3.0 before it was introduced in version 4.0; attribute ignored}}
66 availability(ios,introduced=4.0)));
68 void f6(int) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{previous attribute is here}}
69 void f6(int) __attribute__((availability(ios,deprecated=4.0))); // expected-warning {{availability does not match previous declaration}}
71 void f7(int) __attribute__((availability(ios,introduced=2.0)));
72 void f7(int) __attribute__((availability(ios,deprecated=3.0))); // expected-note {{previous attribute is here}}
73 void f7(int) __attribute__((availability(ios,deprecated=4.0))); // expected-warning {{availability does not match previous declaration}}
75 #if !__has_feature(attribute_availability_with_message)
76 # error "Missing __has_feature"
77 #endif
79 extern int x __attribute__((availability(macosx,introduced=10.5)));
80 extern int x;
82 void f8(void) {
83 int (^b)(int);
84 b = ^ (int i) __attribute__((availability(macosx,introduced=10.2))) { return 1; }; // expected-warning {{'availability' attribute only applies to named declarations}}
87 extern int x2 __attribute__((availability(macosx,introduced=10.2))); // expected-note {{previous attribute is here}}
88 extern int x2 __attribute__((availability(macosx,introduced=10.5))); // expected-warning {{availability does not match previous declaration}}
91 enum Original {
92 OriginalDeprecated __attribute__((availability(macosx, deprecated=10.2))), // expected-note + {{'OriginalDeprecated' has been explicitly marked deprecated here}}
93 OriginalUnavailable __attribute__((availability(macosx, unavailable))) // expected-note + {{'OriginalUnavailable' has been explicitly marked unavailable here}}
96 enum AllDeprecated { // expected-note + {{'AllDeprecated' has been explicitly marked deprecated here}}
97 AllDeprecatedCase,
98 AllDeprecatedUnavailable __attribute__((availability(macosx, unavailable))) // expected-note + {{'AllDeprecatedUnavailable' has been explicitly marked unavailable here}}
99 } __attribute__((availability(macosx, deprecated=10.2)));
101 enum AllUnavailable { // expected-note + {{'AllUnavailable' has been explicitly marked unavailable here}}
102 AllUnavailableCase,
103 } __attribute__((availability(macosx, unavailable)));
105 enum User {
106 UserOD = OriginalDeprecated, // expected-warning {{deprecated}}
107 UserODDeprecated __attribute__((availability(macosx, deprecated=10.2))) = OriginalDeprecated,
108 UserODUnavailable __attribute__((availability(macosx, unavailable))) = OriginalDeprecated,
110 UserOU = OriginalUnavailable, // expected-error {{unavailable}}
111 UserOUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = OriginalUnavailable, // expected-error {{unavailable}}
112 UserOUUnavailable __attribute__((availability(macosx, unavailable))) = OriginalUnavailable,
114 UserAD = AllDeprecatedCase, // expected-warning {{deprecated}}
115 UserADDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllDeprecatedCase,
116 UserADUnavailable __attribute__((availability(macosx, unavailable))) = AllDeprecatedCase,
118 UserADU = AllDeprecatedUnavailable, // expected-error {{unavailable}}
119 UserADUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllDeprecatedUnavailable, // expected-error {{unavailable}}
120 UserADUUnavailable __attribute__((availability(macosx, unavailable))) = AllDeprecatedUnavailable,
122 UserAU = AllUnavailableCase, // expected-error {{unavailable}}
123 UserAUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllUnavailableCase, // expected-error {{unavailable}}
124 UserAUUnavailable __attribute__((availability(macosx, unavailable))) = AllUnavailableCase,
127 enum UserDeprecated {
128 UserDeprecatedOD = OriginalDeprecated,
129 UserDeprecatedODDeprecated __attribute__((availability(macosx, deprecated=10.2))) = OriginalDeprecated,
130 UserDeprecatedODUnavailable __attribute__((availability(macosx, unavailable))) = OriginalDeprecated,
132 UserDeprecatedOU = OriginalUnavailable, // expected-error {{unavailable}}
133 UserDeprecatedOUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = OriginalUnavailable, // expected-error {{unavailable}}
134 UserDeprecatedOUUnavailable __attribute__((availability(macosx, unavailable))) = OriginalUnavailable,
136 UserDeprecatedAD = AllDeprecatedCase,
137 UserDeprecatedADDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllDeprecatedCase,
138 UserDeprecatedADUnavailable __attribute__((availability(macosx, unavailable))) = AllDeprecatedCase,
140 UserDeprecatedADU = AllDeprecatedUnavailable, // expected-error {{unavailable}}
141 UserDeprecatedADUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllDeprecatedUnavailable, // expected-error {{unavailable}}
142 UserDeprecatedADUUnavailable __attribute__((availability(macosx, unavailable))) = AllDeprecatedUnavailable,
144 UserDeprecatedAU = AllUnavailableCase, // expected-error {{unavailable}}
145 UserDeprecatedAUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllUnavailableCase, // expected-error {{unavailable}}
146 UserDeprecatedAUUnavailable __attribute__((availability(macosx, unavailable))) = AllUnavailableCase,
147 } __attribute__((availability(macosx, deprecated=10.2)));
149 enum UserUnavailable {
150 UserUnavailableOD = OriginalDeprecated,
151 UserUnavailableODDeprecated __attribute__((availability(macosx, deprecated=10.2))) = OriginalDeprecated,
152 UserUnavailableODUnavailable __attribute__((availability(macosx, unavailable))) = OriginalDeprecated,
154 UserUnavailableOU = OriginalUnavailable,
155 UserUnavailableOUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = OriginalUnavailable,
156 UserUnavailableOUUnavailable __attribute__((availability(macosx, unavailable))) = OriginalUnavailable,
158 UserUnavailableAD = AllDeprecatedCase,
159 UserUnavailableADDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllDeprecatedCase,
160 UserUnavailableADUnavailable __attribute__((availability(macosx, unavailable))) = AllDeprecatedCase,
162 UserUnavailableADU = AllDeprecatedUnavailable,
163 UserUnavailableADUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllDeprecatedUnavailable,
164 UserUnavailableADUUnavailable __attribute__((availability(macosx, unavailable))) = AllDeprecatedUnavailable,
166 UserUnavailableAU = AllUnavailableCase,
167 UserUnavailableAUDeprecated __attribute__((availability(macosx, deprecated=10.2))) = AllUnavailableCase,
168 UserUnavailableAUUnavailable __attribute__((availability(macosx, unavailable))) = AllUnavailableCase,
169 } __attribute__((availability(macosx, unavailable)));