Index: llvm/lib/Support/CommandLine.cpp =================================================================== --- llvm/lib/Support/CommandLine.cpp +++ llvm/lib/Support/CommandLine.cpp @@ -43,6 +43,7 @@ #include "llvm/Support/raw_ostream.h" #include #include +#include #include using namespace llvm; using namespace cl; @@ -207,6 +208,9 @@ void addOption(Option *O, SubCommand *SC) { bool HadErrors = false; if (O->hasArgStr()) { + // Guard find/insert operations to SC->OptionsMap. + std::lock_guard Lock(OptionsMapMutex); + // If it's a DefaultOption, check to make sure it isn't already there. if (O->isDefaultOption() && SC->OptionsMap.find(O->ArgStr) != SC->OptionsMap.end()) @@ -417,6 +421,7 @@ private: SubCommand *ActiveSubCommand; + std::mutex OptionsMapMutex; Option *LookupOption(SubCommand &Sub, StringRef &Arg, StringRef &Value); Option *LookupLongOption(SubCommand &Sub, StringRef &Arg, StringRef &Value,