[llvm] 1ea9dd3 - [llvm] Use std::nullopt instead of llvm::None (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 23:50:10 PST 2022


Author: Kazu Hirata
Date: 2022-12-05T23:50:04-08:00
New Revision: 1ea9dd32709f9b5def5e1c9e83b0a5cdbb134fb2

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

LOG: [llvm] Use std::nullopt instead of llvm::None (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/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
    llvm/lib/LineEditor/LineEditor.cpp
    llvm/lib/Support/Windows/Process.inc
    llvm/lib/Support/Windows/Threading.inc
    llvm/lib/Support/Z3Solver.cpp
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
    llvm/lib/Target/M68k/M68kMCInstLower.cpp
    llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
index ee4078a20b729..d211a96cd3921 100644
--- a/llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/DIA/DIADataStream.cpp
@@ -30,11 +30,11 @@ DIADataStream::getItemAtIndex(uint32_t Index) const {
   DWORD RecordSize = 0;
   StreamData->Item(Index, 0, &RecordSize, nullptr);
   if (RecordSize == 0)
-    return llvm::None;
+    return std::nullopt;
 
   Record.resize(RecordSize);
   if (S_OK != StreamData->Item(Index, RecordSize, &RecordSize, &Record[0]))
-    return llvm::None;
+    return std::nullopt;
   return Record;
 }
 

diff  --git a/llvm/lib/LineEditor/LineEditor.cpp b/llvm/lib/LineEditor/LineEditor.cpp
index 120435c2644e9..32a58f02ab699 100644
--- a/llvm/lib/LineEditor/LineEditor.cpp
+++ b/llvm/lib/LineEditor/LineEditor.cpp
@@ -301,7 +301,7 @@ Optional<std::string> LineEditor::readLine() const {
     char *Res = ::fgets(Buf, sizeof(Buf), Data->In);
     if (!Res) {
       if (Line.empty())
-        return None;
+        return std::nullopt;
       else
         return Line;
     }

diff  --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index 000a42bc7a80b..86ff261255a98 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -120,7 +120,7 @@ Optional<std::string> Process::GetEnv(StringRef Name) {
   // Convert the argument to UTF-16 to pass it to _wgetenv().
   SmallVector<wchar_t, 128> NameUTF16;
   if (windows::UTF8ToUTF16(Name, NameUTF16))
-    return None;
+    return std::nullopt;
 
   // Environment variable can be encoded in non-UTF8 encoding, and there's no
   // way to know what the encoding is. The only reliable way to look up
@@ -132,7 +132,7 @@ Optional<std::string> Process::GetEnv(StringRef Name) {
     SetLastError(NO_ERROR);
     Size = GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.size());
     if (Size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
-      return None;
+      return std::nullopt;
 
     // Try again with larger buffer.
   } while (Size > Buf.size());
@@ -141,7 +141,7 @@ Optional<std::string> Process::GetEnv(StringRef Name) {
   // Convert the result from UTF-16 to UTF-8.
   SmallVector<char, MAX_PATH> Res;
   if (windows::UTF16ToUTF8(Buf.data(), Size, Res))
-    return None;
+    return std::nullopt;
   return std::string(Res.data());
 }
 

diff  --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 3c012f12ea6ef..533486a17524b 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -254,14 +254,14 @@ llvm::ThreadPoolStrategy::compute_cpu_socket(unsigned ThreadPoolNum) const {
   // Only one CPU socket in the system or process affinity was set, no need to
   // move the thread(s) to another CPU socket.
   if (Groups.size() <= 1)
-    return None;
+    return std::nullopt;
 
   // We ask for less threads than there are hardware threads per CPU socket, no
   // need to dispatch threads to other CPU sockets.
   unsigned MaxThreadsPerSocket =
       UseHyperThreads ? Groups[0].UsableThreads : Groups[0].useableCores();
   if (compute_thread_count() <= MaxThreadsPerSocket)
-    return None;
+    return std::nullopt;
 
   assert(ThreadPoolNum < compute_thread_count() &&
          "The thread index is not within thread strategy's range!");

diff  --git a/llvm/lib/Support/Z3Solver.cpp b/llvm/lib/Support/Z3Solver.cpp
index 1f8444df3c9a3..499548e91286b 100644
--- a/llvm/lib/Support/Z3Solver.cpp
+++ b/llvm/lib/Support/Z3Solver.cpp
@@ -878,7 +878,7 @@ class Z3Solver : public SMTSolver {
     if (res == Z3_L_FALSE)
       return false;
 
-    return None;
+    return std::nullopt;
   }
 
   void push() override { return Z3_solver_push(Context.Context, Solver); }

diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index 0d524b4ecf6d9..6cadadf19a6fe 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -38,7 +38,7 @@ LoongArchAsmBackend::getFixupKind(StringRef Name) const {
     if (Type != -1u)
       return static_cast<MCFixupKind>(FirstLiteralRelocationKind + Type);
   }
-  return None;
+  return std::nullopt;
 }
 
 const MCFixupKindInfo &

diff  --git a/llvm/lib/Target/M68k/M68kMCInstLower.cpp b/llvm/lib/Target/M68k/M68kMCInstLower.cpp
index b3388df93748f..40844803aead1 100644
--- a/llvm/lib/Target/M68k/M68kMCInstLower.cpp
+++ b/llvm/lib/Target/M68k/M68kMCInstLower.cpp
@@ -119,7 +119,7 @@ M68kMCInstLower::LowerOperand(const MachineInstr *MI,
   case MachineOperand::MO_Register:
     // Ignore all implicit register operands.
     if (MO.isImplicit())
-      return None;
+      return std::nullopt;
     return MCOperand::createReg(MO.getReg());
   case MachineOperand::MO_Immediate:
     return MCOperand::createImm(MO.getImm());
@@ -138,7 +138,7 @@ M68kMCInstLower::LowerOperand(const MachineInstr *MI,
         MO, AsmPrinter.GetBlockAddressSymbol(MO.getBlockAddress()));
   case MachineOperand::MO_RegisterMask:
     // Ignore call clobbers.
-    return None;
+    return std::nullopt;
   }
 }
 

diff  --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index 94f403183e5ac..3ebb60b58ced5 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -1746,7 +1746,7 @@ std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
 
   if (!Call) {
     LLVM_DEBUG(dbgs() << "Builtin record was not found!\n");
-    return None;
+    return std::nullopt;
   }
 
   // TODO: check if the provided args meet the builtin requirments.


        


More information about the llvm-commits mailing list