https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110723
Bug ID: 110723 Summary: ICE with allocatable character lhs and parenthesized array with vector subscript Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: anlauf at gcc dot gnu.org Target Milestone: --- Found while analyzing pr95947: program p implicit none character(len=1) :: m(3) = ['a','b','c'] character(len=:), allocatable :: n(:) n = m([2]) n = m([2,3]) n = (m([2])) ! ICE n = (m([2,3])) ! ICE end We end up with EXPR_OP in the assignment for the parenthesized variants, leading to bad gimple. Tentative fix: diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index ef3e6d08f78..63d39c2516e 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -11954,6 +11954,12 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, rss = NULL; + /* Strip left-over parentheses around rhs variables (not expressions). */ + while (expr2->expr_type == EXPR_OP + && expr2->value.op.op == INTRINSIC_PARENTHESES + && expr2->value.op.op1->expr_type == EXPR_VARIABLE) + expr2 = expr2->value.op.op1; + if (expr2->expr_type != EXPR_VARIABLE && expr2->expr_type != EXPR_CONSTANT && (expr2->ts.type == BT_CLASS || gfc_may_be_finalized (expr2->ts))) Not sure if this is the right place.