[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);
----------------
guillem-bartrina-sonarsource wrote:

I can't think of any scenario where this could be “Unknown”: this is the region of the `this` object at the end of the **constructor**; we're creating the object, not calling a method on an existing object, and as far as I know, we cannot create an “Unknown” region... Furthermore, the functions involved do not appear to have _null_ return paths. Besides, there’s no easy way to instrument the getCXXThis function to check if the SVal of the returned loc is ever unknown, since we don’t have access to the state at that point.

Note that these specific instructions were already present; I’ve simply moved them to a separate function. And, so far, no crashes were reported.

However, I can add the defensive check if you deem it appropriate, though I won’t be able to design a test that exercises that path.

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


More information about the cfe-commits mailing list