https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126236
--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kyrylo Tkachov <[email protected]>: https://gcc.gnu.org/g:1934f025d1c9433b314cd8a618d272856041e9ec commit r17-5807-g1934f025d1c9433b314cd8a618d272856041e9ec Author: Kyrylo Tkachov <[email protected]> Date: Thu Oct 15 20:13:50 2026 +0200 rtl: Verify shared jump tables after each pass [PR middle-end/126236] A broken table reference can make tablejump_p stop recognizing a dispatch, which bypasses its CFG checks. Those checks also stop when free_cfg removes the CFG before machine reorganization and branch shortening. Check table references from both instruction patterns and JUMP_LABEL in the existing post-pass RTL verifier. Require live table, base and case labels, label-to-table adjacency, and a shared flag for tables with several repeatable users. Honor the existing target copy restriction when counting users. An uncopyable dispatch can also have an out-of-line execution template. Handle jumps in delay-slot sequences. Allow a shared table to lose users and to change entry width. While the CFG exists, also require a shared table in use to follow one of the jumps through it. Run the structural check on all targets in linear RTL, including after free_cfg. Strengthen the CFG check to compare complete destination sets, including casesi default and exceptional edges. Plugin tests damage individual invariants and check the diagnostics at pass boundaries. Positive tests cover repeated entries, zero or one remaining user, target copy restrictions, shortened tables, delay-slot sequences and casesi default edges. gcc/ChangeLog: PR middle-end/126236 * cfgrtl.cc (rtl_verify_edges): Compare all shared-table destinations with the dispatch's successors. * passes.cc (execute_function_todo): Verify tablejump links before CFG verification and after CFG teardown. * rtl.h (verify_jump_tables): Declare. * rtlanal.cc: Include hash-map.h and tree-pass.h. (verify_jump_tables): New function. gcc/testsuite/ChangeLog: PR middle-end/126236 * gcc.dg/plugin/plugin.exp: Register the tablejump tests. * gcc.dg/plugin/tablejump_plugin.cc: New plugin. * gcc.dg/plugin/tablejump-valid.c: New test. * gcc.dg/plugin/tablejump-missing-edge.c: Likewise. * gcc.dg/plugin/tablejump-extra-edge.c: Likewise. * gcc.dg/plugin/tablejump-null-label.c: Likewise. * gcc.dg/plugin/tablejump-stale-label.c: Likewise. * gcc.dg/plugin/tablejump-missing-ref.c: Likewise. * gcc.dg/plugin/tablejump-detached-label.c: Likewise. * gcc.dg/plugin/tablejump-detached-table.c: Likewise. * gcc.dg/plugin/tablejump-detached-pair.c: Likewise. * gcc.dg/plugin/tablejump-deleted-table.c: Likewise. * gcc.dg/plugin/tablejump-unmarked.c: Likewise. * gcc.dg/plugin/tablejump-case-label.c: Likewise. * gcc.dg/plugin/tablejump-base-label.c: Likewise. * gcc.dg/plugin/tablejump-misplaced-table.c: Likewise. Signed-off-by: Kyrylo Tkachov <[email protected]>
