[clang] [clang][analyzer] Add OpaqueSTLFunctionsModeling (PR #178910)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 2 04:31:33 PST 2026


================
@@ -0,0 +1,76 @@
+//===--- OpaqueSTLFunctionsModeling.cpp -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Forces conservative evaluation for STL internal implementation functions
+// (prefixed with '__') known to cause false positives. This prevents inlining
+// of complex STL internals and avoids wasting analysis time spent in
+// `BugReporterVisitor`s.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/ProgramPoint.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class OpaqueSTLFunctionsModeling : public Checker<eval::Call> {
+public:
+  bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+
+private:
+  bool shouldForceConservativeEval(const CallEvent &Call) const;
+};
+} // anonymous namespace
+
+bool OpaqueSTLFunctionsModeling::evalCall(const CallEvent &Call,
+                                          CheckerContext &C) const {
+  if (!shouldForceConservativeEval(Call))
+    return false;
+
+  ProgramStateRef State = C.getState();
+  State = Call.invalidateRegions(C.blockCount(), State);
+  static const SimpleProgramPointTag OpaqueCallTag{getDebugTag(),
+                                                   "Forced Opaque Call"};
+  C.addTransition(State, &OpaqueCallTag);
----------------
NagyDonat wrote:

```suggestion
  C.addTransition(State);
```
`CheckerContext::addTransition` already uses the currently active checker as a tag for the node that it creates. As this is a simple single-purpose checker whose name should clearly imply its purpose, there is no need to use an explicitly specified tag instead of this.

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


More information about the cfe-commits mailing list