[clang] [llvm] [analyzer] Implemented a base of detecing lifetimebound annotation (PR #200145)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 02:02:57 PDT 2026


================
@@ -0,0 +1,163 @@
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/Support/raw_ostream.h"
+#include "AllocationState.h"
+#include "clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h"
+
+
+using namespace clang;
+using namespace ento;
+using namespace clang::lifetimes;
+
+REGISTER_MAP_WITH_PROGRAMSTATE(LifetimeBoundMap, SymbolRef,
+                               const MemRegion *);
+REGISTER_MAP_WITH_PROGRAMSTATE(LifetimeBoundMapVal, const MemRegion *, const MemRegion *);
+
+
+class LifetimeAnnotations : public Checker<check::PostCall, eval::Call> {
+public:
+  void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
+  void printState(raw_ostream &Out, ProgramStateRef State, const char *NL,
+                  const char *Sep) const override;
+  bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+  void analyzerLifetimeBound(const CallEvent &Call, const CallExpr *, CheckerContext &C) const;
+
+  const BugType BugMsg{this, "LifetimeAnnotations", "LifetimeBound"};
+};
+
+typedef void (LifetimeAnnotations::*FnCheck)(const CallEvent &Call, const CallExpr *,
+                                              CheckerContext &) const;
+CallDescriptionMap<FnCheck> Callbacks = {
+  {{CDM::SimpleFunc, {"clang_analyzer_lifetime_bound"}},
+    &LifetimeAnnotations::analyzerLifetimeBound},
+};
----------------
steakhal wrote:

Usually we use `usings` and just put these inside the class itself because these Callbacks should be also const.

https://github.com/llvm/llvm-project/pull/200145


More information about the cfe-commits mailing list