public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/110723] New: ICE with allocatable character lhs and parenthesized array with vector subscript
Date: Tue, 18 Jul 2023 16:46:03 +0000	[thread overview]
Message-ID: <bug-110723-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2023-07-18 16:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18 16:46 anlauf at gcc dot gnu.org [this message]
2023-07-18 17:01 ` [Bug fortran/110723] " anlauf at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110723-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).