<div dir="ltr"><pre style="color:rgb(0,0,0)">Here's the alternative patch:</pre><pre style="color:rgb(0,0,0)"><br></pre><pre style="color:rgb(0,0,0)">Index: lib/Support/CommandLine.cpp
===================================================================
--- lib/Support/CommandLine.cpp (revision 200882)
+++ lib/Support/CommandLine.cpp (working copy)
@@ -36,6 +36,7 @@
 #include <cerrno>
 #include <cstdlib>
 #include <map>
+#include <set>
 using namespace llvm;
 using namespace cl;
 
@@ -1495,9 +1496,7 @@
   // 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,17 @@
   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);
+      assert(CategoryNames.insert((*I)->getName()).second &&
+             "Duplicate option categories");
+    }
 
     // Sort the different option categories alphabetically.
     assert(SortedCategories.size() > 0 && "No option categories registered!");</pre><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 5, 2014 at 11:49 PM, Alexander Kornienko <span dir="ltr"><<a href="mailto:alexfh@google.com" target="_blank">alexfh@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Jordan,<div><br></div><div>I guess, you know something about analyzer plugins ;)</div><div><br></div><div>
We have a problem here, which this patch just reveals. The analyzer plugin links with the llvm/Support library, and it has the second copy of all the global variables defined in llvm/Support- the first one is in the clang binary - in particular llvm::cl::GeneralCategory. As the patch in r200853 performs the check for duplicate option categories during the registration, this leads to a crash.</div>

<div><br></div><div>I'm not sure what a proper solution would look like. Avoiding global variables or avoiding linking plugins with llvm/clang libraries would certainly solve the problem ;), but would require non-trivial effort. I can implement a correct check, and leave it only when printing the help message. It doesn't seem completely right, but solves both crashes.</div>
<div><div class="h5">
<div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 5, 2014 at 6:49 PM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: rafael<br>
Date: Wed Feb  5 11:49:31 2014<br>
New Revision: 200858<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=200858&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=200858&view=rev</a><br>
Log:<br>
Revert "Fix an invalid check for duplicate option categories."<br>
<br>
This reverts commit r200853.<br>
<br>
It was causing clang/Analysis/checker-plugins.c to crash.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/CommandLine.h<br>
    llvm/trunk/lib/Support/CommandLine.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Support/CommandLine.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CommandLine.h?rev=200858&r1=200857&r2=200858&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CommandLine.h?rev=200858&r1=200857&r2=200858&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/include/llvm/Support/CommandLine.h (original)<br>
+++ llvm/trunk/include/llvm/Support/CommandLine.h Wed Feb  5 11:49:31 2014<br>
@@ -149,8 +149,8 @@ private:<br>
 public:<br>
   OptionCategory(const char *const Name, const char *const Description = 0)<br>
       : Name(Name), Description(Description) { registerCategory(); }<br>
-  const char *getName() const { return Name; }<br>
-  const char *getDescription() const { return Description; }<br>
+  const char *getName() { return Name; }<br>
+  const char *getDescription() { return Description; }<br>
 };<br>
<br>
 // The general Option Category (used as default category).<br>
<br>
Modified: llvm/trunk/lib/Support/CommandLine.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=200858&r1=200857&r2=200858&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=200858&r1=200857&r2=200858&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/Support/CommandLine.cpp (original)<br>
+++ llvm/trunk/lib/Support/CommandLine.cpp Wed Feb  5 11:49:31 2014<br>
@@ -125,21 +125,8 @@ static ManagedStatic<OptionCatSet> Regis<br>
 // Initialise the general option category.<br>
 OptionCategory llvm::cl::GeneralCategory("General options");<br>
<br>
-struct HasName {<br>
-  HasName(StringRef Name) : Name(Name) {}<br>
-  bool operator()(const OptionCategory *Category) const {<br>
-    return Name == Category->getName();<br>
-  }<br>
-  StringRef Name;<br>
-};<br>
-<br>
 void OptionCategory::registerCategory()<br>
 {<br>
-  assert(std::count_if(RegisteredOptionCategories->begin(),<br>
-                       RegisteredOptionCategories->end(),<br>
-                       HasName(getName())) == 0 &&<br>
-         "Duplicate option categories");<br>
-<br>
   RegisteredOptionCategories->insert(this);<br>
 }<br>
<br>
@@ -1508,7 +1495,9 @@ public:<br>
   // It shall return true if A's name should be lexographically<br>
   // ordered before B's name. It returns false otherwise.<br>
   static bool OptionCategoryCompare(OptionCategory *A, OptionCategory *B) {<br>
-    return strcmp(A->getName(), B->getName()) < 0;<br>
+    int Length = strcmp(A->getName(), B->getName());<br>
+    assert(Length != 0 && "Duplicate option categories");<br>
+    return Length < 0;<br>
   }<br>
<br>
   // Make sure we inherit our base class's operator=()<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div></div></div></div></blockquote></div><br>
</div></div>