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)


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)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D142744: Re-ana... Christopher Bazley via Phabricator via cfe-commits

Reply via email to