[clang] [clang][analyzer] Add support for detecting uninitialized dynamically-allocated objects (PR #193001)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 22 01:05:56 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();
----------------
guillem-bartrina-sonarsource wrote:

Done in b51a70e3bfeb38808268735a2993918e990f1056

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


More information about the cfe-commits mailing list