[PATCH] D108592: [WIP][clang][Fuchsia] Support __attribute__((availability)) on Fuchsia

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 23 15:41:29 PDT 2021


leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr.
leonardchan added a project: clang.
Herald added a reviewer: aaron.ballman.
leonardchan requested review of this revision.

This also adds a warning that triggers when a non-zero minor/subminor are used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108592

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/attr-availability-fuchsia.c


Index: clang/test/Sema/attr-availability-fuchsia.c
===================================================================
--- /dev/null
+++ clang/test/Sema/attr-availability-fuchsia.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 "-triple" "x86_64-unknown-fuchsia16" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(fuchsia, introduced = 14, deprecated = 19)));
+void f1(int) __attribute__((availability(fuchsia, introduced = 16)));
+void f2(int) __attribute__((availability(fuchsia, introduced = 14, deprecated = 16))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(fuchsia, introduced = 19)));
+void f4(int) __attribute__((availability(fuchsia, introduced = 9, deprecated = 11, obsoleted = 16), availability(ios, introduced = 2.0, deprecated = 3.0))); // expected-note{{explicitly marked unavailable}}
+void f5(int) __attribute__((availability(ios, introduced = 3.2), availability(fuchsia, unavailable)));                                                       // expected-note{{'f5' has been explicitly marked unavailable here}}
+void f6(int) __attribute__((availability(fuchsia, introduced = 16.0)));
+void f7(int) __attribute__((availability(fuchsia, introduced = 16.1))); // expected-warning {{Fuchsia versions only support 'major', not '.minor[.subminor]}}
+
+void test() {
+  f0(0);
+  f1(0);
+  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in Fuchsia 16}}
+  f3(0);
+  f4(0); // expected-error{{f4' is unavailable: obsoleted in Fuchsia 16}}
+  f5(0); // expected-error{{'f5' is unavailable: not available on Fuchsia}}
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2488,6 +2488,15 @@
     }
   }
 
+  if (II->isStr("fuchsia")) {
+    Optional<unsigned> Min, Sub;
+    if (((Min = Introduced.Version.getMinor()) && Min.getValue()) ||
+        ((Sub = Introduced.Version.getSubminor()) && Sub.getValue())) {
+      S.Diag(AL.getLoc(), diag::warn_availability_fuchsia_unavailable_minor);
+      return;
+    }
+  }
+
   int PriorityModifier = AL.isPragmaClangAttribute()
                              ? Sema::AP_PragmaClangAttribute
                              : Sema::AP_Explicit;
Index: clang/lib/Basic/Targets/OSTargets.h
===================================================================
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -885,6 +885,11 @@
     // Required by the libc++ locale support.
     if (Opts.CPlusPlus)
       Builder.defineMacro("_GNU_SOURCE");
+
+    unsigned Maj, Min, Rev;
+    Triple.getOSVersion(Maj, Min, Rev);
+    this->PlatformName = "fuchsia";
+    this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
   }
 
 public:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3543,6 +3543,9 @@
   InGroup<Availability>;
 def note_protocol_method : Note<
   "protocol method is here">;
+def warn_availability_fuchsia_unavailable_minor : Warning<
+  "Fuchsia versions only support 'major', not '.minor[.subminor]'">,
+  InGroup<Availability>;
 
 def warn_unguarded_availability :
   Warning<"%0 is only available on %1 %2 or newer">,
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -848,6 +848,7 @@
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
     return llvm::StringSwitch<llvm::StringRef>(Platform)
              .Case("android", "Android")
+             .Case("fuchsia", "Fuchsia")
              .Case("ios", "iOS")
              .Case("macos", "macOS")
              .Case("tvos", "tvOS")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108592.368224.patch
Type: text/x-patch
Size: 3955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210823/38ce8e42/attachment-0001.bin>


More information about the cfe-commits mailing list