Repository: llvm/llvm-project
File: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (C/C++)

Code before:
  unsigned NoRetryExhausted : 1;

  /// Emit analyzer warnings as errors.
  LLVM_PREFERRED_TYPE(bool)
  unsigned AnalyzerWerror : 1;

  /// The inlining stack depth limit.
  unsigned InlineMaxStackDepth;

  /// The mode of function selection used during inlining.
  AnalysisInliningMode InliningMode = NoRedundancy;

  // Create a field for each -analyzer-config option.
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,        \
                                             SHALLOW_VAL, DEEP_VAL)            \
  ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL)

#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)                \
  TYPE NAME;

#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
#undef ANALYZER_OPTION
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE

  bool isUnknownAnalyzerConfig(llvm::StringRef Name) {
    static const std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags =
        []() {
          // Create an array of all -analyzer-config command line options.
          std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags = {
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,        \
                                             SHALLOW_VAL, DEEP_VAL)            \
  ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL)

#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)                \
  llvm::StringLiteral(CMDFLAG),

#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
#undef ANALYZER_OPTION
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
          };
          // FIXME: Sort this at compile-time when we get constexpr sort
          // (C++20).
          llvm::sort(AnalyzerConfigCmdFlags);
          return AnalyzerConfigCmdFlags;
        }();

    return !llvm::binary_search(AnalyzerConfigCmdFlags, Name);
  }

  AnalyzerOptions()
      : DisableAllCheckers(false), ShowCheckerHelp(false),

Review comment (performance):
I wonder if we could reduce the complexity here and just use a C-style array of StringLiterals. Could you simplify this?

BTW It looks correct, so if you don't want to go the extra mile, that's also fine.

Code after:
  unsigned NoRetryExhausted : 1;

  /// Emit analyzer warnings as errors.
  LLVM_PREFERRED_TYPE(bool)
  unsigned AnalyzerWerror : 1;

  /// The inlining stack depth limit.
  unsigned InlineMaxStackDepth;

  /// The mode of function selection used during inlining.
  AnalysisInliningMode InliningMode = NoRedundancy;

  // Create a field for each -analyzer-config option.
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,        \
                                             SHALLOW_VAL, DEEP_VAL)            \
  ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL)

#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)                \
  TYPE NAME;

#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
#undef ANALYZER_OPTION
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE

  bool isUnknownAnalyzerConfig(llvm::StringRef Name) {
    static const auto AnalyzerConfigCmdFlags = []() {
      // Create an array of all -analyzer-config command line options.
      std::array AnalyzerConfigCmdFlags{
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,        \
                                             SHALLOW_VAL, DEEP_VAL)            \
  ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL)

#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)                \
  llvm::StringLiteral(CMDFLAG),

#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
#undef ANALYZER_OPTION
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
      };
      // FIXME: Sort this at compile-time when we get constexpr sort (C++20).
      llvm::sort(AnalyzerConfigCmdFlags);
      return AnalyzerConfigCmdFlags;
    }();

    return !llvm::binary_search(AnalyzerConfigCmdFlags, Name);
  }

  AnalyzerOptions()
      : DisableAllCheckers(false), ShowCheckerHelp(false),
        ShowCheckerHelpAlpha(false), ShowCheckerHelpDeveloper(false),
        ShowCheckerOptionList(false), ShowCheckerOptionAlphaList(false),