[PATCH] D120992: [analyzer] ReverseNull: New checker to warn for pointer value conditions, if the pointer value is unconditionally non-null

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 4 10:30:07 PST 2022


xazax.hun added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/NullPtrInterferenceChecker.cpp:166
+/// child is a sink node.
+static bool unconditionallyLeadsHere(const ExplodedNode *N) {
+  size_t NonSinkNodeCount = llvm::count_if(
----------------
Consider the following code snippet:
```
void f(int *p, bool b)
{
  if (b) {
    *p = 4;
  }
  if (p) {
   ...
  }
}
```

I suspect that we would get a warning for the code above. I think warning on the code above might be reasonable (the values of `b` and `p` might be correlated but in some cases the analyzer has no way to know this, probably some assertions could make the code clearer in that case).

My problem is with the wording of the error message.
The warning `Pointer is unconditionally non-null here` on the null check is not true for the code above.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120992/new/

https://reviews.llvm.org/D120992



More information about the cfe-commits mailing list