aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Option/OptTable.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-08-31Revert "[OptTable] Improve error message output for grouped short options"Kevin Athey1-13/+4
This reverts commit 71d7fed3bc2ad6c22729d446526a59fcfd99bd03. Reason: broke sanitizer bots more info: https://reviews.llvm.org/D108770
2021-08-31[OptTable] Improve error message output for grouped short optionsgbreynoo1-4/+13
As seen in https://bugs.llvm.org/show_bug.cgi?id=48880 the current implementation for parsing grouped short options can return unclear error messages. This change fixes the example given in the ticket in which a flag is incorrectly given an argument. Also when parsing a group we now keep reading past the first incorrect option and output errors for all incorrect options in the group. Differential Revision: https://reviews.llvm.org/D108770
2021-08-19[OptTable] Refine how `printHelp` treats empty help textsAndrzej Warzynski1-1/+1
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
2021-06-24[OptTable] Rename PrintHelp to printHelpFangrui Song1-3/+3
To be consistent with other member functions and match the coding standard.
2021-06-25[llvm] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-3/+2
This is a mechanical change. This actually also renames the similarly named methods in the SmallString class, however these methods don't seem to be used outside of the llvm subproject, so this doesn't break building of the rest of the monorepo.
2021-01-11[llvm] Simplify string comparisons (NFC)Kazu Hirata1-1/+1
Identified with readability-string-compare.
2020-12-05Remove memory allocation with stringAditya Kumar1-3/+5
Differential Revision: https://reviews.llvm.org/D92506
2020-09-11[NFC] Fix the signature and definition of findByPrefixAndrzej Warzynski1-1/+1
In https://reviews.llvm.org/rG257b29715bb27b7d9f6c3c40c481b6a4af0b37e5, the definition of OptTable::Info::Flags was changed from `unsigned short` to `unsigned int`, but the definition/declaration of OptTable::findByPrefix wasn't updated to reflect that. This patch updates findByPrefix accordingly.
2020-08-12[Clang options] Optimize optionMatches() runtime by removing mallocsNadav Rotem1-2/+3
The method optionMatches() constructs 9865 std::string instances when comparing different options. Many of these instances exceed the size of the internal storage and force memory allocations. This patch adds an early exit check that eliminates most of the string allocations while keeping the code simple. Example inputs: Prefix: /, Name: Fr Prefix: -, Name: Fr Prefix: -, Name: fsanitize-address-field-padding= Prefix: -, Name: fsanitize-address-globals-dead-stripping Prefix: -, Name: fsanitize-address-poison-custom-array-cookie Prefix: -, Name: fsanitize-address-use-after-scope Prefix: -, Name: fsanitize-address-use-odr-indicator Prefix: -, Name: fsanitize-blacklist= Differential Revision: D85538
2020-08-04[llvm-symbolizer] Switch command line parsing from llvm::cl to OptTableFangrui Song1-2/+30
for the advantage outlined by D83639 ([OptTable] Support grouped short options) Some behavior changes: * -i={0,false} is removed. Use --no-inlines instead. * --demangle={0,false} is removed. Use --no-demangle instead * -untag-addresses={0,false} is removed. Use --no-untag-addresses instead Added a higher level API OptTable::parseArgs which handles optional initial options populated from an environment variable, expands response files recursively, and parses options. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D83530
2020-07-17[OptTable] Support grouped short optionsFangrui Song1-3/+61
POSIX.1-2017 12.2 Utility Syntax Guidelines, Guideline 5 says: > One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one '-' delimiter. i.e. -abc represents -a -b -c. The grouped short options are very common. Many utilities extend the syntax by allowing (an option with an argument) following a sequence of short options. This patch adds the support to OptTable, similar to cl::Group for CommandLine (D58711). llvm-symbolizer will use the feature (D83530). CommandLine is exotic in some aspects. OptTable is preferred if the user wants to get rid of the behaviors. * `cl::opt<bool> i(...)` can be disabled via -i=false or -i=0, which is different from conventional --no-i. * Handling --foo & --no-foo requires a comparison of argument positions, which is a bit clumsy in user code. OptTable::parseOneArg (non-const reference InputArgList) is added along with ParseOneArg (const ArgList &). The duplicate does not look great at first glance. However, The implementation can be simpler if ArgList is mutable. (ParseOneArg is used by clang-cl (FlagsToInclude/FlagsToExclude) and lld COFF (case-insensitive). Adding grouped short options can make the function even more complex.) The implementation allows a long option following a group of short options. We probably should refine the code to disallow this in the future. Allowing this seems benign for now. Reviewed By: grimar, jhenderson Differential Revision: https://reviews.llvm.org/D83639
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-3/+3
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-05-01Option spell checking: Penalize delimiter flags if input has no argumentNico Weber1-0/+9
If the user passes a flag like `-version` to a program, it's more likely they mean `--version` than `-version:`, since there's no parameter passed. Hence, give delimited arguments a penalty of 1 if the user input doesn't contain the delimiter or no data after it. The motivation is that with this, lld-link can suggest "--version" instead of "-version:" for "-version" and "-nodefaultlib" instead of "-nodefaultlib:" for "-nodefaultlibs". Differential Revision: https://reviews.llvm.org/D61382 llvm-svn: 359701
2019-05-01Fix OptTable::findNearest() adding delimiter for freeNico Weber1-9/+8
Prior to this, OptTable::findNearest() thought that the input `--foo` had an editing distance of 0 from an existing flag `--foo=`, which made it suggest flags with delimiters more often than flags without one. After this, it correctly assigns this case an editing distance of 1. Differential Revision: https://reviews.llvm.org/D61373 llvm-svn: 359685
2019-05-01Wrap to 80 columns, no behavior changeNico Weber1-1/+2
llvm-svn: 359679
2019-04-30Fix stack-use-after free after r359580Nico Weber1-3/+4
`Candidate` was a StringRef refering to a temporary string. Instead, create a local variable for the string and use a StringRef referring to that. llvm-svn: 359604
2019-04-30Re-reland "[Option] Fix PR37006 prefix choice in findNearest"Nico Weber1-24/+24
This was first reviewed in https://reviews.llvm.org/D46776 and landed in r332299, but got reverted because it broke the PS4 bots. https://reviews.llvm.org/D50410 fixed this, and then this change was re-reviewed at https://reviews.llvm.org/D50515 and relanded in r341329. It got reverted due to causing MSan issues. However, nobody wrote down the error message and the bot link is dead, so I'm relanding this to capture the MSan error. I'll then either fix it, or copy it somewhere and revert if fixing looks difficult. llvm-svn: 359580
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-10-10[opt] Change the parameter of OptTable::PrintHelp from Name to Usage and ↵Fangrui Song1-7/+5
don't append "[options] <inputs>" Summary: Before, "[options] <inputs>" is unconditionally appended to the `Name` parameter. It is more flexible to change its semantic to `Usage` and let user customize the usage line. % llvm-objcopy ... USAGE: llvm-objcopy <input> [ <output> ] [options] <inputs> With this patch: % llvm-objcopy ... USAGE: llvm-objcopy input [output] Reviewers: rupprecht, alexshap, jhenderson Reviewed By: rupprecht Subscribers: jakehehrlich, mehdi_amini, steven_wu, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D51009 llvm-svn: 344097
2018-09-03Revert r341329 due to MSAN errorBrian Gesiak1-24/+24
Pushing https://reviews.llvm.org/rL341329 revealed an MSAN error. Revert it so that we can fix the error. llvm-svn: 341333
2018-09-03Re-push "[Option] Fix PR37006 prefix choice in findNearest"Brian Gesiak1-24/+24
Summary: Original changeset (https://reviews.llvm.org/D46776) by @modocache. It was reverted after the PS4 bot failed. The issue has been determined to be with the way the PS4 SDK handles this particular option. https://reviews.llvm.org/D50410 removes this test, so we can push this again. Patch by Arnaud Coomans! Reviewers: cfe-commits, modocache Reviewed By: modocache Differential Revision: https://reviews.llvm.org/D50515 llvm-svn: 341329
2018-05-19Re-revert "[Option] Fix PR37006 prefix choice in findNearest"Brian Gesiak1-24/+24
Summary: Reverting due to a test failure in an llvm-mt test on some buildbots, namely http://green.lab.llvm.org/green/job/clang-stage2-configure-Rlto/26020/. llvm-svn: 332812
2018-05-19Un-revert "[Option] Fix PR37006 prefix choice in findNearest"Brian Gesiak1-24/+24
Summary: In https://reviews.llvm.org/rL332804 I loosed the assertion in the Clang driver test that forced me to revert https://reviews.llvm.org/rL332299. Once this lands I should be able to narrow down what caused PS4 buildbots to fail, and reinstate the check in that test. Test Plan: check-llvm & check-clang llvm-svn: 332805
2018-05-14Revert "[Option] Fix PR37006 prefix choice in findNearest"Brian Gesiak1-24/+24
Summary: This revision causes build failures in PS4 and ppc64le buildbots (for example, http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/29988). I'll revert for now and try to diagnose the issue. Test Plan: check-llvm check-clang llvm-svn: 332304
2018-05-14[Option] Fix PR37006 prefix choice in findNearestBrian Gesiak1-24/+24
Summary: In https://bugs.llvm.org/show_bug.cgi?id=37006 Nico Weber points out a flaw in `OptTable::findNearest`: if an option "foo"'s prefixes are "--" and "-", then the nearest option for "--fob" will be "-foo". This is incorrect, however, since the function is expected to return "--foo". The bug is due to a naive loop that attempts to predetermines which prefix is best. Instead, compute the edit distance for each prefix/name pair. Test Plan: `check-llvm` Reviewers: thakis Reviewed By: thakis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D46776 llvm-svn: 332299
2018-03-12[NFC] Replace iterators in PrintHelp with range-based forJan Korous1-6/+4
llvm-svn: 327312
2018-03-12[NFC] PrintHelp cleanupJan Korous1-3/+1
llvm-svn: 327311
2018-03-05[Bash-autocompletion] Pass all flags in shell command-line to ClangYuka Takahashi1-2/+2
Previously, we passed "#" to --autocomplete to indicate to enable cc1 flags. For example, when -cc1 or -Xclang was passed to bash, bash executed `clang --autocomplete=#-<flag they want to complete>`. However, this was not a good implementation because it depends -Xclang and -cc1 parsing to shell. So I changed this to pass all flags shell has, so that Clang can handle them internally. I had to change many testcases because API spec changed quite a lot. Reviewers: teemperor, v.g.vassilev Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39342 llvm-svn: 326684
2018-01-09[Option] For typo '-foo', suggest '--foo'Brian Gesiak1-2/+2
Summary: https://reviews.llvm.org/rL321877 introduced the `OptTable::findNearest` method, to find the closest edit distance option for a given string. However, the implementation contained a bug: for a typo `-foo` with an edit distance of 1 away from a valid option `--foo`, `findNearest` would suggest a nearby option of `foo`. That is, the result would not include the `--` prefix, and so was not a valid option. Fix the bug by ensuring that the prefix string is initialized to one of the valid prefixes for the option. Test Plan: `check-llvm-unit` Reviewers: v.g.vassilev, teemperor, ruiu, jroelofs, yamaguchi Reviewed By: jroelofs Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41873 llvm-svn: 322109
2018-01-05[Option] Add 'findNearest' method to catch typosBrian Gesiak1-0/+63
Summary: Add a method `OptTable::findNearest`, which allows users of OptTable to check user input for misspelled options. In addition, have llvm-mt check for misspelled options. For example, if a user invokes `llvm-mt /oyt:foo`, the error message will indicate that while an option named `/oyt:` does not exist, `/out:` does. The method ports the functionality of the `LookupNearestOption` method from LLVM CommandLine to libLLVMOption. This allows tools like Clang and Swift, which do not use CommandLine, to use this functionality to suggest similarly spelled options. As room for future improvement, the new method as-is cannot yet properly suggest nearby "joined" options -- that is, for an option string "-FozBar", where "-Foo" is the correct option name and "Bar" is the value being passed along with the misspelled option, this method will calculate an edit distance of 4, by deleting "Bar" and changing "z" to "o". It should instead calculate an edit distance of just 1, by changing "z" to "o" and recognizing "Bar" as a value. This commit includes a disabled test that expresses this limitation. Test Plan: `check-llvm` Reviewers: yamaguchi, v.g.vassilev, teemperor, ruiu, jroelofs Reviewed By: jroelofs Subscribers: jroelofs, llvm-commits Differential Revision: https://reviews.llvm.org/D41732 llvm-svn: 321877
2017-08-29Revert "Revert r311552: [Bash-autocompletion] Add support for static ↵Yuka Takahashi1-6/+19
analyzer flags" This reverts commit 7c46b80c022e18d43c1fdafb117b0c409c5a6d1e. r311552 broke lld buildbot because I've changed OptionInfos type from ArrayRef to vector. However the bug is fixed, so I'll commit this again. llvm-svn: 311958
2017-08-24test commit: fix typo in commentNathan Hawes1-1/+1
llvm-svn: 311701
2017-08-23Revert r311552: [Bash-autocompletion] Add support for static analyzer flagsRui Ueyama1-19/+6
This reverts commit r311552 because it broke ubsan and asan bots. llvm-svn: 311557
2017-08-23[Bash-autocompletion] Add support for static analyzer flagsYuka Takahashi1-6/+19
Summary: This is a patch for clang autocomplete feature. It will collect values which -analyzer-checker takes, which is defined in clang/StaticAnalyzer/Checkers/Checkers.inc, dynamically. First, from ValuesCode class in Options.td, TableGen will generate C++ code in Options.inc. Options.inc will be included in DriverOptions.cpp, and calls OptTable's addValues function. addValues function will add second argument to Option's Values class. Values contains string like "foo,bar,.." which is handed to Values class in OptTable. Reviewers: v.g.vassilev, teemperor, ruiu Subscribers: hiraditya, cfe-commits Differential Revision: https://reviews.llvm.org/D36782 llvm-svn: 311552
2017-07-26[Bash-autocompletion] Show HelpText with possible flagsYuka Takahashi1-1/+3
Summary: `clang --autocomplete=-std` will show ``` -std: Language standard to compile for -std= Language standard to compile for -stdlib= C++ standard library to use ``` after this change. However, showing HelpText with completion in bash seems super tricky, so this feature will be used in other shells (fish, zsh...). Reviewers: v.g.vassilev, teemperor, ruiu Subscribers: cfe-commits, hiraditya Differential Revision: https://reviews.llvm.org/D35759 llvm-svn: 309113
2017-07-26[libOption] - Add flag allowing to print options aliases in help text.George Rimar1-7/+15
By default, we display only options that are not hidden and have help texts. This patch adds flag allowing to display aliases that have no help text. In this case help text of aliased option used instead. Differential revision: https://reviews.llvm.org/D35476 llvm-svn: 309087
2017-07-18[libOption] - Replace std::pair with helper struct. NFC.George Rimar1-12/+13
Splitted from D35476. llvm-svn: 308293
2017-07-08[Bash-autocompletion] Auto complete cc1 options if -cc1 is specifiedYuka Takahashi1-1/+5
Summary: We don't want to autocomplete flags whose Flags class has `NoDriverOption` when argv[1] is not `-cc1`. Another idea for this implementation is to make --autocomplete a cc1 option and handle it in clang Frontend, by porting --autocomplete handler from Driver to Frontend, so that we can handle Driver options and CC1 options in unified manner. Differential Revision: https://reviews.llvm.org/D34770 llvm-svn: 307479
2017-07-05[Bash-autocompletion] Show flags which has HelpText or GroupIDYuka Takahashi1-1/+1
Summary: Otherwise internal flags will be also completed. Differential Revision: https://reviews.llvm.org/D34930 llvm-svn: 307116
2017-06-20[GSoC] Flag value completion for clangYuka Takahashi1-0/+34
This is patch for GSoC project, bash-completion for clang. To use this on bash, please run `source clang/utils/bash-autocomplete.sh`. bash-autocomplete.sh is code for bash-completion. In this patch, Options.td was mainly changed in order to add value class in Options.inc. llvm-svn: 305805
2017-06-16[BinaryFormat, Option, TableGen] Fix some Clang-tidy modernize-use-using and ↵Eugene Zelenko1-16/+24
Include What You Use warnings; other minor fixes (NFC). llvm-svn: 305537
2017-05-23[GSoC] Shell autocompletion for clangYuka Takahashi1-0/+14
Summary: This is a first patch for GSoC project, bash-completion for clang. To use this on bash, please run `source clang/utils/bash-autocomplete.sh`. bash-autocomplete.sh is code for bash-completion. Simple flag completion and path completion is available in this patch. Reviewers: teemperor, v.g.vassilev, ruiu, Bigcheese, efriedma Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33237 llvm-svn: 303670
2016-08-17Replace "fallthrough" comments with LLVM_FALLTHROUGHJustin Bogner1-1/+1
This is a mechanical change of comments in switches like fallthrough, fall-through, or fall-thru to use the LLVM_FALLTHROUGH macro instead. llvm-svn: 278902
2016-08-11Use the range variant of find instead of unpacking begin/endDavid Majnemer1-2/+2
If the result of the find is only used to compare against end(), just use is_contained instead. No functionality change is intended. llvm-svn: 278433
2016-04-15Option parser: class for consuming a joined arg in addition to all remaining ↵Hans Wennborg1-1/+1
args llvm-svn: 266394
2015-10-21[Option] Use an ArrayRef to store the Option Infos in OptTable. NFCCraig Topper1-7/+5
llvm-svn: 250901
2015-06-23Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC)Alexander Kornienko1-2/+2
Apparently, the style needs to be agreed upon first. llvm-svn: 240390
2015-06-22Code cleanup: Remove std::move() around xvalue (NFC)Logan Chien1-1/+1
Remove std::move() around xvalue so that copy elision is eligible. In case that copy elision is not appliable, the c++ standard also guarantees the move semantics on xvalue. Thus, it is not necessary to wrap Args with std::move. This also silence a warning since r240345. llvm-svn: 240355
2015-06-22Modify ParseArgs to return the InputArgList by value - there's no need for ↵David Blaikie1-11/+11
dynamic allocation/ownership here The one caller that does anything other than keep this variable on the stack is the single use of DerivedArgList in Clang, which is a bit more interesting but can probably be cleaned up/simplified a bit further (have DerivedArgList take ownership of the InputArgList rather than needing to reference its Args indirectly) which I'll try to after this. llvm-svn: 240345
2015-06-21ArrayRef-ify ParseArgsDavid Blaikie1-4/+3
llvm-svn: 240233