Index: lib/Option/OptTable.cpp =================================================================== --- lib/Option/OptTable.cpp +++ lib/Option/OptTable.cpp @@ -277,8 +277,8 @@ continue; // Find the most appropriate prefix. For example, if a user asks for // "--helm", suggest "--help" over "-help". - StringRef Prefix; - for (int P = 0; CandidateInfo.Prefixes[P]; P++) { + StringRef Prefix = CandidateInfo.Prefixes[0]; + for (int P = 1; CandidateInfo.Prefixes[P]; P++) { if (Option.startswith(CandidateInfo.Prefixes[P])) Prefix = CandidateInfo.Prefixes[P]; } Index: unittests/Option/OptionParsingTest.cpp =================================================================== --- unittests/Option/OptionParsingTest.cpp +++ unittests/Option/OptionParsingTest.cpp @@ -283,6 +283,8 @@ EXPECT_EQ(Nearest, "-blorp"); EXPECT_EQ(1U, T.findNearest("--blorm", Nearest)); EXPECT_EQ(Nearest, "--blorp"); + EXPECT_EQ(1U, T.findNearest("-fjormp", Nearest)); + EXPECT_EQ(Nearest, "--fjormp"); // The nearest candidate respects the prefix and value delimiter // of the original string. Index: unittests/Option/Opts.td =================================================================== --- unittests/Option/Opts.td +++ unittests/Option/Opts.td @@ -34,4 +34,5 @@ def Doopf1 : Flag<["-"], "doopf1">, HelpText<"The doopf1 option">, Flags<[OptFlag1]>; def Doopf2 : Flag<["-"], "doopf2">, HelpText<"The doopf2 option">, Flags<[OptFlag2]>; def Ermgh : Joined<["--"], "ermgh">, HelpText<"The ermgh option">, MetaVarName<"ERMGH">, Flags<[OptFlag1]>; +def Fjormp : Flag<["--"], "fjormp">, HelpText<"The fjormp option">, Flags<[OptFlag1]>; def DashDash : Option<["--"], "", KIND_REMAINING_ARGS>;