[clang] [clang-tools-extra] [clang-tidy][dataflow] Add `bugprone-null-check-after-dereference` check (PR #84166)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 18:44:54 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE LINT COMMENT: clang-tidy-->
:warning: C/C++ code linter, clang-tidy found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
```bash
git diff -U0 origin/main...HEAD -- clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.h clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp |
python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py -path build -p1 -quiet
```
</details>
<details>
<summary>
View the output from clang-tidy here.
</summary>
```
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:16:1: warning: #includes are not sorted properly [llvm-include-order]
note: this fix will not be applied because it overlaps with another fix
16 | #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
| ^
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:18:1: warning: included header DataflowLattice.h is not used directly [misc-include-cleaner]
18 | #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 | #include "clang/Analysis/FlowSensitive/Models/NullPointerAnalysisModel.h"
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:22:1: warning: included header Any.h is not used directly [misc-include-cleaner]
22 | #include "llvm/ADT/Any.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~
23 | #include "llvm/ADT/STLExtras.h"
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:27:1: warning: included header vector is not used directly [misc-include-cleaner]
27 | #include <vector>
| ^~~~~~~~~~~~~~~~~
28 |
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:38:8: warning: struct 'ExpandedResult' can be moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
38 | struct ExpandedResult {
| ^
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:64:3: warning: variable 'Env' of type 'dataflow::Environment' can be declared 'const' [misc-const-correctness]
64 | dataflow::Environment Env(AnalysisContext, FuncDecl);
| ^
| const
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:83:25: warning: 'auto Val' can be declared as 'const auto *Val' [llvm-qualified-auto]
83 | if (auto Val = Diagnoser.WarningLocToVal[Entry.Location];
| ^~~~
| const auto *
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:84:25: warning: 'auto DerefExpr' can be declared as 'const auto *DerefExpr' [llvm-qualified-auto]
84 | auto DerefExpr = Diagnoser.ValToDerefLoc[Val]) {
| ^~~~
| const auto *
clang-tools-extra/clang-tidy/bugprone/NullCheckAfterDereferenceCheck.cpp:97:8: warning: invalid case style for variable 'containsPointerValue' [readability-identifier-naming]
97 | auto containsPointerValue =
| ^~~~~~~~~~~~~~~~~~~~
| ContainsPointerValue
98 | hasDescendant(NullPointerAnalysisModel::ptrValueMatcher());
99 | Finder->addMatcher(
100 | decl(anyOf(functionDecl(unless(isExpansionInSystemHeader()),
101 | // FIXME: Remove the filter below when lambdas are
102 | // well supported by the check.
103 | unless(hasDeclContext(cxxRecordDecl(isLambda()))),
104 | hasBody(containsPointerValue)),
| ~~~~~~~~~~~~~~~~~~~~
| ContainsPointerValue
105 | cxxConstructorDecl(
106 | unless(hasDeclContext(cxxRecordDecl(isLambda()))),
107 | hasAnyConstructorInitializer(
108 | withInitializer(containsPointerValue)))))
| ~~~~~~~~~~~~~~~~~~~~
| ContainsPointerValue
```
</details>
https://github.com/llvm/llvm-project/pull/84166
More information about the cfe-commits
mailing list