[PATCH] D82823: canonicalize macOS 10.16 availability to macOS 11 while preserving uses of if @available macOS 10.16

2020-06-30 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

LGTM, after mine and Aaron's comments.




Comment at: clang/lib/Sema/SemaExpr.cpp:19195-19211
+if (Spec == AvailSpecs.end())
+  return None;
+if (Platform == "macos") {
+  return ObjCAvailabilityCheckExpr::VersionAsWritten{
+  llvm::Triple::getCanonicalVersionForOS(llvm::Triple::MacOSX,
+ Spec->getVersion()),
+  Spec->getVersion()};

nit: The lambda returning an optional seems a little overkill here, e.g. seems 
this could just be:

```
ObjCAvailabilityCheckExpr::VersionAsWritten Version;
if (Spec != AvailSpecs.end()) {
  if (Platform == "macos") {
Version = ObjCAvailabilityCheckExpr::VersionAsWritten{
llvm::Triple::getCanonicalVersionForOS(llvm::Triple::MacOSX,
   Spec->getVersion()),
Spec->getVersion()};
  } else {
Version = 
ObjCAvailabilityCheckExpr::VersionAsWritten{Spec->getVersion(),
   Spec->getVersion()};
  }
}
```


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

https://reviews.llvm.org/D82823



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


[PATCH] D82823: canonicalize macOS 10.16 availability to macOS 11 while preserving uses of if @available macOS 10.16

2020-06-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/ExprObjC.h:1719-1721
+  VersionTuple getVersion() { return VersionToCheck.Version; }
+  VersionTuple getVersionAsWritten() { return VersionToCheck.SourceVersion; }
 

Any reason these functions aren't marked `const`?


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

https://reviews.llvm.org/D82823



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


[PATCH] D82823: canonicalize macOS 10.16 availability to macOS 11 while preserving uses of if @available macOS 10.16

2020-06-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: erik.pilkington, steven_wu.
Herald added subscribers: ributzka, dexonsmith, jkorous.
Herald added a reviewer: aaron.ballman.

This patch canonicalizes the macOS versions in the `availability`, so that 
clang can treat macOS 10.16 availability as macOS 11 availability. The `if 
(@available (macOS 10.16, *)` checks still preserve their original version in 
the generated code to ensure that the software running on macOS Big Sur Beta 1 
can still exhibits the expected runtime behavior for the `10.16` availability 
checks.


https://reviews.llvm.org/D82823

Files:
  clang/include/clang/AST/ExprObjC.h
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CodeGen/attr-availability-new.c
  clang/test/CodeGenObjC/availability-check.m
  clang/test/Sema/attr-availability-macos-new.c

Index: clang/test/Sema/attr-availability-macos-new.c
===
--- /dev/null
+++ clang/test/Sema/attr-availability-macos-new.c
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-macos10.15" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-macos11" -DNEW -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-darwin20" -DNEW -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-macos10.15" -fsyntax-only -verify -fapplication-extension -DAPP_EXT %s
+
+__attribute__((availability(macos,strict,introduced=10.16)))
+void fNew1();
+#ifndef NEW
+// expected-note@-2 {{here}}
+#endif
+
+__attribute__((availability(macosx,strict,introduced=10.16)))
+void fNew();
+
+__attribute__((availability(macos,strict,introduced=11)))
+void fNew() { }
+#ifndef NEW
+// expected-note@-2 {{here}}
+#endif
+
+__attribute__((availability(macosx,strict,deprecated=10.16)))
+void fDep();
+
+__attribute__((availability(macos,strict,deprecated=11)))
+void fDep() { }
+#ifdef NEW
+// expected-note@-2 {{here}}
+#endif
+
+__attribute__((availability(macosx,strict,obsoleted=10.16)))
+void fObs();
+
+__attribute__((availability(macos,strict,obsoleted=11)))
+void fObs() { }
+#ifdef NEW
+// expected-note@-2 {{here}}
+#endif
+
+__attribute__((availability(macosx_app_extension,strict,introduced=10.16)))
+void fAppExt();
+
+__attribute__((availability(macos_app_extension,strict,introduced=11)))
+void fAppExt() { }
+#ifdef APP_EXT
+// expected-note@-2 {{here}}
+#endif
+
+void testVersionRemapping() {
+  fNew1();
+#ifndef NEW
+  // expected-error@-2 {{'fNew1' is unavailable: introduced in macOS 11.0}}
+#endif
+  fNew();
+#ifndef NEW
+  // expected-error@-2 {{'fNew' is unavailable: introduced in macOS 11}}
+#endif
+  fDep();
+#ifdef NEW
+  // expected-warning@-2 {{'fDep' is deprecated: first deprecated in macOS 11}}
+#endif
+  fObs();
+#ifdef NEW
+  // expected-error@-2 {{'fObs' is unavailable: obsoleted in macOS 11}}
+#endif
+
+  fAppExt();
+#ifdef APP_EXT
+  // expected-error@-2 {{'fAppExt' is unavailable: introduced in macOS (App Extension) 11}}
+#endif
+}
+
+__attribute__((availability(macosx,strict,introduced=10.16.1))) // expected-note {{here}}
+void fMatchErr();
+
+__attribute__((availability(macos,strict,introduced=11))) // expected-warning {{availability does not match previous declaration}}
+void fMatchErr() { }
+
+__attribute__((availability(macosx_app_extension,strict,introduced=10.16))) // expected-note {{here}}
+void fAppExtErr();
+
+__attribute__((availability(macos_app_extension,strict,introduced=11.1))) // expected-warning {{availability does not match previous declaration}}
+void fAppExtErr() { }
+
+__attribute__((availability(macos,introduced=11)))
+void fNew2();
+#ifndef NEW
+  // expected-note@-2 {{'fNew2' has been marked as being introduced in macOS 11 here, but the deployment target is macOS 10.15.0}}
+#endif
+__attribute__((availability(macos,introduced=10.16)))
+void fNew3();
+
+__attribute__((availability(macos,introduced=12)))
+void evenNewer();
+#ifdef NEW
+  // expected-note@-2 {{'evenNewer' has been marked as being introduced in macOS 12 here, but the deployment target is macOS 11.0.0}}
+#endif
+
+void testAvailabilityCheck() {
+  if (__builtin_available(macOS 10.16, *)) {
+fNew2();
+fNew3();
+  }
+  if (__builtin_available(macOS 11, *)) {
+fNew2();
+fNew3();
+  }
+  fNew2();
+#ifndef NEW
+  // expected-warning@-2 {{'fNew2' is only available on macOS 11 or newer}} expected-note@-2 {{enclose}}
+#endif
+#ifdef NEW
+  evenNewer(); // expected-warning {{'evenNewer' is only available on macOS 12 or newer}} expected-note {{enclose}}
+#endif
+}
+
+
Index: clang/test/CodeGenObjC/availability-check.m
===
--- clang/test/CodeGenObjC/availability-check.m
+++ clang/test/CodeGenObjC/availability-check.m
@@ -26,6 +26,15 @@
   // CHECK: br i1 true
   if (__builtin_available(ma