Index: llvm/include/llvm/Option/ArgList.h =================================================================== --- llvm/include/llvm/Option/ArgList.h +++ llvm/include/llvm/Option/ArgList.h @@ -419,6 +419,8 @@ NumInputArgStrings(RHS.NumInputArgStrings) {} InputArgList &operator=(InputArgList &&RHS) { + if (this == &RHS) + return *this; releaseMemory(); ArgList::operator=(std::move(RHS)); ArgStrings = std::move(RHS.ArgStrings); Index: llvm/unittests/Option/OptionParsingTest.cpp =================================================================== --- llvm/unittests/Option/OptionParsingTest.cpp +++ llvm/unittests/Option/OptionParsingTest.cpp @@ -238,6 +238,23 @@ EXPECT_TRUE(AL.hasArg(OPT_B)); } +TYPED_TEST(OptTableTest, InputArgListSelfAssign) { + TypeParam T; + unsigned MAI, MAC; + InputArgList AL = T.ParseArgs(Args, MAI, MAC, + /*FlagsToInclude=*/0, + /*FlagsToExclude=*/OptFlag3); + EXPECT_TRUE(AL.hasArg(OPT_A)); + EXPECT_TRUE(AL.hasArg(OPT_C)); + EXPECT_FALSE(AL.hasArg(OPT_SLASH_C)); + + AL = std::move(AL); + + EXPECT_TRUE(AL.hasArg(OPT_A)); + EXPECT_TRUE(AL.hasArg(OPT_C)); + EXPECT_FALSE(AL.hasArg(OPT_SLASH_C)); +} + TYPED_TEST(OptTableTest, DoNotIgnoreCase) { TypeParam T; unsigned MAI, MAC;