[clang] 9cf4419 - [clang] Use std::optional instead of llvm::Optional (NFC)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 2 15:55:04 PST 2023


Author: Kazu Hirata
Date: 2023-01-02T15:54:57-08:00
New Revision: 9cf4419e2451febf09acdf28c7d52ebf436d3a7e

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

LOG: [clang] Use std::optional instead of llvm::Optional (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 
    

Modified: 
    clang/include/clang/APINotes/Types.h
    clang/include/clang/Basic/CLWarnings.h
    clang/include/clang/Basic/CustomizableOptional.h
    clang/include/clang/Basic/TargetID.h
    clang/include/clang/Support/RISCVVIntrinsicUtils.h
    clang/lib/Basic/CLWarnings.cpp
    clang/lib/Basic/TargetID.cpp
    clang/lib/DirectoryWatcher/DirectoryScanner.cpp
    clang/lib/DirectoryWatcher/DirectoryScanner.h
    clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
    clang/lib/Support/RISCVVIntrinsicUtils.cpp
    clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
    clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
    clang/unittests/libclang/LibclangTest.cpp
    clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
    clang/utils/TableGen/NeonEmitter.cpp
    clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/APINotes/Types.h b/clang/include/clang/APINotes/Types.h
index 8dfc3bf4f1e58..af5f05bc0d365 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -10,9 +10,9 @@
 #define LLVM_CLANG_APINOTES_TYPES_H
 
 #include "clang/Basic/Specifiers.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include <climits>
+#include <optional>
 #include <vector>
 
 namespace llvm {
@@ -74,12 +74,12 @@ class CommonEntityInfo {
       : Unavailable(0), UnavailableInSwift(0), SwiftPrivateSpecified(0),
         SwiftPrivate(0) {}
 
-  llvm::Optional<bool> isSwiftPrivate() const {
-    return SwiftPrivateSpecified ? llvm::Optional<bool>(SwiftPrivate)
+  std::optional<bool> isSwiftPrivate() const {
+    return SwiftPrivateSpecified ? std::optional<bool>(SwiftPrivate)
                                  : std::nullopt;
   }
 
-  void setSwiftPrivate(llvm::Optional<bool> Private) {
+  void setSwiftPrivate(std::optional<bool> Private) {
     SwiftPrivateSpecified = Private.has_value();
     SwiftPrivate = Private.value_or(0);
   }
@@ -131,38 +131,38 @@ class CommonTypeInfo : public CommonEntityInfo {
   /// The Swift type to which a given type is bridged.
   ///
   /// Reflects the swift_bridge attribute.
-  llvm::Optional<std::string> SwiftBridge;
+  std::optional<std::string> SwiftBridge;
 
   /// The NS error domain for this type.
-  llvm::Optional<std::string> NSErrorDomain;
+  std::optional<std::string> NSErrorDomain;
 
 public:
   CommonTypeInfo() {}
 
-  const llvm::Optional<std::string> &getSwiftBridge() const {
+  const std::optional<std::string> &getSwiftBridge() const {
     return SwiftBridge;
   }
 
-  void setSwiftBridge(const llvm::Optional<std::string> &SwiftType) {
+  void setSwiftBridge(const std::optional<std::string> &SwiftType) {
     SwiftBridge = SwiftType;
   }
 
-  void setSwiftBridge(const llvm::Optional<llvm::StringRef> &SwiftType) {
+  void setSwiftBridge(const std::optional<llvm::StringRef> &SwiftType) {
     SwiftBridge = SwiftType
-                      ? llvm::Optional<std::string>(std::string(*SwiftType))
+                      ? std::optional<std::string>(std::string(*SwiftType))
                       : std::nullopt;
   }
 
-  const llvm::Optional<std::string> &getNSErrorDomain() const {
+  const std::optional<std::string> &getNSErrorDomain() const {
     return NSErrorDomain;
   }
 
-  void setNSErrorDomain(const llvm::Optional<std::string> &Domain) {
+  void setNSErrorDomain(const std::optional<std::string> &Domain) {
     NSErrorDomain = Domain;
   }
 
-  void setNSErrorDomain(const llvm::Optional<llvm::StringRef> &Domain) {
-    NSErrorDomain = Domain ? llvm::Optional<std::string>(std::string(*Domain))
+  void setNSErrorDomain(const std::optional<llvm::StringRef> &Domain) {
+    NSErrorDomain = Domain ? std::optional<std::string>(std::string(*Domain))
                            : std::nullopt;
   }
 
@@ -221,9 +221,9 @@ class ObjCContextInfo : public CommonTypeInfo {
   ///
   /// Returns the default nullability, if implied, or std::nullopt if there is
   /// none.
-  llvm::Optional<NullabilityKind> getDefaultNullability() const {
+  std::optional<NullabilityKind> getDefaultNullability() const {
     return HasDefaultNullability
-               ? llvm::Optional<NullabilityKind>(
+               ? std::optional<NullabilityKind>(
                      static_cast<NullabilityKind>(DefaultNullability))
                : std::nullopt;
   }
@@ -237,21 +237,21 @@ class ObjCContextInfo : public CommonTypeInfo {
   bool hasDesignatedInits() const { return HasDesignatedInits; }
   void setHasDesignatedInits(bool Value) { HasDesignatedInits = Value; }
 
-  llvm::Optional<bool> getSwiftImportAsNonGeneric() const {
+  std::optional<bool> getSwiftImportAsNonGeneric() const {
     return SwiftImportAsNonGenericSpecified
-               ? llvm::Optional<bool>(SwiftImportAsNonGeneric)
+               ? std::optional<bool>(SwiftImportAsNonGeneric)
                : std::nullopt;
   }
-  void setSwiftImportAsNonGeneric(llvm::Optional<bool> Value) {
+  void setSwiftImportAsNonGeneric(std::optional<bool> Value) {
     SwiftImportAsNonGenericSpecified = Value.has_value();
     SwiftImportAsNonGeneric = Value.value_or(false);
   }
 
-  llvm::Optional<bool> getSwiftObjCMembers() const {
-    return SwiftObjCMembersSpecified ? llvm::Optional<bool>(SwiftObjCMembers)
+  std::optional<bool> getSwiftObjCMembers() const {
+    return SwiftObjCMembersSpecified ? std::optional<bool>(SwiftObjCMembers)
                                      : std::nullopt;
   }
-  void setSwiftObjCMembers(llvm::Optional<bool> Value) {
+  void setSwiftObjCMembers(std::optional<bool> Value) {
     SwiftObjCMembersSpecified = Value.has_value();
     SwiftObjCMembers = Value.value_or(false);
   }
@@ -315,8 +315,8 @@ class VariableInfo : public CommonEntityInfo {
 public:
   VariableInfo() : NullabilityAudited(false), Nullable(0) {}
 
-  llvm::Optional<NullabilityKind> getNullability() const {
-    return NullabilityAudited ? llvm::Optional<NullabilityKind>(
+  std::optional<NullabilityKind> getNullability() const {
+    return NullabilityAudited ? std::optional<NullabilityKind>(
                                     static_cast<NullabilityKind>(Nullable))
                               : std::nullopt;
   }
@@ -364,12 +364,12 @@ class ObjCPropertyInfo : public VariableInfo {
   ObjCPropertyInfo()
       : SwiftImportAsAccessorsSpecified(false), SwiftImportAsAccessors(false) {}
 
-  llvm::Optional<bool> getSwiftImportAsAccessors() const {
+  std::optional<bool> getSwiftImportAsAccessors() const {
     return SwiftImportAsAccessorsSpecified
-               ? llvm::Optional<bool>(SwiftImportAsAccessors)
+               ? std::optional<bool>(SwiftImportAsAccessors)
                : std::nullopt;
   }
-  void setSwiftImportAsAccessors(llvm::Optional<bool> Value) {
+  void setSwiftImportAsAccessors(std::optional<bool> Value) {
     SwiftImportAsAccessorsSpecified = Value.has_value();
     SwiftImportAsAccessors = Value.value_or(false);
   }
@@ -428,23 +428,23 @@ class ParamInfo : public VariableInfo {
   ParamInfo()
       : NoEscapeSpecified(false), NoEscape(false), RawRetainCountConvention() {}
 
-  llvm::Optional<bool> isNoEscape() const {
+  std::optional<bool> isNoEscape() const {
     if (!NoEscapeSpecified)
       return std::nullopt;
     return NoEscape;
   }
-  void setNoEscape(llvm::Optional<bool> Value) {
+  void setNoEscape(std::optional<bool> Value) {
     NoEscapeSpecified = Value.has_value();
     NoEscape = Value.value_or(false);
   }
 
-  llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
+  std::optional<RetainCountConventionKind> getRetainCountConvention() const {
     if (!RawRetainCountConvention)
       return std::nullopt;
     return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
   }
   void
-  setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
+  setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
     RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
     assert(getRetainCountConvention() == Value && "bitfield too small");
   }
@@ -556,13 +556,13 @@ class FunctionInfo : public CommonEntityInfo {
 
   NullabilityKind getReturnTypeInfo() const { return getTypeInfo(0); }
 
-  llvm::Optional<RetainCountConventionKind> getRetainCountConvention() const {
+  std::optional<RetainCountConventionKind> getRetainCountConvention() const {
     if (!RawRetainCountConvention)
       return std::nullopt;
     return static_cast<RetainCountConventionKind>(RawRetainCountConvention - 1);
   }
   void
-  setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
+  setRetainCountConvention(std::optional<RetainCountConventionKind> Value) {
     RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
     assert(getRetainCountConvention() == Value && "bitfield too small");
   }
@@ -659,16 +659,16 @@ class TagInfo : public CommonTypeInfo {
   unsigned IsFlagEnum : 1;
 
 public:
-  llvm::Optional<EnumExtensibilityKind> EnumExtensibility;
+  std::optional<EnumExtensibilityKind> EnumExtensibility;
 
   TagInfo() : HasFlagEnum(0), IsFlagEnum(0) {}
 
-  llvm::Optional<bool> isFlagEnum() const {
+  std::optional<bool> isFlagEnum() const {
     if (HasFlagEnum)
       return IsFlagEnum;
     return std::nullopt;
   }
-  void setFlagEnum(llvm::Optional<bool> Value) {
+  void setFlagEnum(std::optional<bool> Value) {
     HasFlagEnum = Value.has_value();
     IsFlagEnum = Value.value_or(false);
   }
@@ -703,7 +703,7 @@ inline bool operator!=(const TagInfo &LHS, const TagInfo &RHS) {
 /// Describes API notes data for a typedef.
 class TypedefInfo : public CommonTypeInfo {
 public:
-  llvm::Optional<SwiftNewTypeKind> SwiftWrapper;
+  std::optional<SwiftNewTypeKind> SwiftWrapper;
 
   TypedefInfo() {}
 

diff  --git a/clang/include/clang/Basic/CLWarnings.h b/clang/include/clang/Basic/CLWarnings.h
index e3351f430c437..9b8be93bad3a6 100644
--- a/clang/include/clang/Basic/CLWarnings.h
+++ b/clang/include/clang/Basic/CLWarnings.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_CLANG_BASIC_CLWARNINGS_H
 #define LLVM_CLANG_BASIC_CLWARNINGS_H
 
-#include "llvm/ADT/Optional.h"
+#include <optional>
 
 namespace clang {
 
@@ -19,7 +19,7 @@ enum class Group;
 
 /// For cl.exe warning IDs that cleany map to clang diagnostic groups,
 /// returns the corresponding group. Else, returns an empty Optional.
-llvm::Optional<diag::Group> diagGroupFromCLWarningID(unsigned);
+std::optional<diag::Group> diagGroupFromCLWarningID(unsigned);
 
 } // end namespace clang
 

diff  --git a/clang/include/clang/Basic/CustomizableOptional.h b/clang/include/clang/Basic/CustomizableOptional.h
index 52e761d449330..7323a818b0b51 100644
--- a/clang/include/clang/Basic/CustomizableOptional.h
+++ b/clang/include/clang/Basic/CustomizableOptional.h
@@ -10,11 +10,11 @@
 #define CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H
 
 #include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include <cassert>
 #include <new>
+#include <optional>
 #include <utility>
 
 namespace clang {
@@ -46,9 +46,9 @@ template <typename T> class CustomizableOptional {
       : Storage(std::in_place, std::forward<ArgTypes>(Args)...) {}
 
   // Allow conversion from Optional<T>.
-  constexpr CustomizableOptional(const llvm::Optional<T> &y)
+  constexpr CustomizableOptional(const std::optional<T> &y)
       : CustomizableOptional(y ? *y : CustomizableOptional()) {}
-  constexpr CustomizableOptional(llvm::Optional<T> &&y)
+  constexpr CustomizableOptional(std::optional<T> &&y)
       : CustomizableOptional(y ? std::move(*y) : CustomizableOptional()) {}
 
   CustomizableOptional &operator=(T &&y) {
@@ -99,11 +99,11 @@ template <typename T> class CustomizableOptional {
   }
 
   // Allow conversion to Optional<T>.
-  explicit operator llvm::Optional<T> &() const & {
-    return *this ? **this : llvm::Optional<T>();
+  explicit operator std::optional<T> &() const & {
+    return *this ? **this : std::optional<T>();
   }
-  explicit operator llvm::Optional<T> &&() const && {
-    return *this ? std::move(**this) : llvm::Optional<T>();
+  explicit operator std::optional<T> &&() const && {
+    return *this ? std::move(**this) : std::optional<T>();
   }
 };
 

diff  --git a/clang/include/clang/Basic/TargetID.h b/clang/include/clang/Basic/TargetID.h
index d7c05b2d0c49e..f1922942804eb 100644
--- a/clang/include/clang/Basic/TargetID.h
+++ b/clang/include/clang/Basic/TargetID.h
@@ -12,6 +12,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/Triple.h"
+#include <optional>
 #include <set>
 
 namespace clang {
@@ -37,9 +38,9 @@ llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T,
 /// If the target ID contains feature+, map it to true.
 /// If the target ID contains feature-, map it to false.
 /// If the target ID does not contain a feature (default), do not map it.
-llvm::Optional<llvm::StringRef>
-parseTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch,
-              llvm::StringMap<bool> *FeatureMap);
+std::optional<llvm::StringRef> parseTargetID(const llvm::Triple &T,
+                                             llvm::StringRef OffloadArch,
+                                             llvm::StringMap<bool> *FeatureMap);
 
 /// Returns canonical target ID, assuming \p Processor is canonical and all
 /// entries in \p Features are valid.

diff  --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index b5ce83a2654de..0d5ebf058e604 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -11,10 +11,10 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitmaskEnum.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include <cstdint>
+#include <optional>
 #include <set>
 #include <string>
 #include <unordered_map>
@@ -27,7 +27,7 @@ class raw_ostream;
 namespace clang {
 namespace RISCV {
 
-using VScaleVal = llvm::Optional<unsigned>;
+using VScaleVal = std::optional<unsigned>;
 
 // Modifier for vector type.
 enum class VectorTypeModifier : uint8_t {
@@ -197,7 +197,7 @@ struct PrototypeDescriptor {
   static const PrototypeDescriptor Mask;
   static const PrototypeDescriptor Vector;
   static const PrototypeDescriptor VL;
-  static llvm::Optional<PrototypeDescriptor>
+  static std::optional<PrototypeDescriptor>
   parsePrototypeDescriptor(llvm::StringRef PrototypeStr);
 };
 
@@ -238,7 +238,7 @@ struct LMULType {
   LMULType(int Log2LMUL);
   // Return the C/C++ string representation of LMUL
   std::string str() const;
-  llvm::Optional<unsigned> getScale(unsigned ElementBitwidth) const;
+  std::optional<unsigned> getScale(unsigned ElementBitwidth) const;
   void MulLog2LMUL(int Log2LMUL);
 };
 
@@ -354,11 +354,11 @@ class RVVTypeCache {
   /// and LMUL with type transformers). It also record result of type in legal
   /// or illegal set to avoid compute the same config again. The result maybe
   /// have illegal RVVType.
-  llvm::Optional<RVVTypes>
+  std::optional<RVVTypes>
   computeTypes(BasicType BT, int Log2LMUL, unsigned NF,
                llvm::ArrayRef<PrototypeDescriptor> Prototype);
-  llvm::Optional<RVVTypePtr> computeType(BasicType BT, int Log2LMUL,
-                                         PrototypeDescriptor Proto);
+  std::optional<RVVTypePtr> computeType(BasicType BT, int Log2LMUL,
+                                        PrototypeDescriptor Proto);
 };
 
 enum PolicyScheme : uint8_t {

diff  --git a/clang/lib/Basic/CLWarnings.cpp b/clang/lib/Basic/CLWarnings.cpp
index 0cf367d9f7f62..5449d8f59fcf4 100644
--- a/clang/lib/Basic/CLWarnings.cpp
+++ b/clang/lib/Basic/CLWarnings.cpp
@@ -12,10 +12,11 @@
 
 #include "clang/Basic/CLWarnings.h"
 #include "clang/Basic/DiagnosticCategories.h"
+#include <optional>
 
 using namespace clang;
 
-llvm::Optional<diag::Group>
+std::optional<diag::Group>
 clang::diagGroupFromCLWarningID(unsigned CLWarningID) {
   switch (CLWarningID) {
   case 4005: return diag::Group::MacroRedefined;

diff  --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index 20e07cb7266a7..7cc4d67e3a522 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -101,7 +101,7 @@ parseTargetIDWithFormatCheckingOnly(llvm::StringRef TargetID,
   return Processor;
 }
 
-llvm::Optional<llvm::StringRef>
+std::optional<llvm::StringRef>
 parseTargetID(const llvm::Triple &T, llvm::StringRef TargetID,
               llvm::StringMap<bool> *FeatureMap) {
   auto OptionalProcessor =

diff  --git a/clang/lib/DirectoryWatcher/DirectoryScanner.cpp b/clang/lib/DirectoryWatcher/DirectoryScanner.cpp
index fa060af9c7ae5..428f87eddc7b6 100644
--- a/clang/lib/DirectoryWatcher/DirectoryScanner.cpp
+++ b/clang/lib/DirectoryWatcher/DirectoryScanner.cpp
@@ -9,12 +9,13 @@
 #include "DirectoryScanner.h"
 
 #include "llvm/Support/Path.h"
+#include <optional>
 
 namespace clang {
 
 using namespace llvm;
 
-Optional<sys::fs::file_status> getFileStatus(StringRef Path) {
+std::optional<sys::fs::file_status> getFileStatus(StringRef Path) {
   sys::fs::file_status Status;
   std::error_code EC = status(Path, Status);
   if (EC)

diff  --git a/clang/lib/DirectoryWatcher/DirectoryScanner.h b/clang/lib/DirectoryWatcher/DirectoryScanner.h
index 42fe8efcc8fec..84cffa5704f76 100644
--- a/clang/lib/DirectoryWatcher/DirectoryScanner.h
+++ b/clang/lib/DirectoryWatcher/DirectoryScanner.h
@@ -8,6 +8,7 @@
 
 #include "clang/DirectoryWatcher/DirectoryWatcher.h"
 #include "llvm/Support/FileSystem.h"
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -24,6 +25,6 @@ getAsFileEvents(const std::vector<std::string> &Scan);
 
 /// Gets status of file (or directory) at \p Path.
 /// \returns std::nullopt if \p Path doesn't exist or can't get the status.
-llvm::Optional<llvm::sys::fs::file_status> getFileStatus(llvm::StringRef Path);
+std::optional<llvm::sys::fs::file_status> getFileStatus(llvm::StringRef Path);
 
 } // namespace clang

diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 5815742d57ac7..91e3ccf2ec304 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_ANALYZER_WEBKIT_PTRTYPESEMANTICS_H
 
 #include "llvm/ADT/APInt.h"
-#include "llvm/ADT/Optional.h"
+#include <optional>
 
 namespace clang {
 class CXXBaseSpecifier;
@@ -28,30 +28,30 @@ class Type;
 
 /// \returns CXXRecordDecl of the base if the type is ref-countable, nullptr if
 /// not, std::nullopt if inconclusive.
-llvm::Optional<const clang::CXXRecordDecl *>
-isRefCountable(const clang::CXXBaseSpecifier *Base);
+std::optional<const clang::CXXRecordDecl*>
+isRefCountable(const clang::CXXBaseSpecifier* Base);
 
 /// \returns true if \p Class is ref-countable, false if not, std::nullopt if
 /// inconclusive.
-llvm::Optional<bool> isRefCountable(const clang::CXXRecordDecl *Class);
+std::optional<bool> isRefCountable(const clang::CXXRecordDecl* Class);
 
 /// \returns true if \p Class is ref-counted, false if not.
 bool isRefCounted(const clang::CXXRecordDecl *Class);
 
 /// \returns true if \p Class is ref-countable AND not ref-counted, false if
 /// not, std::nullopt if inconclusive.
-llvm::Optional<bool> isUncounted(const clang::CXXRecordDecl *Class);
+std::optional<bool> isUncounted(const clang::CXXRecordDecl* Class);
 
 /// \returns true if \p T is either a raw pointer or reference to an uncounted
 /// class, false if not, std::nullopt if inconclusive.
-llvm::Optional<bool> isUncountedPtr(const clang::Type *T);
+std::optional<bool> isUncountedPtr(const clang::Type* T);
 
 /// \returns true if \p F creates ref-countable object from uncounted parameter,
 /// false if not.
 bool isCtorOfRefCounted(const clang::FunctionDecl *F);
 
 /// \returns true if \p M is getter of a ref-counted class, false if not.
-llvm::Optional<bool> isGetterOfRefCounted(const clang::CXXMethodDecl *Method);
+std::optional<bool> isGetterOfRefCounted(const clang::CXXMethodDecl* Method);
 
 /// \returns true if \p F is a conversion between ref-countable or ref-counted
 /// pointer types.

diff  --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index c1c4a30576adc..9a550806f69d8 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -8,7 +8,6 @@
 
 #include "clang/Support/RISCVVIntrinsicUtils.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -16,6 +15,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 #include <numeric>
+#include <optional>
 
 using namespace llvm;
 
@@ -362,7 +362,8 @@ void RVVType::applyBasicType() {
   assert(ElementBitwidth != 0 && "Bad element bitwidth!");
 }
 
-Optional<PrototypeDescriptor> PrototypeDescriptor::parsePrototypeDescriptor(
+std::optional<PrototypeDescriptor>
+PrototypeDescriptor::parsePrototypeDescriptor(
     llvm::StringRef PrototypeDescriptorStr) {
   PrototypeDescriptor PD;
   BaseTypeModifier PT = BaseTypeModifier::Invalid;
@@ -783,7 +784,7 @@ void RVVType::applyFixedLog2LMUL(int Log2LMUL, enum FixedLMULType Type) {
   Scale = LMUL.getScale(ElementBitwidth);
 }
 
-Optional<RVVTypes>
+std::optional<RVVTypes>
 RVVTypeCache::computeTypes(BasicType BT, int Log2LMUL, unsigned NF,
                            ArrayRef<PrototypeDescriptor> Prototype) {
   // LMUL x NF must be less than or equal to 8.
@@ -814,8 +815,8 @@ static uint64_t computeRVVTypeHashValue(BasicType BT, int Log2LMUL,
          ((uint64_t)(Proto.VTM & 0xff) << 32);
 }
 
-Optional<RVVTypePtr> RVVTypeCache::computeType(BasicType BT, int Log2LMUL,
-                                               PrototypeDescriptor Proto) {
+std::optional<RVVTypePtr> RVVTypeCache::computeType(BasicType BT, int Log2LMUL,
+                                                    PrototypeDescriptor Proto) {
   uint64_t Idx = computeRVVTypeHashValue(BT, Log2LMUL, Proto);
   // Search first
   auto It = LegalTypes.find(Idx);

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 2e60519691f04..ad942efb352e8 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -53,6 +53,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include <atomic>
+#include <optional>
 
 using namespace llvm;
 using namespace llvm::opt;
@@ -1231,8 +1232,8 @@ linkAndWrapDeviceFiles(SmallVectorImpl<OffloadFile> &LinkerInputFiles,
   return WrappedOutput;
 }
 
-Optional<std::string> findFile(StringRef Dir, StringRef Root,
-                               const Twine &Name) {
+std::optional<std::string> findFile(StringRef Dir, StringRef Root,
+                                    const Twine &Name) {
   SmallString<128> Path;
   if (Dir.startswith("="))
     sys::path::append(Path, Root, Dir.substr(1), Name);
@@ -1244,20 +1245,24 @@ Optional<std::string> findFile(StringRef Dir, StringRef Root,
   return std::nullopt;
 }
 
-Optional<std::string> findFromSearchPaths(StringRef Name, StringRef Root,
-                                          ArrayRef<StringRef> SearchPaths) {
+std::optional<std::string>
+findFromSearchPaths(StringRef Name, StringRef Root,
+                    ArrayRef<StringRef> SearchPaths) {
   for (StringRef Dir : SearchPaths)
-    if (Optional<std::string> File = findFile(Dir, Root, Name))
+    if (std::optional<std::string> File = findFile(Dir, Root, Name))
       return File;
   return std::nullopt;
 }
 
-Optional<std::string> searchLibraryBaseName(StringRef Name, StringRef Root,
-                                            ArrayRef<StringRef> SearchPaths) {
+std::optional<std::string>
+searchLibraryBaseName(StringRef Name, StringRef Root,
+                      ArrayRef<StringRef> SearchPaths) {
   for (StringRef Dir : SearchPaths) {
-    if (Optional<std::string> File = findFile(Dir, Root, "lib" + Name + ".so"))
+    if (std::optional<std::string> File =
+            findFile(Dir, Root, "lib" + Name + ".so"))
       return File;
-    if (Optional<std::string> File = findFile(Dir, Root, "lib" + Name + ".a"))
+    if (std::optional<std::string> File =
+            findFile(Dir, Root, "lib" + Name + ".a"))
       return File;
   }
   return std::nullopt;
@@ -1265,8 +1270,8 @@ Optional<std::string> searchLibraryBaseName(StringRef Name, StringRef Root,
 
 /// Search for static libraries in the linker's library path given input like
 /// `-lfoo` or `-l:libfoo.a`.
-Optional<std::string> searchLibrary(StringRef Input, StringRef Root,
-                                    ArrayRef<StringRef> SearchPaths) {
+std::optional<std::string> searchLibrary(StringRef Input, StringRef Root,
+                                         ArrayRef<StringRef> SearchPaths) {
   if (Input.startswith(":"))
     return findFromSearchPaths(Input.drop_front(), Root, SearchPaths);
   return searchLibraryBaseName(Input, Root, SearchPaths);

diff  --git a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
index 53361a1184f5d..4ad6f8025674b 100644
--- a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -15,6 +15,7 @@
 #include <condition_variable>
 #include <future>
 #include <mutex>
+#include <optional>
 #include <thread>
 
 using namespace llvm;
@@ -177,7 +178,7 @@ struct VerifyingConsumer {
   }
 
   // Not locking - caller has to lock Mtx.
-  llvm::Optional<bool> result() const {
+  std::optional<bool> result() const {
     if (ExpectedInitial.empty() && ExpectedNonInitial.empty() &&
         UnexpectedInitial.empty() && UnexpectedNonInitial.empty())
       return true;

diff  --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index 0845476f31dea..809426a01ca7a 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -19,6 +19,7 @@
 #include <functional>
 #include <map>
 #include <memory>
+#include <optional>
 #include <set>
 #define DEBUG_TYPE "libclang-test"
 
@@ -934,7 +935,7 @@ void Class1::fun() {}
   ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
                                        nullptr, 0, TUFlags);
 
-  llvm::Optional<CXCursor> typeRefCsr;
+  std::optional<CXCursor> typeRefCsr;
   Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
     if (cursor.kind == CXCursor_TypeRef) {
       typeRefCsr.emplace(cursor);

diff  --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index ec682edb57f63..0b553254682ca 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -12,7 +12,6 @@
 
 #include "TableGenBackends.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -30,6 +29,7 @@
 #include <cctype>
 #include <functional>
 #include <map>
+#include <optional>
 #include <set>
 using namespace llvm;
 
@@ -250,8 +250,9 @@ typedef llvm::PointerUnion<RecordVec*, RecordSet*> VecOrSet;
 
 namespace {
 class InferPedantic {
-  typedef llvm::DenseMap<const Record*,
-                         std::pair<unsigned, Optional<unsigned> > > GMap;
+  typedef llvm::DenseMap<const Record *,
+                         std::pair<unsigned, std::optional<unsigned>>>
+      GMap;
 
   DiagGroupParentMap &DiagGroupParents;
   const std::vector<Record*> &Diags;
@@ -675,7 +676,7 @@ struct DiagnosticTextBuilder {
 };
 
 template <class Derived> struct DiagTextVisitor {
-  using ModifierMappingsType = Optional<std::vector<int>>;
+  using ModifierMappingsType = std::optional<std::vector<int>>;
 
 private:
   Derived &getDerived() { return static_cast<Derived &>(*this); }
@@ -706,7 +707,7 @@ template <class Derived> struct DiagTextVisitor {
 
   private:
     DiagTextVisitor &Visitor;
-    Optional<std::vector<int>> OldMappings;
+    std::optional<std::vector<int>> OldMappings;
 
   public:
     Piece *Substitution;

diff  --git a/clang/utils/TableGen/NeonEmitter.cpp b/clang/utils/TableGen/NeonEmitter.cpp
index 98e195d0a63a2..8f46b08b1366f 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -26,7 +26,6 @@
 #include "TableGenBackends.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
@@ -44,6 +43,7 @@
 #include <cstdint>
 #include <deque>
 #include <map>
+#include <optional>
 #include <set>
 #include <sstream>
 #include <string>
@@ -559,7 +559,7 @@ class NeonEmitter {
   /// Called by Intrinsic - this attempts to get an intrinsic that takes
   /// the given types as arguments.
   Intrinsic &getIntrinsic(StringRef Name, ArrayRef<Type> Types,
-                          Optional<std::string> MangledName);
+                          std::optional<std::string> MangledName);
 
   /// Called by Intrinsic - returns a globally-unique number.
   unsigned getUniqueNumber() { return UniqueNumber++; }
@@ -1471,7 +1471,7 @@ Intrinsic::DagEmitter::emitDagCall(DagInit *DI, bool MatchMangledName) {
     N = SI->getAsUnquotedString();
   else
     N = emitDagArg(DI->getArg(0), "").second;
-  Optional<std::string> MangledName;
+  std::optional<std::string> MangledName;
   if (MatchMangledName) {
     if (Intr.getRecord()->getValueAsBit("isLaneQ"))
       N += "q";
@@ -1895,7 +1895,7 @@ void Intrinsic::indexBody() {
 //===----------------------------------------------------------------------===//
 
 Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types,
-                                     Optional<std::string> MangledName) {
+                                     std::optional<std::string> MangledName) {
   // First, look up the name in the intrinsic map.
   assert_with_loc(IntrinsicMap.find(Name.str()) != IntrinsicMap.end(),
                   ("Intrinsic '" + Name + "' not found!").str());

diff  --git a/clang/utils/TableGen/RISCVVEmitter.cpp b/clang/utils/TableGen/RISCVVEmitter.cpp
index b69712e57f04f..d9caafeec8c42 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -25,6 +25,7 @@
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
 #include <numeric>
+#include <optional>
 
 using namespace llvm;
 using namespace clang::RISCV;
@@ -560,7 +561,7 @@ void RVVEmitter::createRVVIntrinsics(
     for (char I : TypeRange) {
       for (int Log2LMUL : Log2LMULList) {
         BasicType BT = ParseBasicType(I);
-        Optional<RVVTypes> Types =
+        std::optional<RVVTypes> Types =
             TypeCache.computeTypes(BT, Log2LMUL, NF, Prototype);
         // Ignored to create new intrinsic if there are any illegal types.
         if (!Types)
@@ -584,7 +585,7 @@ void RVVEmitter::createRVVIntrinsics(
                     BasicPrototype, /*IsMasked=*/false,
                     /*HasMaskedOffOperand=*/false, HasVL, NF,
                     IsPrototypeDefaultTU, UnMaskedPolicyScheme, P);
-            Optional<RVVTypes> PolicyTypes =
+            std::optional<RVVTypes> PolicyTypes =
                 TypeCache.computeTypes(BT, Log2LMUL, NF, PolicyPrototype);
             Out.push_back(std::make_unique<RVVIntrinsic>(
                 Name, SuffixStr, OverloadedName, OverloadedSuffixStr, IRName,
@@ -596,7 +597,7 @@ void RVVEmitter::createRVVIntrinsics(
         if (!HasMasked)
           continue;
         // Create a masked intrinsic
-        Optional<RVVTypes> MaskTypes =
+        std::optional<RVVTypes> MaskTypes =
             TypeCache.computeTypes(BT, Log2LMUL, NF, Prototype);
         Out.push_back(std::make_unique<RVVIntrinsic>(
             Name, SuffixStr, OverloadedName, OverloadedSuffixStr, MaskedIRName,
@@ -611,7 +612,7 @@ void RVVEmitter::createRVVIntrinsics(
               RVVIntrinsic::computeBuiltinTypes(
                   BasicPrototype, /*IsMasked=*/true, HasMaskedOffOperand, HasVL,
                   NF, IsPrototypeDefaultTU, MaskedPolicyScheme, P);
-          Optional<RVVTypes> PolicyTypes =
+          std::optional<RVVTypes> PolicyTypes =
               TypeCache.computeTypes(BT, Log2LMUL, NF, PolicyPrototype);
           Out.push_back(std::make_unique<RVVIntrinsic>(
               Name, SuffixStr, OverloadedName, OverloadedSuffixStr,


        


More information about the cfe-commits mailing list