Skip to content

Commit b041a58

Browse files
authored
[clang-tidy][NFC] concat static-analyzer name at compilation time (#147406)
```cpp for (std::string OptionName : { #define GET_CHECKER_OPTIONS #define CHECKER_OPTION(TYPE, CHECKER, OPTION_NAME, DESCRIPTION, DEFAULT, \ RELEASE, HIDDEN) \ Twine(AnalyzerCheckNamePrefix).concat(CHECKER ":" OPTION_NAME).str(), #include "clang/StaticAnalyzer/Checkers/Checkers.inc" #undef CHECKER_OPTION #undef GET_CHECKER_OPTIONS }) { Result.Options.insert(OptionName); } ``` This code is doing a lot of unnecessary work at runtime. For each of the (currently) 59 checker options, it runs `Twine(AnalyzerCheckNamePrefix).concat(CHECKER ":" OPTION_NAME).str(),`, which allocates a string (all of this is unrolled, leading to code bloat). Then it copies all those strings (because `std::string OptionName`, not `const std::string& OptionName`). All of this can be done at compile time!
1 parent 62e537a commit b041a58

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ namespace clang::tidy {
5555

5656
namespace {
5757
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
58+
#define ANALYZER_CHECK_NAME_PREFIX "clang-analyzer-"
5859
static constexpr llvm::StringLiteral AnalyzerCheckNamePrefix =
59-
"clang-analyzer-";
60+
ANALYZER_CHECK_NAME_PREFIX;
6061

6162
class AnalyzerDiagnosticConsumer : public ento::PathDiagnosticConsumer {
6263
public:
@@ -669,18 +670,19 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
669670
Buffer.append(AnalyzerCheck);
670671
Result.Checks.insert(Buffer);
671672
}
672-
for (std::string OptionName : {
673+
674+
static constexpr llvm::StringLiteral OptionNames[] = {
673675
#define GET_CHECKER_OPTIONS
674676
#define CHECKER_OPTION(TYPE, CHECKER, OPTION_NAME, DESCRIPTION, DEFAULT, \
675677
RELEASE, HIDDEN) \
676-
Twine(AnalyzerCheckNamePrefix).concat(CHECKER ":" OPTION_NAME).str(),
678+
ANALYZER_CHECK_NAME_PREFIX CHECKER ":" OPTION_NAME,
677679

678680
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
679681
#undef CHECKER_OPTION
680682
#undef GET_CHECKER_OPTIONS
681-
}) {
682-
Result.Options.insert(OptionName);
683-
}
683+
};
684+
685+
Result.Options.insert_range(OptionNames);
684686
#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
685687

686688
Context.setOptionsCollector(&Result.Options);

0 commit comments

Comments
 (0)