[Bug analyzer/119697] Support for exception subclass matching in analyzer
"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]> Tue, 04 Aug 2026 09:05:19 +0000
| Newsgroups | gmane.comp.gcc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D119697 --- Comment #2 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:672923ae05596d602c16f4bdb7449931c5e81cf5 commit r17-2927-g672923ae05596d602c16f4bdb7449931c5e81cf5 Author: Egas Ribeiro <[email protected]> Date: Fri Jun 19 19:19:51 2026 +0100 analyzer: support exception subclass matching [PR analyzer/119697] The analyzer's exception_matches_type_p only treated an exception as caught when the handler type and exception type were identical, so a handler catching a base class did not match a thrown derived class. Add an exception_matches_type_p langhook returning whether a handler of one type catches an exception of another per the language's rules. The default returns false, preserving behavior for frontends without exception support (such as C). The C++ frontend implements it via can_convert_eh (now non-static). This keeps the analyzer language agnostic and the C++ catch-matching rules in the frontend. PR analyzer/119697 gcc/ChangeLog: * langhooks.h (struct lang_hooks): Add exception_matches_type_p. * langhooks-def.h (LANG_HOOKS_EH_MAY_CATCH_P): Define as hook_bool_tree_tree_false. (LANG_HOOKS_INITIALIZER): Add it. gcc/cp/ChangeLog: * except.cc (can_convert_eh): Make non-static. * cp-tree.h (can_convert_eh): Declare. * cp-lang.cc (LANG_HOOKS_EH_MAY_CATCH_P): Define as can_convert_eh. gcc/analyzer/ChangeLog: * ops.cc: Include "langhooks.h". (exception_matches_type_p): Use the exception_matches_type_p langhook; fix catch/exception argument order. gcc/testsuite/ChangeLog: * g++.dg/analyzer/exception-dynamic-spec.C: Remove xfail. * g++.dg/analyzer/exception-subclass-1.C: Remove xfail. __analyzer_dump_path in the catch handler. * g++.dg/analyzer/exception-subclass-2.C: Add __analyzer_dump_path in the catch handler; Add __analyzer_eval to interprocedural call. * g++.dg/analyzer/exception-subclass-3.C: New test. * g++.dg/analyzer/exception-subclass-4.C: New test. * g++.dg/analyzer/multiple-inheritance-1.C: New test. Signed-off-by: Egas Ribeiro <[email protected]>=