@@ -715,7 +715,7 @@ void CXXInstanceCall::getExtraInvalidatedValues(
715715 // Get the record decl for the class of 'This'. D->getParent() may return
716716 // a base class decl, rather than the class of the instance which needs to
717717 // be checked for mutable fields.
718- const CXXRecordDecl *ParentRecord = getDeclForDynamicType ();
718+ const CXXRecordDecl *ParentRecord = getDeclForDynamicType (). first ;
719719 if (!ParentRecord || !ParentRecord->hasDefinition ())
720720 return ;
721721
@@ -747,17 +747,19 @@ SVal CXXInstanceCall::getCXXThisVal() const {
747747 return ThisVal;
748748}
749749
750- const CXXRecordDecl *CXXInstanceCall::getDeclForDynamicType () const {
750+ std::pair<const CXXRecordDecl *, bool >
751+ CXXInstanceCall::getDeclForDynamicType () const {
751752 const MemRegion *R = getCXXThisVal ().getAsRegion ();
752753 if (!R)
753- return nullptr ;
754+ return {} ;
754755
755756 DynamicTypeInfo DynType = getDynamicTypeInfo (getState (), R);
756757 if (!DynType.isValid ())
757- return nullptr ;
758+ return {} ;
758759
759760 assert (!DynType.getType ()->getPointeeType ().isNull ());
760- return DynType.getType ()->getPointeeCXXRecordDecl ();
761+ return {DynType.getType ()->getPointeeCXXRecordDecl (),
762+ DynType.canBeASubClass ()};
761763}
762764
763765RuntimeDefinition CXXInstanceCall::getRuntimeDefinition () const {
@@ -771,7 +773,7 @@ RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const {
771773 if (!MD->isVirtual ())
772774 return AnyFunctionCall::getRuntimeDefinition ();
773775
774- const CXXRecordDecl *RD = getDeclForDynamicType ();
776+ auto [RD, CanBeSubClass] = getDeclForDynamicType ();
775777 if (!RD || !RD->hasDefinition ())
776778 return {};
777779
@@ -795,23 +797,20 @@ RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const {
795797 return {};
796798 }
797799
798- const MemRegion *R = getCXXThisVal ().getAsRegion ();
799- DynamicTypeInfo DynType = getDynamicTypeInfo (getState (), R);
800- assert (DynType.isValid () && " ensured by getDeclForDynamicType()" );
801-
802800 // Does the decl that we found have an implementation?
803801 const FunctionDecl *Definition;
804802 if (!Result->hasBody (Definition)) {
805- if (!DynType. canBeASubClass () )
803+ if (!CanBeSubClass )
806804 return AnyFunctionCall::getRuntimeDefinition ();
807805 return {};
808806 }
809807
810808 // We found a definition. If we're not sure that this devirtualization is
811809 // actually what will happen at runtime, make sure to provide the region so
812810 // that ExprEngine can decide what to do with it.
813- if (DynType.canBeASubClass ())
814- return RuntimeDefinition (Definition, R->StripCasts ());
811+ if (CanBeSubClass)
812+ return RuntimeDefinition (Definition,
813+ getCXXThisVal ().getAsRegion ()->StripCasts ());
815814 return RuntimeDefinition (Definition, /* DispatchRegion=*/ nullptr );
816815}
817816
0 commit comments