From 2626ede61bd9240905ff52a28f864ae1576746b1 Mon Sep 17 00:00:00 2001 From: Don Hinton Date: Fri, 3 May 2019 18:56:25 +0000 Subject: [PATCH] [CommandLine] Enable Grouping for short options by default. Part 4 of 5 Summary: This change enables `cl::Grouping` for short options -- options with names of a single character. This is consistent with GNU getopt behavior. Reviewers: rnk, MaskRay Reviewed By: MaskRay Subscribers: thopre, cfe-commits, MaskRay, rupprecht, hiraditya, llvm-commits Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D61270 llvm-svn: 359917 --- include/llvm/Support/CommandLine.h | 6 +++++- lib/Support/CommandLine.cpp | 2 ++ test/tools/llvm-readobj/merged.test | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index 7951128a48a..74f5de6621e 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -1200,7 +1200,11 @@ template <> struct applicator { }; template <> struct applicator { - static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); } + static void opt(MiscFlags MF, Option &O) { + assert((MF != Grouping || O.ArgStr.size() == 1) && + "cl::Grouping can only apply to single charater Options."); + O.setMiscFlag(MF); + } }; // apply method - Apply modifiers to an option in a type safe way. diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 1ca31b69c78..ff53fefefea 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -421,6 +421,8 @@ void Option::setArgStr(StringRef S) { GlobalParser->updateArgStr(this, S); assert((S.empty() || S[0] != '-') && "Option can't start with '-"); ArgStr = S; + if (ArgStr.size() == 1) + setMiscFlag(Grouping); } void Option::reset() { diff --git a/test/tools/llvm-readobj/merged.test b/test/tools/llvm-readobj/merged.test index 0fcc14f1f95..a6f567cda6c 100644 --- a/test/tools/llvm-readobj/merged.test +++ b/test/tools/llvm-readobj/merged.test @@ -10,4 +10,4 @@ RUN: FileCheck %s --input-file %t.merged RUN: not llvm-readobj -aeWhSrnudlVgIs %p/Inputs/trivial.obj.elf-i386 2>&1 | FileCheck %s --check-prefix=UNKNOWN CHECK-NOT: Unknown command line argument -UNKNOWN: Unknown command line argument +UNKNOWN: for the --section-headers option: may only occur zero or one times!