https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97114
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Egas Ribeiro <[email protected]>: https://gcc.gnu.org/g:8f1698229d33a74cda7ec9f02575172df10b2774 commit r17-2756-g8f1698229d33a74cda7ec9f02575172df10b2774 Author: Egas Ribeiro <[email protected]> Date: Sun Jul 5 11:59:51 2026 +0100 analyzer: support vfunc devirtualization [PR97114] The analyzer doesn't currently support virtual function call resolution, and has no way to devirtualize concrete calls. This patch adds support for devirtualization of virtual methods by adding logic around OBJ_TYPE_REF calls and using the information it tracks to link the calls back to the concrete subclass implementation stored in the OBJ_TYPE_REF_OBJECT's vptr field. This approach relies on the pre-existing store binding mechanism to keep track of which _ZTV* instance the object's vptr field points to, and thus doesn't require any additional modeling of the dynamic type of the object to resolve calls. can_throw_p is also extended to consider thunks that wrap virtual methods when dealing with multiple inheritance, and now checks TREE_NOTHROW for more accurate results (i.e considers noexcept attributes on methods). PR analyzer/97114 gcc/analyzer/ChangeLog: * region-model.cc (can_throw_p): improve NOTHROW detection and consider the thunk case. (region_model::get_fndecl_for_virtual_call): New function. (region_model::get_fndecl_for_call): Update to use get_fndecl_for_virtual_call on OBJ_TYPE_REF. * region-model.h (class region_model): New decl. gcc/testsuite/ChangeLog: * g++.dg/analyzer/devirt-1.C: New test. * g++.dg/analyzer/devirt-multiple-inheritance-1.C: New test. * g++.dg/analyzer/devirt-noexcept-1.C: New test. * g++.dg/analyzer/devirt-unknown-1.C: New test. Signed-off-by: Egas Ribeiro <[email protected]>
