llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

<details>
<summary>Changes</summary>

This also adds a single use of this new functionality, migrating users of 
std::optional&lt;NullabilityKind&gt;

---

Patch is 21.05 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/191828.diff


17 Files Affected:

- (modified) clang/include/clang/APINotes/Types.h (+18-32) 
- (modified) clang/include/clang/AST/ASTConcept.h (+1-1) 
- (modified) clang/include/clang/AST/ASTContext.h (+1-1) 
- (modified) clang/include/clang/AST/Decl.h (+1-1) 
- (modified) clang/include/clang/AST/TemplateName.h (+1-1) 
- (modified) clang/include/clang/AST/TypeBase.h (+3-3) 
- (modified) clang/include/clang/Basic/Diagnostic.h (+1-1) 
- (added) clang/include/clang/Basic/SmallOptional.h (+79) 
- (modified) clang/include/clang/Basic/Specifiers.h (+3) 
- (removed) clang/include/clang/Basic/UnsignedOrNone.h (-53) 
- (modified) clang/lib/APINotes/APINotesTypes.cpp (+4-4) 
- (modified) clang/lib/AST/Type.cpp (+3-4) 
- (modified) clang/lib/Sema/Sema.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExprObjC.cpp (+3-5) 
- (modified) clang/lib/Sema/SemaType.cpp (+1-1) 


