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

Ziqing Luo via cfe-commits cfe-commits at lists.llvm.org
Tue May 6 11:48:40 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();
----------------
ziqingluo-90 wrote:

Thanks for the comments!
yeah, I'm aware that `SVal::getType` could return something not accurate as NoQ pointed out in a different page.  What I was thinking is:
- If `SVal::getType`  is conservative, regardless of how inaccurate it is, we will be fine to use it.
- If we avoid using SVal::getType`, its improvement will come slowly.

But you guys are right that we should not take the risk in the core engine.  I'll fix it.


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


More information about the cfe-commits mailing list