diff options
author | Alexander Kornienko <alexfh@google.com> | 2014-02-05 16:56:37 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2014-02-05 16:56:37 +0000 |
commit | e88421b6f70ebc33e8405a95de29ba4756731449 (patch) | |
tree | 26eb05034345c21b826cfa88603693a36bb8f7bf /llvm/lib/Support/CommandLine.cpp | |
parent | f387387835f9f96db2924aae695b20fcf825ded5 (diff) | |
download | bcm5719-llvm-e88421b6f70ebc33e8405a95de29ba4756731449.tar.gz bcm5719-llvm-e88421b6f70ebc33e8405a95de29ba4756731449.zip |
Fix an invalid check for duplicate option categories.
Summary:
The check performed in the comparator is invalid, as some STL
implementations enforce strict weak ordering by calling the comparator with the
same value. This check was also in a wrong place: the assertion would only fire
when -help was used. The new check is performed each time the category is
registered (we are not going to have thousands of them, so it's fine to do it in
O(N^2)).
Reviewers: jordan_rose
Reviewed By: jordan_rose
CC: cfe-commits, alexmc
Differential Revision: http://llvm-reviews.chandlerc.com/D2699
llvm-svn: 200853
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 16db4d63960..289bb87433f 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -125,8 +125,21 @@ static ManagedStatic<OptionCatSet> RegisteredOptionCategories; // Initialise the general option category. OptionCategory llvm::cl::GeneralCategory("General options"); +struct HasName { + HasName(StringRef Name) : Name(Name) {} + bool operator()(const OptionCategory *Category) const { + return Name == Category->getName(); + } + StringRef Name; +}; + void OptionCategory::registerCategory() { + assert(std::count_if(RegisteredOptionCategories->begin(), + RegisteredOptionCategories->end(), + HasName(getName())) == 0 && + "Duplicate option categories"); + RegisteredOptionCategories->insert(this); } @@ -1495,9 +1508,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=() |