Index: llvm/trunk/lib/Support/CommandLine.cpp =================================================================== --- llvm/trunk/lib/Support/CommandLine.cpp +++ llvm/trunk/lib/Support/CommandLine.cpp @@ -450,7 +450,7 @@ // must be explicitly added if you want multiple categories that include it. if (&C != &GeneralCategory && Categories[0] == &GeneralCategory) Categories[0] = &C; - else + else if (find(Categories, &C) == Categories.end()) Categories.push_back(&C); } Index: llvm/trunk/unittests/Support/CommandLineTest.cpp =================================================================== --- llvm/trunk/unittests/Support/CommandLineTest.cpp +++ llvm/trunk/unittests/Support/CommandLineTest.cpp @@ -170,8 +170,12 @@ TEST(CommandLineTest, UseMultipleCategories) { StackOption TestOption2("test-option2", cl::cat(TestCategory), + cl::cat(cl::GeneralCategory), cl::cat(cl::GeneralCategory)); + // Make sure cl::GeneralCategory wasn't added twice. + ASSERT_EQ(TestOption2.Categories.size(), 2U); + ASSERT_NE(TestOption2.Categories.end(), find_if(TestOption2.Categories, [&](const llvm::cl::OptionCategory *Cat) {