[llvm] f90025e - [llvm] Compare std::optional<T> to values directly (NFC) (#146222)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 28 13:04:19 PDT 2025


Author: Kazu Hirata
Date: 2025-06-28T13:04:16-07:00
New Revision: f90025ebd930a4719f3d7ac61d802ce948f9f433

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

LOG: [llvm] Compare std::optional<T> to values directly (NFC) (#146222)

This patch transforms:

  X && *X == Y

to:

  X == Y

where X is of std::optional<T>, and Y is of T or similar.

Added: 
    

Modified: 
    llvm/lib/TargetParser/AArch64TargetParser.cpp
    llvm/unittests/Support/RISCVAttributeParserTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index 2c805e2f7e664..c17fa729bac4f 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -50,7 +50,7 @@ std::optional<AArch64::ArchInfo> AArch64::ArchInfo::findBySubArch(StringRef SubA
 
 std::optional<AArch64::FMVInfo> lookupFMVByID(AArch64::ArchExtKind ExtID) {
   for (const AArch64::FMVInfo &Info : AArch64::getFMVInfo())
-    if (Info.ID && *Info.ID == ExtID)
+    if (Info.ID == ExtID)
       return Info;
   return {};
 }

diff  --git a/llvm/unittests/Support/RISCVAttributeParserTest.cpp b/llvm/unittests/Support/RISCVAttributeParserTest.cpp
index 777dc4d0f4d42..7e862822fdd74 100644
--- a/llvm/unittests/Support/RISCVAttributeParserTest.cpp
+++ b/llvm/unittests/Support/RISCVAttributeParserTest.cpp
@@ -45,7 +45,7 @@ static bool testAttribute(unsigned Tag, unsigned Value, unsigned ExpectedTag,
   cantFail(Parser.parse(Bytes, llvm::endianness::little));
 
   std::optional<unsigned> Attr = Parser.getAttributeValue("", ExpectedTag);
-  return Attr && *Attr == ExpectedValue;
+  return Attr == ExpectedValue;
 }
 
 static bool testTagString(unsigned Tag, const char *name) {


        


More information about the llvm-commits mailing list