https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118790
--- Comment #29 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Perhaps with a help of yet another bitmap, mark_scope_block_unused could bitmap_set_bit DECL_UID of all the BLOCK_VARS VAR_DECLs with DECL_HAS_VALUE_EXPR_P seen in the scopes, and then remove_unused_scope_block_p could when keeping such VAR_DECLs walk_tree their DECL_VALUE_EXPR and if it sees in there a VAR_DECL with DECL_HAS_VALUE_EXPR_P which is not marked in that bitmap, mark it there and queue for addition into the outermost BLOCK_VARS.