summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2014-02-07 17:42:30 +0000
committerAlexander Kornienko <alexfh@google.com>2014-02-07 17:42:30 +0000
commit11b8b431964b870e3021a8eca8bf1d870a58f474 (patch)
tree8fe83597520c14a0c77819f6e2c87d104d013541
parent24e5f9652aff7fc28bb3855d12e9d7506b384ad6 (diff)
downloadllvm-11b8b431964b870e3021a8eca8bf1d870a58f474.tar.gz
llvm-11b8b431964b870e3021a8eca8bf1d870a58f474.tar.bz2
llvm-11b8b431964b870e3021a8eca8bf1d870a58f474.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200981 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/CommandLine.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index 16db4d6396..7b2a4d0270 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -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!");