[llvm] r200981 - Fix an invalid check for duplicate option categories.
Alexander Kornienko
alexfh at google.com
Fri Feb 7 09:42:30 PST 2014
Author: alexfh
Date: Fri Feb 7 11:42:30 2014
New Revision: 200981
URL: http://llvm.org/viewvc/llvm-project?rev=200981&view=rev
Log:
Fix an invalid check for duplicate option categories.
An intermediate solution until the problems with analyzer plugins linking with
llvm/Support and causing assertions due to duplicate GeneralCategory are solved.
Modified:
llvm/trunk/lib/Support/CommandLine.cpp
Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=200981&r1=200980&r2=200981&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Fri Feb 7 11:42:30 2014
@@ -36,6 +36,7 @@
#include <cerrno>
#include <cstdlib>
#include <map>
+#include <set>
using namespace llvm;
using namespace cl;
@@ -1495,9 +1496,7 @@ public:
// It shall return true if A's name should be lexographically
// ordered before B's name. It returns false otherwise.
static bool OptionCategoryCompare(OptionCategory *A, OptionCategory *B) {
- int Length = strcmp(A->getName(), B->getName());
- assert(Length != 0 && "Duplicate option categories");
- return Length < 0;
+ return strcmp(A->getName(), B->getName()) < 0;
}
// Make sure we inherit our base class's operator=()
@@ -1507,13 +1506,20 @@ protected:
virtual void printOptions(StrOptionPairVector &Opts, size_t MaxArgLen) {
std::vector<OptionCategory *> SortedCategories;
std::map<OptionCategory *, std::vector<Option *> > CategorizedOptions;
+ std::set<std::string> CategoryNames;
// Collect registered option categories into vector in preparation for
// sorting.
for (OptionCatSet::const_iterator I = RegisteredOptionCategories->begin(),
E = RegisteredOptionCategories->end();
- I != E; ++I)
+ I != E; ++I) {
SortedCategories.push_back(*I);
+ // FIXME: Move this check to OptionCategory::registerCategory after the
+ // problem with analyzer plugins linking to llvm/Support and causing
+ // assertion on the duplicate llvm::cl::GeneralCategory is solved.
+ assert(CategoryNames.insert((*I)->getName()).second &&
+ "Duplicate option categories");
+ }
// Sort the different option categories alphabetically.
assert(SortedCategories.size() > 0 && "No option categories registered!");
More information about the llvm-commits
mailing list