[llvm] 4dfd5a3 - [llvm] Use std::optional instead of llvm::Optional (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 20:27:48 PST 2023


Author: Kazu Hirata
Date: 2023-02-14T20:27:41-08:00
New Revision: 4dfd5a3eb6c3bc26ab19a18bfc2cbf2ec609c370

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

LOG: [llvm] 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: 
    llvm/docs/HowToSetUpLLVMStyleRTTI.rst
    llvm/include/llvm/TableGen/Record.h
    llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/HowToSetUpLLVMStyleRTTI.rst b/llvm/docs/HowToSetUpLLVMStyleRTTI.rst
index 54fe6fb10d61b..423f4d5ffc56b 100644
--- a/llvm/docs/HowToSetUpLLVMStyleRTTI.rst
+++ b/llvm/docs/HowToSetUpLLVMStyleRTTI.rst
@@ -544,7 +544,7 @@ This would enable us to cast from a ``char *`` to a SomeValue, if we wanted to.
 Optional value casting
 ----------------------
 When your types are not constructible from ``nullptr`` or there isn't a simple
-way to tell when an object is invalid, you may want to use ``llvm::Optional``.
+way to tell when an object is invalid, you may want to use ``std::optional``.
 In those cases, you probably want something like this:
 
 .. code-block:: c++
@@ -558,14 +558,14 @@ but it enables casting like so:
 .. code-block:: c++
 
   SomeValue someVal = ...;
-  Optional<AnotherValue> valOr = dyn_cast<AnotherValue>(someVal);
+  std::optional<AnotherValue> valOr = dyn_cast<AnotherValue>(someVal);
 
 With the ``_if_present`` variants, you can even do optional chaining like this:
 
 .. code-block:: c++
 
-  Optional<SomeValue> someVal = ...;
-  Optional<AnotherValue> valOr = dyn_cast_if_present<AnotherValue>(someVal);
+  std::optional<SomeValue> someVal = ...;
+  std::optional<AnotherValue> valOr = dyn_cast_if_present<AnotherValue>(someVal);
 
-and ``valOr`` will be ``None`` if either ``someVal`` cannot be converted *or*
-if ``someVal`` was also ``None``.
+and ``valOr`` will be ``std::nullopt`` if either ``someVal`` cannot be converted *or*
+if ``someVal`` was also ``std::nullopt``.

diff  --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 76c555d25ebf0..ba89da3cbe925 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -1828,7 +1828,7 @@ class Record {
 
   /// This method looks up the specified field and returns its value as a
   /// string, throwing an exception if the value is not a string and
-  /// llvm::Optional() if the field does not exist.
+  /// std::nullopt if the field does not exist.
   std::optional<StringRef> getValueAsOptionalString(StringRef FieldName) const;
 
   /// This method looks up the specified field and returns its value as a

diff  --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index 5988ca27d84de..9f21299813580 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -1405,7 +1405,7 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape,
 // function call or any of the memory intrinsics, we check whether this
 // instruction is prior to CoroBegin. To answer question 3, we track the offsets
 // of all aliases created for the alloca prior to CoroBegin but used after
-// CoroBegin. llvm::Optional is used to be able to represent the case when the
+// CoroBegin. std::optional is used to be able to represent the case when the
 // offset is unknown (e.g. when you have a PHINode that takes in 
diff erent
 // offset values). We cannot handle unknown offsets and will assert. This is the
 // potential issue left out. An ideal solution would likely require a


        


More information about the llvm-commits mailing list