[PATCH] D142744: Re-analyze functions as top-level

Christopher Bazley via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 27 09:06:03 PST 2023


chrisbazley created this revision.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
chrisbazley requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If a function with a _Nullable parameter has at least
one caller, the checker behaves as though no other
parameter value is possible. This is because the static
analyzer doesn't re-analyse functions as top level
(with the exception of C++ copy and move operators, and
ObjC methods).

Fixed by modifying shouldSkipFunction to return false.

After this change, Clang-tidy even emits different
warnings for the same line of code, if appropriate:
"Nullable pointer is dereferenced" for a (simulated)
top-level call and "Dereference of null pointer"
for a call to the same function with a known null value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142744

Files:
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -408,6 +408,12 @@
   //   Count naming convention errors more aggressively.
   if (isa<ObjCMethodDecl>(D))
     return false;
+
+  // If a function with a _Nullable parameter has at least one caller, the
+  // checker behaves as though no other parameter value is possible. This is
+  // because the static analyzer doesn't re-analyse functions as top level.
+  return false;
+
   // We also want to reanalyze all C++ copy and move assignment operators to
   // separately check the two cases where 'this' aliases with the parameter and
   // where it may not. (cplusplus.SelfAssignmentChecker)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142744.492795.patch
Type: text/x-patch
Size: 846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230127/ebf64062/attachment.bin>


More information about the cfe-commits mailing list