[clang] 2df0fa4 - [clang] Use StringRef::consume_front (NFC)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 27 00:19:17 PST 2023


Author: Kazu Hirata
Date: 2023-12-27T00:19:12-08:00
New Revision: 2df0fa41a3aa416d84f9f22490f329bf851d447e

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

LOG: [clang] Use StringRef::consume_front (NFC)

Added: 
    

Modified: 
    clang/lib/Basic/Warnings.cpp
    clang/lib/Driver/ToolChains/Arch/X86.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Warnings.cpp b/clang/lib/Basic/Warnings.cpp
index bab1af4f03b67b..92954cab6fb040 100644
--- a/clang/lib/Basic/Warnings.cpp
+++ b/clang/lib/Basic/Warnings.cpp
@@ -96,11 +96,7 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
 
       // Check to see if this warning starts with "no-", if so, this is a
       // negative form of the option.
-      bool isPositive = true;
-      if (Opt.starts_with("no-")) {
-        isPositive = false;
-        Opt = Opt.substr(3);
-      }
+      bool isPositive = !Opt.consume_front("no-");
 
       // Figure out how this option affects the warning.  If -Wfoo, map the
       // diagnostic to a warning, if -Wno-foo, map it to ignore.

diff  --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index fef0522aaf45b8..53e26a9f8e229e 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -237,9 +237,7 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
     assert(Name.starts_with("m") && "Invalid feature name.");
     Name = Name.substr(1);
 
-    bool IsNegative = Name.starts_with("no-");
-    if (IsNegative)
-      Name = Name.substr(3);
+    bool IsNegative = Name.consume_front("no-");
 
 #ifndef NDEBUG
     assert(Name.starts_with("avx10.") && "Invalid AVX10 feature name.");


        


More information about the cfe-commits mailing list