[llvm] [mlir] [Support] Accept only true, false, 1 and 0 for cl::opt<bool> (PR #224975)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 00:27:03 PDT 2026
================
@@ -439,13 +439,13 @@ static CommandLineParser &globalParser() {
template <typename T, T TrueVal, T FalseVal>
static bool parseBool(Option &O, StringRef ArgName, StringRef Arg, T &Value) {
- if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
- Arg == "1") {
+ // A bare -flag passes a null Arg; -flag= passes an empty one.
+ if (!Arg.data() || Arg == "true" || Arg == "1") {
----------------
MaskRay wrote:
`!Arg.data()` is intentional. To reject `-flag=`, we should test `!Arg.data()` here.
When `ProvideOption → addOccurrence → parser<bool>::parse → parseBool` runs:
- `-flag` → Arg.data() == nullptr (null, "no value given")
- `-flag=` → Arg.data() != nullptr && Arg.empty() (an explicitly empty value)
- `-flag=x` → "x"
https://github.com/llvm/llvm-project/pull/224975
More information about the llvm-commits
mailing list