llvm.org GIT mirror llvm / 375079a
Option parsing: properly handle flag aliases for joined options (PR23394) A joined option always needs to have an argument, even if it's an empty one. Clang would previously assert when trying to use --extra-warnings, which is a flag alias for -W, which is a joined option. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236434 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
3 changed file(s) with 21 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
124124 Val += strlen(Val) + 1;
125125 }
126126 }
127
128 if (UnaliasedOption.getKind() == JoinedClass && !getAliasArgs())
129 // A Flag alias for a Joined option must provide an argument.
130 A->getValues().push_back("");
131
127132 return A;
128133 }
129134 case JoinedClass: {
208208 EXPECT_EQ(AL->getAllArgValues(OPT_Slurp)[1], "--");
209209 EXPECT_EQ(AL->getAllArgValues(OPT_Slurp)[2], "foo");
210210 }
211
212 TEST(Option, FlagAliasToJoined) {
213 TestOptTable T;
214 unsigned MAI, MAC;
215
216 // Check that a flag alias provides an empty argument to a joined option.
217 const char *MyArgs[] = { "-K" };
218 std::unique_ptr AL(
219 T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
220 EXPECT_EQ(AL->size(), 1U);
221 EXPECT_TRUE(AL->hasArg(OPT_B));
222 EXPECT_EQ(AL->getAllArgValues(OPT_B).size(), 1U);
223 EXPECT_EQ(AL->getAllArgValues(OPT_B)[0], "");
224 }
2222 def J : Flag<["-"], "J">, Alias, AliasArgs<["foo"]>;
2323 def Joo : Flag<["-"], "Joo">, Alias, AliasArgs<["bar"]>;
2424
25 def K : Flag<["-"], "K">, Alias;
26
2527 def Slurp : Option<["-"], "slurp", KIND_REMAINING_ARGS>;