Skip to content

Commit 4f0ad8d

Browse files
authored
[clang-tidy] support static analyzer checker configuration in --verify-config (#109523)
Previously the configuration options for the Clang Static Analyzer checkers were not recognized for the verification of the configuration with `--verify-config`. Add all available configuration options of CSA checkers as possible configuration options in a clang-tidy config.
1 parent 8789a7e commit 4f0ad8d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,18 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
672672
Buffer.append(AnalyzerCheck);
673673
Result.Names.insert(Buffer);
674674
}
675+
for (std::string OptionName : {
676+
#define GET_CHECKER_OPTIONS
677+
#define CHECKER_OPTION(TYPE, CHECKER, OPTION_NAME, DESCRIPTION, DEFAULT, \
678+
RELEASE, HIDDEN) \
679+
Twine(AnalyzerCheckNamePrefix).concat(CHECKER ":" OPTION_NAME).str(),
680+
681+
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
682+
#undef CHECKER_OPTION
683+
#undef GET_CHECKER_OPTIONS
684+
}) {
685+
Result.Options.insert(OptionName);
686+
}
675687
#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
676688

677689
Context.setOptionsCollector(&Result.Options);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ The improvements are...
9999
Improvements to clang-tidy
100100
--------------------------
101101

102+
- Improved :program:`clang-tidy`'s `--verify-config` flag by adding support for
103+
the configuration options of the `Clang Static Analyzer Checks
104+
<https://clang.llvm.org/docs/analyzer/checkers.html>`_.
105+
102106
- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
103107
happening on certain platforms when interrupting the script.
104108

clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@
3030
// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 'bugprone-arguments-*' doesn't match any known check [-verify-config]
3131
// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown check 'bugprone-assert-side-effects'; did you mean 'bugprone-assert-side-effect' [-verify-config]
3232

33+
// RUN: echo -e 'Checks: "-*,clang-analyzer-optin.cplusplus.UninitializedObject"\nCheckOptions:\n clang-analyzer-optin.cplusplus.UninitializedObject:Pedantic: true' > %T/MyClangTidyConfigCSA
34+
// RUN: clang-tidy --verify-config --config-file=%T/MyClangTidyConfigCSA 2>&1 | FileCheck %s -check-prefix=CHECK-VERIFY-CSA-OK -implicit-check-not='{{warnings|error}}'
35+
// CHECK-VERIFY-CSA-OK: No config errors detected.
36+
37+
// RUN: echo -e 'Checks: "-*,clang-analyzer-optin.cplusplus.UninitializedObject"\nCheckOptions:\n clang-analyzer-optin.cplusplus.UninitializedObject.Pedantic: true' > %T/MyClangTidyConfigCSABad
38+
// RUN: not clang-tidy --verify-config --config-file=%T/MyClangTidyConfigCSABad 2>&1 | FileCheck %s -check-prefix=CHECK-VERIFY-CSA-BAD -implicit-check-not='{{warnings|error}}'
39+
// CHECK-VERIFY-CSA-BAD: command-line option '-config': warning: unknown check option 'clang-analyzer-optin.cplusplus.UninitializedObject.Pedantic'; did you mean 'clang-analyzer-optin.cplusplus.UninitializedObject:Pedantic' [-verify-config]
40+

0 commit comments

Comments
 (0)