diff options
| author | Brian Gesiak <modocache@gmail.com> | 2018-05-14 22:36:47 +0000 |
|---|---|---|
| committer | Brian Gesiak <modocache@gmail.com> | 2018-05-14 22:36:47 +0000 |
| commit | ed5b3255f00ac938aba1d58ad05bd83738f5a608 (patch) | |
| tree | fef839051191c4652d3a602e8960d6dbe44527d3 /llvm/lib/Option | |
| parent | c19843714c5a8bbd9d28302daf8364c0a7ff12f9 (diff) | |
| download | bcm5719-llvm-ed5b3255f00ac938aba1d58ad05bd83738f5a608.tar.gz bcm5719-llvm-ed5b3255f00ac938aba1d58ad05bd83738f5a608.zip | |
Revert "[Option] Fix PR37006 prefix choice in findNearest"
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
Diffstat (limited to 'llvm/lib/Option')
| -rw-r--r-- | llvm/lib/Option/OptTable.cpp | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index 293b6e54e21..022b9d5d933 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -252,33 +252,38 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString, unsigned MinimumLength) const { assert(!Option.empty()); - // Consider each [option prefix + option name] pair as a candidate, finding - // the closest match. + // Consider each option as a candidate, finding the closest match. unsigned BestDistance = UINT_MAX; for (const Info &CandidateInfo : ArrayRef<Info>(OptionInfos).drop_front(FirstSearchableIndex)) { StringRef CandidateName = CandidateInfo.Name; - // We can eliminate some option prefix/name pairs as candidates right away: - // * Ignore option candidates with empty names, such as "--", or names - // that do not meet the minimum length. + // Ignore option candidates with empty names, such as "--", or names + // that do not meet the minimum length. if (CandidateName.empty() || CandidateName.size() < MinimumLength) continue; - // * If FlagsToInclude were specified, ignore options that don't include - // those flags. + // If FlagsToInclude were specified, ignore options that don't include + // those flags. if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude)) continue; - // * Ignore options that contain the FlagsToExclude. + // Ignore options that contain the FlagsToExclude. if (CandidateInfo.Flags & FlagsToExclude) continue; - // * Ignore positional argument option candidates (which do not - // have prefixes). + // Ignore positional argument option candidates (which do not + // have prefixes). if (!CandidateInfo.Prefixes) continue; + // Find the most appropriate prefix. For example, if a user asks for + // "--helm", suggest "--help" over "-help". + StringRef Prefix = CandidateInfo.Prefixes[0]; + for (int P = 1; CandidateInfo.Prefixes[P]; P++) { + if (Option.startswith(CandidateInfo.Prefixes[P])) + Prefix = CandidateInfo.Prefixes[P]; + } - // Now check if the candidate ends with a character commonly used when + // Check if the candidate ends with a character commonly used when // delimiting an option from its value, such as '=' or ':'. If it does, // attempt to split the given option based on that delimiter. std::string Delimiter = ""; @@ -292,19 +297,14 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString, else std::tie(LHS, RHS) = Option.split(Last); - // Consider each possible prefix for each candidate to find the most - // appropriate one. For example, if a user asks for "--helm", suggest - // "--help" over "-help". - for (int P = 0; const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) { - std::string NormalizedName = (LHS + Delimiter).str(); - StringRef Candidate = (CandidatePrefix + CandidateName).str(); - unsigned Distance = - Candidate.edit_distance(NormalizedName, /*AllowReplacements=*/true, - /*MaxEditDistance=*/BestDistance); - if (Distance < BestDistance) { - BestDistance = Distance; - NearestString = (Candidate + RHS).str(); - } + std::string NormalizedName = + (LHS.drop_front(Prefix.size()) + Delimiter).str(); + unsigned Distance = + CandidateName.edit_distance(NormalizedName, /*AllowReplacements=*/true, + /*MaxEditDistance=*/BestDistance); + if (Distance < BestDistance) { + BestDistance = Distance; + NearestString = (Prefix + CandidateName + RHS).str(); } } return BestDistance; |

