[llvm] [Support] Accept -no-<name> to negate cl::opt<bool> (PR #224978)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 01:43:42 PDT 2026


================
@@ -551,7 +551,17 @@ Option *CommandLineParser::LookupOption(SubCommand &Sub, StringRef &Arg,
   // If we have an equals sign, remember the value.
   if (EqualPos == StringRef::npos) {
     // Look up the option.
-    return Sub.OptionsMap.lookup(Arg);
+    if (Option *O = Sub.OptionsMap.lookup(Arg))
+      return O;
+    // -no-<name> negates the boolean option <name>.
----------------
MaskRay wrote:

The `no-<name>` fallback runs only after `OptionsMap.lookup(Arg)` fails. For a `no-<name>` option this requires two hash table lookups. This is an acceptable cost since it's rare to have super long `-no-<name>` option chain. The longest command lines I have seen are mostly clang driver and -Xclang cc1 options. -mllvm options are rare.

https://github.com/llvm/llvm-project/pull/224978


More information about the llvm-commits mailing list