[PATCH] D105101: [analyzer] Make CheckerManager::hasPathSensitiveCheckers() complete again

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 29 05:04:47 PDT 2021


steakhal created this revision.
steakhal added reviewers: NoQ, vsavchenko, Szelethus, martong.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, whisperity.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It turns out that the `CheckerManager::hasPathSensitiveCheckers()` missed checking for the `BeginFunctionCheckers`.
It seems like other callbacks are also missing:

- ObjCMessageNilCheckers
- BeginFunctionCheckers
- NewAllocatorCheckers
- PointerEscapeCheckers
- EndOfTranslationUnitCheckers

In this patch, I wanted to use a fold-expression, but until C++17 arrives we are left with the old-school method.

When I tried to write a unittest I observed an interesting behavior. I subscribed only to the BeginFunction event, it was not fired.
However, when I also defined the PreCall with an empty handler, suddenly both fired.
I could add this test demonstrating the issue, but I don't think it would serve much value in a long run. I don't expect regressions for this.

However, I think it would be great to enforce the completeness of this list in a runtime check.
I could not come up with a solution for this though.

PS: Thank you @szelethus for helping me debugging this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105101

Files:
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp


Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -33,21 +33,21 @@
 using namespace ento;
 
 bool CheckerManager::hasPathSensitiveCheckers() const {
-  return !StmtCheckers.empty()              ||
-         !PreObjCMessageCheckers.empty()    ||
-         !PostObjCMessageCheckers.empty()   ||
-         !PreCallCheckers.empty()    ||
-         !PostCallCheckers.empty()   ||
-         !LocationCheckers.empty()          ||
-         !BindCheckers.empty()              ||
-         !EndAnalysisCheckers.empty()       ||
-         !EndFunctionCheckers.empty()           ||
-         !BranchConditionCheckers.empty()   ||
-         !LiveSymbolsCheckers.empty()       ||
-         !DeadSymbolsCheckers.empty()       ||
-         !RegionChangesCheckers.empty()     ||
-         !EvalAssumeCheckers.empty()        ||
-         !EvalCallCheckers.empty();
+  const auto IfAnyAreNonEmpty = [](const auto &... Callbacks) -> bool {
+    bool Result = false;
+    // FIXME: Use fold expressions in C++17.
+    int Unused[]{0, (Result |= !Callbacks.empty())...};
+    static_cast<void>(Unused);
+    return Result;
+  };
+  return IfAnyAreNonEmpty(
+      StmtCheckers, PreObjCMessageCheckers, ObjCMessageNilCheckers,
+      PostObjCMessageCheckers, PreCallCheckers, PostCallCheckers,
+      LocationCheckers, BindCheckers, EndAnalysisCheckers,
+      BeginFunctionCheckers, EndFunctionCheckers, BranchConditionCheckers,
+      NewAllocatorCheckers, LiveSymbolsCheckers, DeadSymbolsCheckers,
+      RegionChangesCheckers, PointerEscapeCheckers, EvalAssumeCheckers,
+      EvalCallCheckers, EndOfTranslationUnitCheckers);
 }
 
 void CheckerManager::finishedCheckerRegistration() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105101.355179.patch
Type: text/x-patch
Size: 1850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210629/7b033cf3/attachment-0001.bin>


More information about the cfe-commits mailing list