]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-eh: Don't crash on GIMPLE_TRY_FINALLY with empty cleanup sequence [PR117845]
authorSimon Martin <simon@nasilyan.com>
Mon, 9 Dec 2024 08:21:25 +0000 (09:21 +0100)
committerSimon Martin <simartin@gcc.gnu.org>
Mon, 9 Dec 2024 08:24:53 +0000 (09:24 +0100)
commitac054467bf42365de85336775cba9b9f476e73ed
tree83a45ae87bb6b340b48682a95176c4ef298db855
parent7b8f236187e1e62c664fae6e76a5e38075bfc3d7
tree-eh: Don't crash on GIMPLE_TRY_FINALLY with empty cleanup sequence [PR117845]

The following valid code triggers an ICE with -fsanitize=address

=== cut here ===
void l() {
    auto const ints = {0,1,2,3,4,5};
    for (auto i : { 3 } ) {
        __builtin_printf("%d ", i);
    }
}
=== cut here ===

The problem is that honor_protect_cleanup_actions does not expect the
cleanup sequence of a GIMPLE_TRY_FINALLY to be empty. It is however the
case here since r14-8681-gceb242f5302027, because lower_stmt removes the
only statement in the sequence: a ASAN_MARK statement for the array that
backs the initializer_list).

This patch simply checks that the finally block is not 0 before
accessing it in honor_protect_cleanup_actions.

PR c++/117845

gcc/ChangeLog:

* tree-eh.cc (honor_protect_cleanup_actions): Support empty
finally sequences.

gcc/testsuite/ChangeLog:

* g++.dg/asan/pr117845-2.C: New test.
* g++.dg/asan/pr117845.C: New test.

(cherry picked from commit 3076539544d3e36684cc8eed3374aeff5b44c9b1)
gcc/testsuite/g++.dg/asan/pr117845-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/asan/pr117845.C [new file with mode: 0644]
gcc/tree-eh.cc