From 64b0924531cc113029a3b738e9a3c2091e1740b3 Mon Sep 17 00:00:00 2001 From: Don Hinton Date: Sat, 22 Jun 2019 23:32:36 +0000 Subject: Revert [CommandLine] Remove OptionCategory and SubCommand caches from the Option class. This reverts r364134 (git commit a5b83bc9e3b8e8945b55068c762bd6c73621a4b0) Caused errors in the asan bot, so the GeneralCategory global needs to be changed to ManagedStatic. Differential Revision: https://reviews.llvm.org/D62105 llvm-svn: 364141 --- llvm/lib/Support/CommandLine.cpp | 107 +++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 49 deletions(-) (limited to 'llvm/lib/Support/CommandLine.cpp') diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 20f129a4f3d..25510fa58ff 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -142,7 +142,7 @@ public: // This collects Options added with the cl::DefaultOption flag. Since they can // be overridden, they are not added to the appropriate SubCommands until // ParseCommandLineOptions actually runs. - SmallVector, 4> DefaultOptions; + SmallVector DefaultOptions; // This collects the different option categories that have been registered. SmallPtrSet RegisteredOptionCategories; @@ -182,16 +182,15 @@ public: } void addLiteralOption(Option &Opt, StringRef Name) { - for(SubCommand *SC: Opt.getSubCommands()) - addLiteralOption(Opt, SC, Name); - } - - void addOption(Option *O, SubCommand *SC, bool ProcessDefaultOptions = false) { - if (!ProcessDefaultOptions && O->isDefaultOption()) { - DefaultOptions.push_back(std::make_pair(O, SC)); - return; + if (Opt.Subs.empty()) + addLiteralOption(Opt, &*TopLevelSubCommand, Name); + else { + for (auto SC : Opt.Subs) + addLiteralOption(Opt, SC, Name); } + } + void addOption(Option *O, SubCommand *SC) { bool HadErrors = false; if (O->hasArgStr()) { // If it's a DefaultOption, check to make sure it isn't already there. @@ -233,14 +232,22 @@ public: for (const auto &Sub : RegisteredSubCommands) { if (SC == Sub) continue; - addOption(O, Sub, ProcessDefaultOptions); + addOption(O, Sub); } } } - void addDefaultOptions() { - for (std::pair