From: Marek Polacek Date: Thu, 11 Jul 2024 19:57:43 +0000 (-0400) Subject: eh: ICE with std::initializer_list and ASan [PR115865] X-Git-Tag: basepoints/gcc-16~7412 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e60a6abfece40c7bf55d6ca0a439078d3f5159a;p=thirdparty%2Fgcc.git eh: ICE with std::initializer_list and ASan [PR115865] Here we ICE with -fsanitize=address on std::initializer_list x = { 1, 2, 3 }; since r14-8681, which removed .ASAN_MARK calls on TREE_STATIC variables. That means that lower_try_finally now instead of try { .ASAN_MARK (UNPOISON, &C.0, 12); x = {}; x._M_len = 3; x._M_array = &C.0; } finally { .ASAN_MARK (POISON, &C.0, 12); } gets: try { x = {}; x._M_len = 3; x._M_array = &C.0; } finally { } and we ICE on the empty finally in lower_try_finally_onedest while getting get_eh_else. PR c++/115865 gcc/ChangeLog: * tree-eh.cc (get_eh_else): Check that the result of gimple_seq_first_stmt is non-null. gcc/testsuite/ChangeLog: * g++.dg/asan/initlist2.C: New test. Co-authored-by: Jakub Jelinek --- diff --git a/gcc/testsuite/g++.dg/asan/initlist2.C b/gcc/testsuite/g++.dg/asan/initlist2.C new file mode 100644 index 000000000000..bce5410be339 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/initlist2.C @@ -0,0 +1,16 @@ +// PR c++/115865 +// { dg-do compile } +// { dg-options "-fsanitize=address" } + +typedef decltype(sizeof(char)) size_t; + +namespace std { +template class initializer_list { + int *_M_array; + size_t _M_len; +}; +} + +int main() { + std::initializer_list x = { 1, 2, 3 }; +} diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc index a776ad5c92ba..9609bdc0d9b7 100644 --- a/gcc/tree-eh.cc +++ b/gcc/tree-eh.cc @@ -950,7 +950,7 @@ static inline geh_else * get_eh_else (gimple_seq finally) { gimple *x = gimple_seq_first_stmt (finally); - if (gimple_code (x) == GIMPLE_EH_ELSE) + if (x && gimple_code (x) == GIMPLE_EH_ELSE) { gcc_assert (gimple_seq_singleton_p (finally)); return as_a (x);