[clang] [analyzer] Add cplusplus.DestroyedAsWrongType checker (PR #237801)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 8 04:24:47 PST 2026
================
@@ -0,0 +1,366 @@
+//===- DestroyedAsWrongTypeChecker.cpp --------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines a checker that finds storage reused by placement new for an object
+// of a different type and then destroyed or deleted as the original type
+// (C++ [basic.life]p11, [expr.delete]p3).
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/ExprCXX.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/Support/FormatVariadic.h"
+#include <optional>
----------------
steakhal wrote:
I didn't really look much but I'm surprised to see that the DynamicType trait header is not included.
I figured that already tracks the dynamic type of some storage. That is also used for devirtualizing calls I think, and/or also used for modeling the success or failure of dynamic-casts. I figured at glance that this is fairly similar to what this checker wants to model in some sense.
So I wonder, have you considered using that, and how would this checker fit into the existing uses of the DynamicType trait?
https://github.com/llvm/llvm-project/pull/237801
More information about the cfe-commits
mailing list