diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4252,7 +4252,7 @@ def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option,FlangOption,FC1Option]>, Group, HelpText<"Language standard to compile for">, ValuesCode<[{ - const char *Values = + static constexpr const char VALUES_CODE [] = #define LANGSTANDARD(id, name, lang, desc, features) name "," #define LANGSTANDARD_ALIAS(id, alias) alias "," #include "clang/Basic/LangStandards.def" @@ -5263,7 +5263,7 @@ def analyzer_checker : Separate<["-"], "analyzer-checker">, HelpText<"Choose analyzer checkers to enable">, ValuesCode<[{ - const char *Values = + static constexpr const char VALUES_CODE [] = #define GET_CHECKERS #define CHECKER(FULLNAME, CLASS, HT, DOC_URI, IS_HIDDEN) FULLNAME "," #include "clang/StaticAnalyzer/Checkers/Checkers.inc" diff --git a/clang/lib/Driver/DriverOptions.cpp b/clang/lib/Driver/DriverOptions.cpp --- a/clang/lib/Driver/DriverOptions.cpp +++ b/clang/lib/Driver/DriverOptions.cpp @@ -16,6 +16,10 @@ using namespace clang::driver::options; using namespace llvm::opt; +#define OPTTABLE_VALUES_CODE +#include "clang/Driver/Options.inc" +#undef OPTTABLE_VALUES_CODE + #define PREFIX(NAME, VALUE) \ static constexpr llvm::StringLiteral NAME##_init[] = VALUE; \ static constexpr llvm::ArrayRef NAME( \ @@ -43,16 +47,6 @@ } const llvm::opt::OptTable &clang::driver::getDriverOptTable() { - static const DriverOptTable *Table = []() { - auto Result = std::make_unique(); - // Options.inc is included in DriverOptions.cpp, and calls OptTable's - // addValues function. - // Opt is a variable used in the code fragment in Options.inc. - OptTable &Opt = *Result; -#define OPTTABLE_ARG_INIT -#include "clang/Driver/Options.inc" -#undef OPTTABLE_ARG_INIT - return Result.release(); - }(); - return *Table; + static DriverOptTable Table; + return Table; } diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h --- a/llvm/include/llvm/Option/OptTable.h +++ b/llvm/include/llvm/Option/OptTable.h @@ -60,7 +60,7 @@ private: /// The option information table. - std::vector OptionInfos; + ArrayRef OptionInfos; bool IgnoreCase; bool GroupedShortOptions = false; const char *EnvVar = nullptr; @@ -174,17 +174,6 @@ unsigned FlagsToInclude = 0, unsigned FlagsToExclude = 0, unsigned MinimumLength = 4) const; - /// Add Values to Option's Values class - /// - /// \param [in] Option - Prefix + Name of the flag which Values will be - /// changed. For example, "-analyzer-checker". - /// \param [in] Values - String of Values seperated by ",", such as - /// "foo, bar..", where foo and bar is the argument which the Option flag - /// takes - /// - /// \return true in success, and false in fail. - bool addValues(StringRef Option, const char *Values); - /// Parse a single argument; returning the new argument and /// updating Index. /// diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -300,17 +300,6 @@ return BestDistance; } -bool OptTable::addValues(StringRef Option, const char *Values) { - for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) { - Info &In = OptionInfos[I]; - if (optionMatches(In, Option)) { - In.Values = Values; - return true; - } - } - return false; -} - // Parse a single argument, return the new argument, and update Index. If // GroupedShortOptions is true, -a matches "-abc" and the argument in Args will // be updated to "-bc". This overload does not support diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp --- a/llvm/utils/TableGen/OptParserEmitter.cpp +++ b/llvm/utils/TableGen/OptParserEmitter.cpp @@ -259,6 +259,21 @@ OS << "#undef COMMA\n"; OS << "#endif // PREFIX\n\n"; + OS << "/////////\n"; + OS << "// ValuesCode\n\n"; + OS << "#ifdef OPTTABLE_VALUES_CODE\n"; + for (const Record &R : llvm::make_pointee_range(Opts)) { + // The option values, if any; + if (!isa(R.getValueInit("ValuesCode"))) { + assert(isa(R.getValueInit("Values")) && + "Cannot choose between Values and ValuesCode"); + OS << "#define VALUES_CODE " << getOptionName(R) << "_Values\n"; + OS << R.getValueAsString("ValuesCode") << "\n"; + OS << "#undef VALUES_CODE\n"; + } + } + OS << "#endif\n"; + OS << "/////////\n"; OS << "// Groups\n\n"; OS << "#ifdef OPTION\n"; @@ -388,6 +403,9 @@ OS << ", "; if (!isa(R.getValueInit("Values"))) write_cstring(OS, R.getValueAsString("Values")); + else if (!isa(R.getValueInit("ValuesCode"))) { + OS << getOptionName(R) << "_Values"; + } else OS << "nullptr"; }; @@ -460,29 +478,5 @@ OS << "\n"; OS << "\n"; - OS << "#ifdef OPTTABLE_ARG_INIT\n"; - OS << "//////////\n"; - OS << "// Option Values\n\n"; - for (const Record &R : llvm::make_pointee_range(Opts)) { - if (isa(R.getValueInit("ValuesCode"))) - continue; - OS << "{\n"; - OS << "bool ValuesWereAdded;\n"; - OS << R.getValueAsString("ValuesCode"); - OS << "\n"; - for (StringRef Prefix : R.getValueAsListOfStrings("Prefixes")) { - OS << "ValuesWereAdded = Opt.addValues("; - std::string S(Prefix); - S += R.getValueAsString("Name"); - write_cstring(OS, S); - OS << ", Values);\n"; - OS << "(void)ValuesWereAdded;\n"; - OS << "assert(ValuesWereAdded && \"Couldn't add values to " - "OptTable!\");\n"; - } - OS << "}\n"; - } - OS << "\n"; - OS << "#endif // OPTTABLE_ARG_INIT\n"; } } // end namespace llvm