[clang] [clang][analyzer] Add support for detecting uninitialized dynamically-allocated objects (PR #193001)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 21 06:03:21 PDT 2026
================
@@ -451,26 +451,44 @@ static void printTail(llvm::raw_ostream &Out,
// Utility functions.
//===----------------------------------------------------------------------===//
+static const SubRegion *
+getConstructedSubRegion(const CXXConstructorDecl *CtorDecl,
+ CheckerContext &Context) {
+ Loc ThisLoc =
+ Context.getSValBuilder().getCXXThis(CtorDecl, Context.getStackFrame());
+ SVal ObjectV = Context.getState()->getSVal(ThisLoc);
+ return ObjectV.getAsRegion()->getAs<SubRegion>();
+}
+
static const TypedValueRegion *
getConstructedRegion(const CXXConstructorDecl *CtorDecl,
CheckerContext &Context) {
- Loc ThisLoc =
- Context.getSValBuilder().getCXXThis(CtorDecl, Context.getStackFrame());
+ const SubRegion *SR = getConstructedSubRegion(CtorDecl, Context);
+ if (!SR)
+ return nullptr;
- SVal ObjectV = Context.getState()->getSVal(ThisLoc);
+ if (const auto *TVR = SR->getAs<TypedValueRegion>()) {
+ return TVR->getValueType()->getAsCXXRecordDecl() ? TVR : nullptr;
+ }
- auto *R = ObjectV.getAsRegion()->getAs<TypedValueRegion>();
- if (R && !R->getValueType()->getAsCXXRecordDecl())
+ QualType DynType = CtorDecl->getThisType()->getPointeeType();
----------------
steakhal wrote:
I think the `DynType` would suggest to the reader that it has something to do with dynamic type.
However, the pointee of "this" is still a static type. Maybe `ThisTy` or `ThisPointeeTy` would be a better fit.
https://github.com/llvm/llvm-project/pull/193001
More information about the cfe-commits
mailing list