[PATCH] D92495: [clang] Add a new nullability annotation for swift async: _Nullable_result

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 3 09:34:50 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/Basic/AttrDocs.td:3516
+``_Nullable_result`` pointer can be ``nil``, just like ``_Nullable``. Where this
+attribute differs from ``_Nullable`` is when its used on a parameter to a
+completion handler in a Swift async method. For instance, here:
----------------
its -> it's


================
Comment at: clang/include/clang/Basic/AttrDocs.td:3526
+available, or calls it with an error. ``_Nullable_result`` indicates to the
+Swift imported that this is the uncommon case where ``result`` can get ``nil``
+even if no error has occured, and will therefore import it as a Swift optional
----------------
Swift imported -> Swift importer


================
Comment at: clang/lib/Basic/IdentifierTable.cpp:718-719
+  case NullabilityKind::NullableResult:
+    assert(!isContextSensitive &&
+           "_Nullable_result isn't supported as context-sensitive keyword");
+    return "_Nullable_result";
----------------
Can you explain why it differs from `_Nullable` in this case?


================
Comment at: clang/lib/Sema/SemaExprObjC.cpp:1566
   unsigned receiverNullabilityIdx = 0;
-  if (auto nullability = ReceiverType->getNullability(Context))
+  if (auto nullability = ReceiverType->getNullability(Context)) {
+    if (*nullability == NullabilityKind::NullableResult)
----------------
Should that be `auto *`?


================
Comment at: clang/lib/Sema/SemaExprObjC.cpp:1573
   unsigned resultNullabilityIdx = 0;
-  if (auto nullability = resultType->getNullability(Context))
+  if (auto nullability = resultType->getNullability(Context)) {
+    if (*nullability == NullabilityKind::NullableResult)
----------------
Same here.


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

https://reviews.llvm.org/D92495



More information about the cfe-commits mailing list