Skip to content

Commit 992f540

Browse files
zoecarvertru
authored andcommitted
[clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS
This cherry-picks swiftlang#6431 since without it, macOS 14 SDK headers don't compile when targeting catalyst. Fixes #64438. (cherry picked from commit bb58748)
1 parent ed4284a commit 992f540

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ ShouldDiagnoseAvailabilityInContext(Sema &S, AvailabilityResult K,
123123
const NamedDecl *OffendingDecl) {
124124
assert(K != AR_Available && "Expected an unavailable declaration here!");
125125

126+
// If this was defined using CF_OPTIONS, etc. then ignore the diagnostic.
127+
auto DeclLoc = Ctx->getBeginLoc();
128+
// This is only a problem in Foundation's C++ implementation for CF_OPTIONS.
129+
if (DeclLoc.isMacroID() && S.getLangOpts().CPlusPlus &&
130+
isa<TypedefDecl>(OffendingDecl)) {
131+
StringRef MacroName = S.getPreprocessor().getImmediateMacroName(DeclLoc);
132+
if (MacroName == "CF_OPTIONS" || MacroName == "OBJC_OPTIONS" ||
133+
MacroName == "SWIFT_OPTIONS" || MacroName == "NS_OPTIONS") {
134+
return false;
135+
}
136+
}
137+
126138
// Checks if we should emit the availability diagnostic in the context of C.
127139
auto CheckContext = [&](const Decl *C) {
128140
if (K == AR_NotYetIntroduced) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// expected-no-diagnostics
3+
4+
#define CF_OPTIONS(_type, _name) __attribute__((availability(swift, unavailable))) _type _name; enum : _name
5+
6+
__attribute__((availability(macOS, unavailable)))
7+
typedef CF_OPTIONS(unsigned, TestOptions) {
8+
x
9+
};

0 commit comments

Comments
 (0)