aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-11-24 08:44:28 +0100
committerJakub Jelinek <jakub@redhat.com>2023-11-24 08:54:06 +0100
commit1c44bd92a86db3fcdeb4a66ce2f3222d13af0681 (patch)
treefba47a9bb67d3235952efe84ae57bd2037b5cc00 /gcc/tree.cc
parenta7d82b45edeed99a850595eee0e59d16c4df7aff (diff)
downloadgcc-1c44bd92a86db3fcdeb4a66ce2f3222d13af0681.zip
gcc-1c44bd92a86db3fcdeb4a66ce2f3222d13af0681.tar.gz
gcc-1c44bd92a86db3fcdeb4a66ce2f3222d13af0681.tar.bz2
tree: Fix up try_catch_may_fallthru [PR112619]
The following testcase ICEs with -std=c++98 since r14-5086 because block_may_fallthru is called on a TRY_CATCH_EXPR whose second operand is a MODIFY_EXPR rather than STATEMENT_LIST, which try_catch_may_fallthru apparently expects. I've been wondering whether that isn't some kind of FE bug and whether there isn't some unwritten rule that second operand of TRY_CATCH_EXPR must be a STATEMENT_LIST. Looking at the FEs, the C++ FE uses mostly its own trees, TRY_BLOCK (TRY_CATCH_EXPR replacement) with HANDLER in it (CATCH_EXPR replacement) - but HANDLER can be immediate second operand rather than nested in STATEMENT_LIST, EH_SPEC_BLOCK (this one stands for both TRY_CATCH_EXPR and EH_FILTER_EXPR in its second argument); both of these are only replaced by the generic trees during gimplification though, so will unlikely be seen by block_may_fallthru; and then CLEANUP_STMT, which is genericized into TRY_CATCH_EXPR with non-CATCH_EXPR/EH_FILTER_EXPR in its body (this is the one that causes the ICE on this testcase). The Go and Rust FEs create TRY_CATCH_EXPR with CATCH_EXPR immediately in its second argument (but either are unlucky that block_may_fallthru isn't called or the body can always fallthru, or latent ICE), while the D FE most likely hit this ICE and attempts to work around it, by checking at TRY_CATCH_EXPR creation time if the second argument from pop_stmt_list is STATEMENT_LIST and if not, forcefully wraps it into a STATEMENT_LIST. Unfortunately, I don't see an easy way to create an artificial tree iterator from just a single tree statement, so the patch duplicates what the loops later do (after all, it is very simple, just didn't want to duplicate also the large comments explaning it, so the 3 See below. comments). 2023-11-24 Jakub Jelinek <jakub@redhat.com> PR c++/112619 * tree.cc (try_catch_may_fallthru): If second operand of TRY_CATCH_EXPR is not a STATEMENT_LIST, handle it as if it was a STATEMENT_LIST containing a single statement. * g++.dg/eh/pr112619.C: New test.
Diffstat (limited to 'gcc/tree.cc')
-rw-r--r--gcc/tree.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/tree.cc b/gcc/tree.cc
index a3d907a..e9f703e 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -12573,6 +12573,24 @@ try_catch_may_fallthru (const_tree stmt)
if (block_may_fallthru (TREE_OPERAND (stmt, 0)))
return true;
+ switch (TREE_CODE (TREE_OPERAND (stmt, 1)))
+ {
+ case CATCH_EXPR:
+ /* See below. */
+ return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1)));
+
+ case EH_FILTER_EXPR:
+ /* See below. */
+ return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1)));
+
+ case STATEMENT_LIST:
+ break;
+
+ default:
+ /* See below. */
+ return false;
+ }
+
i = tsi_start (TREE_OPERAND (stmt, 1));
switch (TREE_CODE (tsi_stmt (i)))
{