[llvm-branch-commits] [clang] 992f540 - [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 8 03:30:19 PDT 2023
Author: zoecarver
Date: 2023-08-08T12:29:46+02:00
New Revision: 992f540fa247da18526af7ae8fb74999d9e77fce
URL: https://github.com/llvm/llvm-project/commit/992f540fa247da18526af7ae8fb74999d9e77fce
DIFF: https://github.com/llvm/llvm-project/commit/992f540fa247da18526af7ae8fb74999d9e77fce.diff
LOG: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS
This cherry-picks https://github.com/apple/llvm-project/pull/6431
since without it, macOS 14 SDK headers don't compile when targeting
catalyst.
Fixes #64438.
(cherry picked from commit bb58748e52ebd48a46de20525ef2c594db044a11)
Added:
clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
Modified:
clang/lib/Sema/SemaAvailability.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp
index 05ad42780e5006..84c06566387ccb 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -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) {
diff --git a/clang/test/SemaCXX/suppress-availability-error-cf-options.cpp b/clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
new file mode 100644
index 00000000000000..c28018464513f9
--- /dev/null
+++ b/clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
@@ -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
+};
More information about the llvm-branch-commits
mailing list