[llvm] r202404 - Re-apply r200853, which should not crash after Clang plugins were converted to loadable modules in r201256.
Alexander Kornienko
alexfh at google.com
Thu Feb 27 06:47:37 PST 2014
Author: alexfh
Date: Thu Feb 27 08:47:37 2014
New Revision: 202404
URL: http://llvm.org/viewvc/llvm-project?rev=202404&view=rev
Log:
Re-apply r200853, which should not crash after Clang plugins were converted to loadable modules in r201256.
Modified:
llvm/trunk/include/llvm/Support/CommandLine.h
llvm/trunk/lib/Support/CommandLine.cpp
Modified: llvm/trunk/include/llvm/Support/CommandLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CommandLine.h?rev=202404&r1=202403&r2=202404&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CommandLine.h (original)
+++ llvm/trunk/include/llvm/Support/CommandLine.h Thu Feb 27 08:47:37 2014
@@ -149,8 +149,8 @@ private:
public:
OptionCategory(const char *const Name, const char *const Description = 0)
: Name(Name), Description(Description) { registerCategory(); }
- const char *getName() { return Name; }
- const char *getDescription() { return Description; }
+ const char *getName() const { return Name; }
+ const char *getDescription() const { return Description; }
};
// The general Option Category (used as default category).
Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=202404&r1=202403&r2=202404&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Thu Feb 27 08:47:37 2014
@@ -36,7 +36,6 @@
#include <cerrno>
#include <cstdlib>
#include <map>
-#include <set>
using namespace llvm;
using namespace cl;
@@ -126,8 +125,21 @@ static ManagedStatic<OptionCatSet> Regis
// 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);
}
@@ -1506,7 +1518,6 @@ 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.
@@ -1514,11 +1525,6 @@ protected:
E = RegisteredOptionCategories->end();
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.
More information about the llvm-commits
mailing list