From dcc6b7b1d5e5a0f9537ce1bf919ac2338bd7ad7b Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Thu, 5 Aug 2021 11:42:30 +0000 Subject: [PATCH] [OptTable] Refine how `printHelp` treats empty help texts Currently, `printHelp` behaves differently for options that: * do not define `HelpText` (such options _are not printed_), and * define its `HelpText` as `HelpText<"">` (such options _are printed_). In practice, both approaches lead to no help text and `printHelp` should treat them consistently. This patch addresses that by making `printHelpt` check the length of the help text to be printed. All affected tests have been updated accordingly. The option definitions for llvm-cvtres have been updated with a short description or "Not implemented" for options that are ignored by the tool. Differential Revision: https://reviews.llvm.org/D107557 --- flang/test/Driver/driver-help-hidden.f90 | 5 ----- flang/test/Driver/driver-help.f90 | 12 ------------ llvm/lib/Option/OptTable.cpp | 2 +- llvm/test/tools/llvm-cvtres/help.test | 14 ++++++++------ llvm/tools/llvm-cvtres/Opts.td | 16 ++++++++-------- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 index 9e63408..c91fdaa 100644 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -39,12 +39,7 @@ ! CHECK-NEXT: Specify where to find the compiled intrinsic modules ! CHECK-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations -! CHECK-NEXT: -fno-backslash ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics -! CHECK-NEXT: -fno-implicit-none -! CHECK-NEXT: -fno-logical-abbreviations -! CHECK-NEXT: {{[[:space:]]$}} -! CHECK-NEXT: -fno-xor-operator ! CHECK-NEXT: -fopenacc Enable OpenACC ! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 index 441cf73..b895dc4 100644 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -39,12 +39,7 @@ ! HELP-NEXT: Specify where to find the compiled intrinsic modules ! HELP-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations -! HELP-NEXT: -fno-backslash ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics -! HELP-NEXT: -fno-implicit-none -! HELP-NEXT: -fno-logical-abbreviations -! HELP-NEXT: {{[[:space:]]$}} -! HELP-NEXT: -fno-xor-operator ! HELP-NEXT: -fopenacc Enable OpenACC ! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. @@ -73,8 +68,6 @@ ! HELP-FC1-NEXT: -E Only run the preprocessor ! HELP-FC1-NEXT: -falternative-parameter-statement ! HELP-FC1-NEXT: Enable the old style PARAMETER statement -! HELP-FC1-NEXT: -fanalyzed-objects-for-unparse -! HELP-FC1-NEXT: {{[[:space:]]$}} ! HELP-FC1-NEXT: -fbackslash Specify that backslash in string introduces an escape character ! HELP-FC1-NEXT: -fdebug-dump-all Dump symbols and the parse tree after the semantic checks ! HELP-FC1-NEXT: -fdebug-dump-parse-tree-no-sema @@ -110,12 +103,7 @@ ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations ! HELP-FC1-NEXT: -fno-analyzed-objects-for-unparse ! HELP-FC1-NEXT: Do not use the analyzed objects when unparsing -! HELP-FC1-NEXT: -fno-backslash -! HELP-FC1-NEXT: -fno-implicit-none -! HELP-FC1-NEXT: -fno-logical-abbreviations -! HELP-FC1-NEXT: {{[[:space:]]$}} ! HELP-FC1-NEXT: -fno-reformat Dump the cooked character stream in -E mode -! HELP-FC1-NEXT: -fno-xor-operator ! HELP-FC1-NEXT: -fopenacc Enable OpenACC ! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index f5bf166..a994a42 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -654,7 +654,7 @@ void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title, HelpText = getOptionHelpText(Alias.getID()); } - if (HelpText) { + if (HelpText && (strlen(HelpText) != 0)) { const char *HelpGroup = getOptionHelpGroup(*this, Id); const std::string &OptName = getOptionHelpName(*this, Id); GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText}); diff --git a/llvm/test/tools/llvm-cvtres/help.test b/llvm/test/tools/llvm-cvtres/help.test index 3be7c96..a3817e9 100644 --- a/llvm/test/tools/llvm-cvtres/help.test +++ b/llvm/test/tools/llvm-cvtres/help.test @@ -4,11 +4,13 @@ ; HELP_TEST: OVERVIEW: Resource Converter ; HELP_TEST-DAG: USAGE: llvm-cvtres [options] file... ; HELP_TEST-DAG: OPTIONS: -; HELP_TEST-NEXT: /DEFINE:symbol -; HELP_TEST-NEXT: /FOLDDUPS: +; HELP_TEST-NEXT: /DEFINE:symbol Not implemented +; HELP_TEST-NEXT: /FOLDDUPS: Not implemented +; HELP_TEST-NEXT: /HELP Display available options ; HELP_TEST-NEXT: /MACHINE:{ARM|ARM64|EBC|IA64|X64|X86} -; HELP_TEST-DAG: /NOLOGO -; HELP_TEST-NEXT: /OUT:filename -; HELP_TEST-NEXT: /READONLY +; HELP_TEST-NEXT: Machine architecture +; HELP_TEST-DAG: /NOLOGO Not implemented +; HELP_TEST-NEXT: /OUT:filename Output file +; HELP_TEST-NEXT: /READONLY Not implemented ; HELP_TEST-NEXT: /TIMESTAMP: Timestamp for coff header, defaults to current time -; HELP_TEST-NEXT: /VERBOSE +; HELP_TEST-NEXT: /VERBOSE Use verbose output diff --git a/llvm/tools/llvm-cvtres/Opts.td b/llvm/tools/llvm-cvtres/Opts.td index 8687d47..21d5837 100644 --- a/llvm/tools/llvm-cvtres/Opts.td +++ b/llvm/tools/llvm-cvtres/Opts.td @@ -2,14 +2,14 @@ include "llvm/Option/OptParser.td" // All the switches can be preceded by either '/' or '-'. -def DEFINE : Joined<["/", "-"], "DEFINE:">, HelpText<"">, MetaVarName<"symbol">; -def FOLDDUPS : Flag<["/", "-"], "FOLDDUPS:">, HelpText<"">; -def MACHINE : Joined<["/", "-"], "MACHINE:">, HelpText<"">, MetaVarName<"{ARM|ARM64|EBC|IA64|X64|X86}">; -def NOLOGO : Flag<["/", "-"], "NOLOGO">, HelpText<"">; -def OUT : Joined<["/", "-"], "OUT:">, HelpText<"">, MetaVarName<"filename">; -def READONLY : Flag<["/", "-"], "READONLY">, HelpText<"">; -def VERBOSE : Flag<["/", "-"], "VERBOSE">, HelpText<"">; -def HELP : Flag<["/", "-"], "HELP">; +def DEFINE : Joined<["/", "-"], "DEFINE:">, HelpText<"Not implemented">, MetaVarName<"symbol">; +def FOLDDUPS : Flag<["/", "-"], "FOLDDUPS:">, HelpText<"Not implemented">; +def MACHINE : Joined<["/", "-"], "MACHINE:">, HelpText<"Machine architecture">, MetaVarName<"{ARM|ARM64|EBC|IA64|X64|X86}">; +def NOLOGO : Flag<["/", "-"], "NOLOGO">, HelpText<"Not implemented">; +def OUT : Joined<["/", "-"], "OUT:">, HelpText<"Output file">, MetaVarName<"filename">; +def READONLY : Flag<["/", "-"], "READONLY">, HelpText<"Not implemented">; +def VERBOSE : Flag<["/", "-"], "VERBOSE">, HelpText<"Use verbose output">; +def HELP : Flag<["/", "-"], "HELP">, HelpText<"Display available options">; def H : Flag<["/", "-"], "H">, Alias; def HELP_Q : Flag<["/?", "-?"], "">, Alias; -- 2.7.4