Author: Matheus Izvekov
Date: 2026-04-14T10:15:45-03:00
New Revision: ae2e4768f9bdcbb2c33906708a0ab6e2a7059734

URL: 
https://github.com/llvm/llvm-project/commit/ae2e4768f9bdcbb2c33906708a0ab6e2a7059734
DIFF: 
https://github.com/llvm/llvm-project/commit/ae2e4768f9bdcbb2c33906708a0ab6e2a7059734.diff

LOG: [clang] NFC: Refactor UnsignedOrNone into OptionalUnsigned<T> with enum 
support (#191828)

This kind optional is simpler to use when it needs to be represented in
a bitfield, because it has an `unsigned` integer representation which
avoids overflows. This applies to enums as well.

This also adds a single use of this new functionality, migrating users
of `std::optional<NullabilityKind>`
This optional used to be represented as two members in a bitfield, and
this simplifies things down to one.

Added: 
    clang/include/clang/Basic/OptionalUnsigned.h

Modified: 
    clang/include/clang/APINotes/Types.h
    clang/include/clang/AST/ASTConcept.h
    clang/include/clang/AST/Decl.h
    clang/include/clang/AST/TemplateName.h
    clang/include/clang/AST/TypeBase.h
    clang/include/clang/Basic/Diagnostic.h
    clang/include/clang/Basic/Specifiers.h
    clang/lib/APINotes/APINotesTypes.cpp
    clang/lib/AST/Type.cpp
    clang/lib/Sema/Sema.cpp
    clang/lib/Sema/SemaExpr.cpp
    clang/lib/Sema/SemaExprObjC.cpp
    clang/lib/Sema/SemaType.cpp

Removed: 
    clang/include/clang/Basic/UnsignedOrNone.h


################################################################################
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..4319df35ab7e5 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/OptionalUnsigned.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/Decl.h b/clang/include/clang/AST/Decl.h
index 076d9ba935583..e45a6dae56d9b 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -29,11 +29,11 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/Basic/OperatorKinds.h"
+#include "clang/Basic/OptionalUnsigned.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/PragmaKinds.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..47cfec8f61e6f 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/OptionalUnsigned.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..826b747f2c751 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/OptionalUnsigned.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/OptionalUnsigned.h 
b/clang/include/clang/Basic/OptionalUnsigned.h
new file mode 100644
index 0000000000000..ded84857310dc
--- /dev/null
+++ b/clang/include/clang/Basic/OptionalUnsigned.h
@@ -0,0 +1,81 @@
+//===- OptionalUnsigned.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::OptionalUnsigned.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_OPTIONAL_UNSIGNED_H
+#define LLVM_CLANG_BASIC_OPTIONAL_UNSIGNED_H
+
+#include <cassert>
+#include <llvm/ADT/STLForwardCompat.h>
+#include <optional>
+
+namespace clang {
+
+template <class T> struct OptionalUnsigned {
+  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 OptionalUnsigned(std::nullopt_t) : Rep(0) {}
+  OptionalUnsigned(T Val) : Rep(static_cast<underlying_type>(Val) + 1) {
+    assert(has_value());
+  }
+  OptionalUnsigned(int) = delete;
+
+  constexpr static OptionalUnsigned
+  fromInternalRepresentation(underlying_type Rep) {
+    return {std::nullopt, Rep};
+  }
+  constexpr underlying_type toInternalRepresentation() const { return Rep; }
+
+  constexpr bool has_value() const { return Rep != 0; }
+
+  explicit constexpr operator bool() const { return has_value(); }
+  T operator*() const {
+    assert(has_value());
+    return static_cast<T>(Rep - 1);
+  }
+
+  T value_or(T Def) const { return has_value() ? operator*() : Def; }
+
+  friend constexpr bool operator==(OptionalUnsigned LHS, OptionalUnsigned RHS) 
{
+    return LHS && RHS ? *LHS == *RHS : bool(LHS) == bool(RHS);
+  }
+  friend constexpr bool operator!=(OptionalUnsigned LHS, OptionalUnsigned RHS) 
{
+    return !(LHS == RHS);
+  }
+
+  friend constexpr bool operator<(OptionalUnsigned LHS, OptionalUnsigned RHS) {
+    return LHS != RHS && (!LHS || (RHS && *LHS < *RHS));
+  }
+  friend constexpr bool operator<=(OptionalUnsigned LHS, OptionalUnsigned RHS) 
{
+    return LHS == RHS || LHS < RHS;
+  }
+  friend constexpr bool operator>=(OptionalUnsigned LHS, OptionalUnsigned RHS) 
{
+    return !(LHS < RHS);
+  }
+  friend constexpr bool operator>(OptionalUnsigned LHS, OptionalUnsigned RHS) {
+    return !(LHS <= RHS);
+  }
+
+private:
+  constexpr OptionalUnsigned(std::nullopt_t, underlying_type Rep) : Rep(Rep) 
{};
+
+  underlying_type Rep;
+};
+
+using UnsignedOrNone = OptionalUnsigned<unsigned>;
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_OPTIONAL_UNSIGNED_H

diff  --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index 118c3b75aed95..8da6fd4cf454a 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/OptionalUnsigned.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 = OptionalUnsigned<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/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 = NullabilityKind::Nullable;
     receiverNullabilityIdx = 1 + static_cast<unsigned>(*nullability);
   }
 
   unsigned resultNullabilityIdx = 0;
-  if (std::optional<NullabilityKind> nullability =
-          resultType->getNullability()) {
+  if (NullabilityKindOrNone nullability = resultType->getNullability()) {
     if (*nullability == NullabilityKind::NullableResult)
       nullability = NullabilityKind::Nullable;
     resultNullabilityIdx = 1 + static_cast<unsigned>(*nullability);

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 846474fe94adf..3dc8ceb70f3cd 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -4401,7 +4401,7 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   }
 
   // Determine whether we should infer _Nonnull on pointer types.
-  std::optional<NullabilityKind> inferNullability;
+  NullabilityKindOrNone inferNullability = std::nullopt;
   bool inferNullabilityCS = false;
   bool inferNullabilityInnerOnly = false;
   bool inferNullabilityInnerOnlyComplete = false;


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

Reply via email to