[PATCH] D46747: [Sema] Use dotted form of macOS version for unguarded availability FixIts

Jan Korous via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 14 07:31:01 PDT 2018


jkorous updated this revision to Diff 146605.
jkorous added a comment.

Fixed the test. It turned out that version component separator for availability is set during parsing which is why all other tests (including my bad one) are passing.

The only way how to set underscore as a separator is through VersionTuple constructor...

https://clang.llvm.org/doxygen/classclang_1_1VersionTuple.html#a71e5354ccb617494136bdcb4d208a573

  clang::VersionTuple::VersionTuple	(	unsigned 	Major,
    unsigned 	Minor,
    unsigned 	Subminor,
    unsigned 	Build,
    bool 	UsesUnderscores = false 
  )

...which is exactly what is happening during parsing version tuple...

  VersionTuple Parser::ParseVersionTuple(SourceRange &Range) {
    // ...
    return VersionTuple(Major, Minor, Subminor, (AfterMajorSeparator == '_'));
  }

...which function is called when parsing availability attribute:

  void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability,
    // ...
    VersionTuple Version = ParseVersionTuple(VersionRange);
    // ...
  }


https://reviews.llvm.org/D46747

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/FixIt/fixit-availability-method.mm


Index: test/FixIt/fixit-availability-method.mm
===================================================================
--- /dev/null
+++ test/FixIt/fixit-availability-method.mm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.11 -Wunguarded-availability -fdiagnostics-parseable-fixits -fsyntax-only -verify %s
+
+ at interface foo
+- (void) method_bar __attribute__((availability(macosx, introduced = 10_12))); // expected-note {{'method_bar' has been explicitly marked partial here}}
+ at end
+
+int main() {
+    [foo method_bar]; // \
+    // expected-warning {{'method_bar' is only available on macOS 10.12 or newer}} \
+    // expected-note {{enclose 'method_bar' in an @available check to silence this warning}} \
+    // CHECK: "fix-it:.*if (@available(macOS 10.12, *))"
+    return 0;
+}
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7467,6 +7467,7 @@
     const AvailabilityAttr *AA =
       getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
     VersionTuple Introduced = AA->getIntroduced();
+    Introduced.UseDotAsSeparator();
 
     if (AvailabilityStack.back() >= Introduced)
       return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46747.146605.patch
Type: text/x-patch
Size: 1244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180514/ed638988/attachment.bin>


More information about the cfe-commits mailing list