[PATCH] D157245: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-07 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D157245#4565166 , @hans wrote:

> lgtm

Thanks!

> Maybe we want this for the release/17.x branch too?

Sure, trying that here: https://github.com/llvm/llvm-project/issues/64496


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157245/new/

https://reviews.llvm.org/D157245

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157245: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-07 Thread Nico Weber via Phabricator via cfe-commits
thakis closed this revision.
thakis added a comment.

bb58748e52ebd48a46de20525ef2c594db044a11 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157245/new/

https://reviews.llvm.org/D157245

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157245: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm

Maybe we want this for the release/17.x branch too?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157245/new/

https://reviews.llvm.org/D157245

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157245: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-06 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hans.
Herald added a project: All.
thakis requested review of this revision.

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.



The github issue has all the details: 
https://github.com/llvm/llvm-project/issues/64438

The patch maybe looks a bit eh, but doing something different downstream also 
seems a bit eh. The system headers are precision matched to this patch.

(I'll commit this with @zoecarver as author to not steal attribution )


https://reviews.llvm.org/D157245

Files:
  clang/lib/Sema/SemaAvailability.cpp
  clang/test/SemaCXX/suppress-availability-error-cf-options.cpp


Index: clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
===
--- /dev/null
+++ 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
+};
Index: clang/lib/Sema/SemaAvailability.cpp
===
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -123,6 +123,18 @@
 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(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) {


Index: clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
===
--- /dev/null
+++ 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
+};
Index: clang/lib/Sema/SemaAvailability.cpp
===
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -123,6 +123,18 @@
 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(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) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits