[clang] [StaticAnalyzer] Make it a noop when initializing a field of empty record (PR #138594)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue May 6 05:05:16 PDT 2025


================
@@ -715,7 +717,11 @@ void ExprEngine::handleConstructor(const Expr *E,
         // actually make things worse. Placement new makes this tricky as well,
         // since it's then possible to be initializing one part of a multi-
         // dimensional array.
-        State = State->bindDefaultZero(Target, LCtx);
+        const CXXRecordDecl *TargetHeldRecord =
+            Target.getType(Ctx)->getPointeeCXXRecordDecl();
----------------
steakhal wrote:

Good point!

`SVal::getType` should be avoided unless it's infeasible to avoid in the context because the type it returns may differ from the actual type that was lost during translating from C++ to the abstract domain in the abstract machine (aka. we approximated something on the way).

Anyway, I believe you could use the proper type by considering the following:
`E` is either `CXXConstructExpr` or `CXXInheritedCtorInitExpr` according to the assert at the beginning of the function.
In both of these we have a `getConstructor()` that should give us the `CXXMethodDecl` and it's `getParent()` should be the `CXXRecordDecl`.


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


More information about the cfe-commits mailing list