Skip to content

Commit

Permalink
[clang/cxx-interop] Teach clang to ignore availability errors that co…
Browse files Browse the repository at this point in the history
…me from CF_OPTIONS

This cherry-picks apple#6431
since without it, macOS 14 SDK headers don't compile when targeting
catalyst.

Fixes #64438.
  • Loading branch information
zoecarver authored and nico committed Aug 7, 2023
1 parent 8baf862 commit bb58748
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions clang/lib/Sema/SemaAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ ShouldDiagnoseAvailabilityInContext(Sema &S, AvailabilityResult K,
const NamedDecl *OffendingDecl) {
assert(K != AR_Available && "Expected an unavailable declaration here!");

// If this was defined using CF_OPTIONS, etc. then ignore the diagnostic.
auto DeclLoc = Ctx->getBeginLoc();
// This is only a problem in Foundation's C++ implementation for CF_OPTIONS.
if (DeclLoc.isMacroID() && S.getLangOpts().CPlusPlus &&
isa<TypedefDecl>(OffendingDecl)) {
StringRef MacroName = S.getPreprocessor().getImmediateMacroName(DeclLoc);
if (MacroName == "CF_OPTIONS" || MacroName == "OBJC_OPTIONS" ||
MacroName == "SWIFT_OPTIONS" || MacroName == "NS_OPTIONS") {
return false;
}
}

// Checks if we should emit the availability diagnostic in the context of C.
auto CheckContext = [&](const Decl *C) {
if (K == AR_NotYetIntroduced) {
Expand Down
9 changes: 9 additions & 0 deletions clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics

#define CF_OPTIONS(_type, _name) __attribute__((availability(swift, unavailable))) _type _name; enum : _name

__attribute__((availability(macOS, unavailable)))
typedef CF_OPTIONS(unsigned, TestOptions) {
x
};

0 comments on commit bb58748

Please sign in to comment.