[PATCH] Fortran: Fix ICE-on-invalid in trans_code
Sandra Loosemore <[email protected]> Sat, 4 Jul 2026 15:53:30 -0600
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.fortran |
|---|---|
| Message-ID | <[email protected]> |
While testing some WIP OpenMP patches, I ran into an ICE in trans_code after an error in an OpenMP directive was diagnosed. It was trying to use SET_EXPR_LOCATION on error_mark_node, which isn't EXPR_P and doesn't have a location field. I think this fix is "obvious" but I'll wait a couple days before pushing it in case anyone objects or has a better idea. -Sandra
0001-Fortran-Fix-ICE-on-invalid-in-trans_code.patch
(text/x-patch, 989 B)
From 755d810da2ee4d74cb08c9c0686790f8a23a9160 Mon Sep 17 00:00:00 2001 From: Sandra Loosemore <[email protected]> Date: Sat, 4 Jul 2026 13:58:42 +0000 Subject: [PATCH] Fortran: Fix ICE-on-invalid in trans_code. gcc/fortran/ChangeLog * trans.cc (trans_code): Do not try to set location on non-expr tree expressions, e.g. error_mark_node. --- gcc/fortran/trans.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc index c366d7f4dbf..874dac59e4a 100644 --- a/gcc/fortran/trans.cc +++ b/gcc/fortran/trans.cc @@ -2696,7 +2696,9 @@ trans_code (gfc_code * code, tree cond) if (res != NULL_TREE && ! IS_EMPTY_STMT (res)) { - if (TREE_CODE (res) != STATEMENT_LIST) + /* Don't try to set location for trees that don't have one, + e.g. STATEMENT_LIST or error_mark_node. */ + if (EXPR_P (res)) SET_EXPR_LOCATION (res, input_location); /* Add the new statement to the block. */ -- 2.39.5