``````````diff
diff --git a/clang/include/clang/APINotes/Types.h 
b/clang/include/clang/APINotes/Types.h
index 0f370953fca59..4a87f36a72cd3 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -233,13 +233,9 @@ inline bool operator!=(const CommonTypeInfo &LHS, const 
CommonTypeInfo &RHS) {
 /// Describes API notes data for an Objective-C class or protocol or a C++
 /// namespace.
 class ContextInfo : public CommonTypeInfo {
-  /// Whether this class has a default nullability.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned HasDefaultNullability : 1;
-
-  /// The default nullability.
-  LLVM_PREFERRED_TYPE(NullabilityKind)
-  unsigned DefaultNullability : 2;
+  /// The default nullability, if any.
+  LLVM_PREFERRED_TYPE(NullabilityKindOrNone)
+  unsigned DefaultNullabilityOrNone : 3;
 
   /// Whether this class has designated initializers recorded.
   LLVM_PREFERRED_TYPE(bool)
@@ -257,7 +253,7 @@ class ContextInfo : public CommonTypeInfo {
 
 public:
   ContextInfo()
-      : HasDefaultNullability(0), DefaultNullability(0), HasDesignatedInits(0),
+      : DefaultNullabilityOrNone(0), HasDesignatedInits(0),
         SwiftImportAsNonGenericSpecified(false), 
SwiftImportAsNonGeneric(false),
         SwiftObjCMembersSpecified(false), SwiftObjCMembers(false) {}
 
@@ -266,17 +262,15 @@ class ContextInfo : public CommonTypeInfo {
   ///
   /// Returns the default nullability, if implied, or std::nullopt if there is
   /// none.
-  std::optional<NullabilityKind> getDefaultNullability() const {
-    return HasDefaultNullability
-               ? std::optional<NullabilityKind>(
-                     static_cast<NullabilityKind>(DefaultNullability))
-               : std::nullopt;
+  NullabilityKindOrNone getDefaultNullability() const {
+    return NullabilityKindOrNone::fromInternalRepresentation(
+        DefaultNullabilityOrNone);
   }
 
   /// Set the default nullability for properties and methods of this class.
   void setDefaultNullability(NullabilityKind Kind) {
-    HasDefaultNullability = true;
-    DefaultNullability = static_cast<unsigned>(Kind);
+    DefaultNullabilityOrNone =
+        NullabilityKindOrNone(Kind).toInternalRepresentation();
   }
 
   bool hasDesignatedInits() const { return HasDesignatedInits; }
@@ -412,30 +406,23 @@ inline bool operator!=(const BoundsSafetyInfo &LHS,
 
 /// API notes for a variable/property.
 class VariableInfo : public CommonEntityInfo {
-  /// Whether this property has been audited for nullability.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned NullabilityAudited : 1;
-
-  /// The kind of nullability for this property. Only valid if the nullability
+  /// The kind of nullability for this property, if the nullability
   /// has been audited.
-  LLVM_PREFERRED_TYPE(NullabilityKind)
-  unsigned Nullable : 2;
+  LLVM_PREFERRED_TYPE(NullabilityKindOrNone)
+  unsigned NullabilityOrNone : 3;
 
   /// The C type of the variable, as a string.
   std::string Type;
 
 public:
-  VariableInfo() : NullabilityAudited(false), Nullable(0) {}
+  VariableInfo() : NullabilityOrNone(0) {}
 
-  std::optional<NullabilityKind> getNullability() const {
-    return NullabilityAudited ? std::optional<NullabilityKind>(
-                                    static_cast<NullabilityKind>(Nullable))
-                              : std::nullopt;
+  NullabilityKindOrNone getNullability() const {
+    return 
NullabilityKindOrNone::fromInternalRepresentation(NullabilityOrNone);
   }
 
   void setNullabilityAudited(NullabilityKind kind) {
-    NullabilityAudited = true;
-    Nullable = static_cast<unsigned>(kind);
+    NullabilityOrNone = NullabilityKindOrNone(kind).toInternalRepresentation();
   }
 
   const std::string &getType() const { return Type; }
@@ -446,7 +433,7 @@ class VariableInfo : public CommonEntityInfo {
   VariableInfo &operator|=(const VariableInfo &RHS) {
     static_cast<CommonEntityInfo &>(*this) |= RHS;
 
-    if (!NullabilityAudited && RHS.NullabilityAudited)
+    if (!getNullability() && RHS.getNullability())
       setNullabilityAudited(*RHS.getNullability());
     if (Type.empty())
       Type = RHS.Type;
@@ -459,8 +446,7 @@ class VariableInfo : public CommonEntityInfo {
 
 inline bool operator==(const VariableInfo &LHS, const VariableInfo &RHS) {
   return static_cast<const CommonEntityInfo &>(LHS) == RHS &&
-         LHS.NullabilityAudited == RHS.NullabilityAudited &&
-         LHS.Nullable == RHS.Nullable && LHS.Type == RHS.Type;
+         LHS.NullabilityOrNone == RHS.NullabilityOrNone && LHS.Type == 
RHS.Type;
 }
 
 inline bool operator!=(const VariableInfo &LHS, const VariableInfo &RHS) {
diff --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index f362f24ebc72a..2aeecb31c7a60 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -17,8 +17,8 @@
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/NestedNameSpecifierBase.h"
 #include "clang/AST/TemplateBase.h"
+#include "clang/Basic/SmallOptional.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/UnsignedOrNone.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index ba1b58489c327..427700ccf77f4 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2997,7 +2997,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
                                        bool IsParam) const {
     auto SubTnullability = SubT->getNullability();
     auto SuperTnullability = SuperT->getNullability();
-    if (SubTnullability.has_value() == SuperTnullability.has_value()) {
+    if (bool(SubTnullability) == bool(SuperTnullability)) {
       // Neither has nullability; return true
       if (!SubTnullability)
         return true;
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 076d9ba935583..1e7d4d4bc9c8f 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -31,9 +31,9 @@
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/PragmaKinds.h"
+#include "clang/Basic/SmallOptional.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Basic/UnsignedOrNone.h"
 #include "clang/Basic/Visibility.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/ArrayRef.h"
diff --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index b6999a1b4e9b9..2be35341500cb 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -17,7 +17,7 @@
 #include "clang/AST/NestedNameSpecifierBase.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/OperatorKinds.h"
-#include "clang/Basic/UnsignedOrNone.h"
+#include "clang/Basic/SmallOptional.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/PointerUnion.h"
diff --git a/clang/include/clang/AST/TypeBase.h 
b/clang/include/clang/AST/TypeBase.h
index 8802b15d99034..a64bbb99b13d2 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -3133,7 +3133,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   /// Note that nullability is only captured as sugar within the type
   /// system, not as part of the canonical type, so nullability will
   /// be lost by canonicalization and desugaring.
-  std::optional<NullabilityKind> getNullability() const;
+  NullabilityKindOrNone getNullability() const;
 
   /// Determine whether the given type can have a nullability
   /// specifier applied to it, i.e., if it is any kind of pointer type.
@@ -6716,7 +6716,7 @@ class AttributedType : public Type, public 
llvm::FoldingSetNode {
 
   bool isCallingConv() const;
 
-  std::optional<NullabilityKind> getImmediateNullability() const;
+  NullabilityKindOrNone getImmediateNullability() const;
 
   /// Strip off the top-level nullability annotation on the given
   /// type, if it's there.
@@ -6727,7 +6727,7 @@ class AttributedType : public Type, public 
llvm::FoldingSetNode {
   /// to the underlying modified type.
   ///
   /// \returns the top-level nullability, if present.
-  static std::optional<NullabilityKind> stripOuterNullability(QualType &T);
+  static NullabilityKindOrNone stripOuterNullability(QualType &T);
 
   void Profile(llvm::FoldingSetNodeID &ID) {
     Profile(ID, getAttrKind(), ModifiedType, EquivalentType, Attribute);
diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index aa05f9d60dadf..08132491a264e 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -16,9 +16,9 @@
 
 #include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SmallOptional.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Basic/UnsignedOrNone.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FunctionExtras.h"
diff --git a/clang/include/clang/Basic/SmallOptional.h 
b/clang/include/clang/Basic/SmallOptional.h
new file mode 100644
index 0000000000000..bef31ce1a53b1
--- /dev/null
+++ b/clang/include/clang/Basic/SmallOptional.h
@@ -0,0 +1,79 @@
+//===- UnsignedOrNone.h - simple optional index-----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+/// \file
+/// Defines clang::UnsignedOrNone.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_UNSIGNED_OR_NONE_H
+#define LLVM_CLANG_BASIC_UNSIGNED_OR_NONE_H
+
+#include <cassert>
+#include <llvm/ADT/STLForwardCompat.h>
+#include <optional>
+
+namespace clang {
+
+template <class T> struct SmallOptional {
+  using underlying_type =
+      typename std::conditional_t<std::is_enum_v<T>, std::underlying_type<T>,
+                                  llvm::type_identity<T>>::type;
+  static_assert(std::is_unsigned_v<underlying_type>);
+
+  constexpr SmallOptional(std::nullopt_t) : Rep(0) {}
+  SmallOptional(T Val) : Rep(static_cast<underlying_type>(Val) + 1) {
+    assert(operator bool());
+  }
+  SmallOptional(int) = delete;
+
+  constexpr static SmallOptional
+  fromInternalRepresentation(underlying_type Rep) {
+    return {std::nullopt, Rep};
+  }
+  constexpr underlying_type toInternalRepresentation() const { return Rep; }
+
+  explicit constexpr operator bool() const { return Rep != 0; }
+  T operator*() const {
+    assert(operator bool());
+    return static_cast<T>(Rep - 1);
+  }
+
+  T value_or(T Def) const { return operator bool() ? operator*() : Def; }
+
+  friend constexpr bool operator==(SmallOptional LHS, SmallOptional RHS) {
+    return LHS && RHS ? *LHS == *RHS : bool(LHS) == bool(RHS);
+  }
+  friend constexpr bool operator!=(SmallOptional LHS, SmallOptional RHS) {
+    return !(LHS == RHS);
+  }
+
+  friend constexpr bool operator<(SmallOptional LHS, SmallOptional RHS) {
+    return LHS != RHS && (!LHS || (RHS && *LHS < *RHS));
+  }
+  friend constexpr bool operator<=(SmallOptional LHS, SmallOptional RHS) {
+    return LHS == RHS || LHS < RHS;
+  }
+  friend constexpr bool operator>=(SmallOptional LHS, SmallOptional RHS) {
+    return !(LHS < RHS);
+  }
+  friend constexpr bool operator>(SmallOptional LHS, SmallOptional RHS) {
+    return !(LHS <= RHS);
+  }
+
+private:
+  constexpr SmallOptional(std::nullopt_t, underlying_type Rep) : Rep(Rep) {};
+
+  underlying_type Rep;
+};
+
+using UnsignedOrNone = SmallOptional<unsigned>;
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_UNSIGNED_OR_NONE_H
diff --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index 118c3b75aed95..cc7175a47f9da 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_BASIC_SPECIFIERS_H
 #define LLVM_CLANG_BASIC_SPECIFIERS_H
 
+#include "clang/Basic/SmallOptional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -361,6 +362,8 @@ namespace clang {
     // parameters are assumed to only get null on error.
     NullableResult,
   };
+  using NullabilityKindOrNone = SmallOptional<NullabilityKind>;
+
   /// Prints human-readable debug representation.
   llvm::raw_ostream &operator<<(llvm::raw_ostream&, NullabilityKind);
 
diff --git a/clang/include/clang/Basic/UnsignedOrNone.h 
b/clang/include/clang/Basic/UnsignedOrNone.h
deleted file mode 100644
index 659fd8c6487d2..0000000000000
--- a/clang/include/clang/Basic/UnsignedOrNone.h
+++ /dev/null
@@ -1,53 +0,0 @@
-//===- UnsignedOrNone.h - simple optional index-----*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-/// \file
-/// Defines clang::UnsignedOrNone.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_BASIC_UNSIGNED_OR_NONE_H
-#define LLVM_CLANG_BASIC_UNSIGNED_OR_NONE_H
-
-#include <cassert>
-#include <optional>
-
-namespace clang {
-
-struct UnsignedOrNone {
-  constexpr UnsignedOrNone(std::nullopt_t) : Rep(0) {}
-  UnsignedOrNone(unsigned Val) : Rep(Val + 1) { assert(operator bool()); }
-  UnsignedOrNone(int) = delete;
-
-  constexpr static UnsignedOrNone fromInternalRepresentation(unsigned Rep) {
-    return {std::nullopt, Rep};
-  }
-  constexpr unsigned toInternalRepresentation() const { return Rep; }
-
-  explicit constexpr operator bool() const { return Rep != 0; }
-  unsigned operator*() const {
-    assert(operator bool());
-    return Rep - 1;
-  }
-
-  friend constexpr bool operator==(UnsignedOrNone LHS, UnsignedOrNone RHS) {
-    return LHS.Rep == RHS.Rep;
-  }
-  friend constexpr bool operator!=(UnsignedOrNone LHS, UnsignedOrNone RHS) {
-    return LHS.Rep != RHS.Rep;
-  }
-
-private:
-  constexpr UnsignedOrNone(std::nullopt_t, unsigned Rep) : Rep(Rep) {};
-
-  unsigned Rep;
-};
-
-} // namespace clang
-
-#endif // LLVM_CLANG_BASIC_UNSIGNED_OR_NONE_H
diff --git a/clang/lib/APINotes/APINotesTypes.cpp 
b/clang/lib/APINotes/APINotesTypes.cpp
index 78b3b5a237e38..8a368bc468685 100644
--- a/clang/lib/APINotes/APINotesTypes.cpp
+++ b/clang/lib/APINotes/APINotesTypes.cpp
@@ -49,8 +49,8 @@ LLVM_DUMP_METHOD void CommonTypeInfo::dump(llvm::raw_ostream 
&OS) const {
 
 LLVM_DUMP_METHOD void ContextInfo::dump(llvm::raw_ostream &OS) {
   static_cast<CommonTypeInfo &>(*this).dump(OS);
-  if (HasDefaultNullability)
-    OS << "DefaultNullability: " << DefaultNullability << ' ';
+  if (NullabilityKindOrNone K = getDefaultNullability())
+    OS << "DefaultNullability: " << *K << ' ';
   if (HasDesignatedInits)
     OS << "[HasDesignatedInits] ";
   if (SwiftImportAsNonGenericSpecified)
@@ -62,8 +62,8 @@ LLVM_DUMP_METHOD void ContextInfo::dump(llvm::raw_ostream 
&OS) {
 
 LLVM_DUMP_METHOD void VariableInfo::dump(llvm::raw_ostream &OS) const {
   static_cast<const CommonEntityInfo &>(*this).dump(OS);
-  if (NullabilityAudited)
-    OS << "Audited Nullability: " << Nullable << ' ';
+  if (NullabilityKindOrNone K = getNullability())
+    OS << "Audited Nullability: " << *K << ' ';
   if (!Type.empty())
     OS << "C Type: " << Type << ' ';
   OS << '\n';
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 78983fd38410d..1cc318697d936 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -5097,7 +5097,7 @@ LinkageInfo Type::getLinkageAndVisibility() const {
   return LinkageComputer{}.getTypeLinkageAndVisibility(this);
 }
 
-std::optional<NullabilityKind> Type::getNullability() const {
+NullabilityKindOrNone Type::getNullability() const {
   QualType Type(this, 0);
   while (const auto *AT = Type->getAs<AttributedType>()) {
     // Check whether this is an attributed type with nullability
@@ -5263,7 +5263,7 @@ bool Type::canHaveNullability(bool ResultIfUnknown) const 
{
   llvm_unreachable("bad type kind!");
 }
 
-std::optional<NullabilityKind> AttributedType::getImmediateNullability() const 
{
+NullabilityKindOrNone AttributedType::getImmediateNullability() const {
   if (getAttrKind() == attr::TypeNonNull)
     return NullabilityKind::NonNull;
   if (getAttrKind() == attr::TypeNullable)
@@ -5275,8 +5275,7 @@ std::optional<NullabilityKind> 
AttributedType::getImmediateNullability() const {
   return std::nullopt;
 }
 
-std::optional<NullabilityKind>
-AttributedType::stripOuterNullability(QualType &T) {
+NullabilityKindOrNone AttributedType::stripOuterNullability(QualType &T) {
   QualType AttrTy = T;
   if (auto MacroTy = dyn_cast<MacroQualifiedType>(T))
     AttrTy = MacroTy->getUnderlyingType();
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index ef45d5842c795..8a68f2f19bf3d 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -686,12 +686,12 @@ void Sema::PrintStats() const {
 void Sema::diagnoseNullableToNonnullConversion(QualType DstType,
                                                QualType SrcType,
                                                SourceLocation Loc) {
-  std::optional<NullabilityKind> ExprNullability = SrcType->getNullability();
+  NullabilityKindOrNone ExprNullability = SrcType->getNullability();
   if (!ExprNullability || (*ExprNullability != NullabilityKind::Nullable &&
                            *ExprNullability != 
NullabilityKind::NullableResult))
     return;
 
-  std::optional<NullabilityKind> TypeNullability = DstType->getNullability();
+  NullabilityKindOrNone TypeNullability = DstType->getNullability();
   if (!TypeNullability || *TypeNullability != NullabilityKind::NonNull)
     return;
 
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 53ff818a2af53..74fe79f59f826 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -4557,7 +4557,7 @@ static QualType mergeTypeNullabilityForRedecl(Sema &S, 
SourceLocation loc,
   auto prevNullability = prevType->getNullability();
 
   // Easy case: both have nullability.
-  if (nullability.has_value() == prevNullability.has_value()) {
+  if (bool(nullability) == bool(prevNullability)) {
     // Neither has nullability; continue.
     if (!nullability)
       return type;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9fd8c6a0a5451..cf235095d489d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9152,7 +9152,7 @@ static QualType computeConditionalNullability(QualType 
ResTy, bool IsBin,
     return ResTy;
 
   auto GetNullability = [](QualType Ty) {
-    std::optional<NullabilityKind> Kind = Ty->getNullability();
+    NullabilityKindOrNone Kind = Ty->getNullability();
     if (Kind) {
       // For our purposes, treat _Nullable_result as _Nullable.
       if (*Kind == NullabilityKind::NullableResult)
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 36be822c817d2..bc191359db839 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -669,7 +669,7 @@ ExprResult SemaObjC::BuildObjCBoxedExpr(SourceRange SR, 
Expr *ValueExpr) {
       BoxingMethod = StringWithUTF8StringMethod;
       BoxedType = NSStringPointer;
       // Transfer the nullability from method's return type.
-      std::optional<NullabilityKind> Nullability =
+      NullabilityKindOrNone Nullability =
           BoxingMethod->getReturnType()->getNullability();
       if (Nullability)
         BoxedType =
@@ -1704,16 +1704,14 @@ QualType SemaObjC::getMessageSendResultType(const Expr 
*Receiver,
 
   // Map the nullability of the result into a table index.
   unsigned receiverNullabilityIdx = 0;
-  if (std::optional<NullabilityKind> nullability =
-          ReceiverType->getNullability()) {
+  if (NullabilityKindOrNone nullability = ReceiverType->getNullability()) {
     if (*nullability == NullabilityKind::NullableResult)
       nullability = Null...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/191828
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to