[clang] [analyzer] Use dynamic type when invalidating by a member function call (PR #111138)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 24 01:34:57 PDT 2024


================
@@ -748,6 +747,22 @@ SVal CXXInstanceCall::getCXXThisVal() const {
   return ThisVal;
 }
 
+const CXXRecordDecl *CXXInstanceCall::getDeclForDynamicType() const {
+  const MemRegion *R = getCXXThisVal().getAsRegion();
+  if (!R)
+    return nullptr;
+
+  DynamicTypeInfo DynType = getDynamicTypeInfo(getState(), R);
+  if (!DynType.isValid())
+    return nullptr;
+
+  QualType Ty = DynType.getType()->getPointeeType();
+  if (Ty.isNull())
----------------
steakhal wrote:

My reasoning was that while it was asserted here, it may not apply in general. Given that I abstract this code in a separate function, I may shouldn't enforce this invariant.
Although, the `assert˙wouldn't fire in any of the tests we have.
What I could do, is to have an assert and also a graceful return in that case. That way we would get the benefit of both world.

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


More information about the cfe-commits mailing list