From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C4C6F3857C4E; Wed, 7 Sep 2022 18:13:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4C6F3857C4E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662574426; bh=REx8MLRzzShxtn3m2ftykz5yehWWNGLVDTz8RVheKD0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WERMW7inEodZqpzVizqUAnwyAYwYkn3O93TjIHOx2FgJ+ZaHXiFlYBTPS6wv9exjX drJskj40rPjH/hv+5Eeo1uX6Kx4nKtOHP2X3u45QDFVV+/jytwaBWYSw1nplixL6Gw 7ZONc+FGhsYzMTjSa+hfTqvdmhxQWeiJGcJkNvdc= From: "kargl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/106500] ICE on function as an argument to c_sizeof() Date: Wed, 07 Sep 2022 18:13:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kargl at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status everconfirmed priority cf_reconfirmed_on Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106500 kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Priority|P3 |P4 Last reconfirmed| |2022-09-07 --- Comment #3 from kargl at gcc dot gnu.org --- (In reply to G. Steinmetz from comment #2) > The following examples are presumably valid code, > don't use a function, nor alloc, but should be related : >=20 >=20 > $ cat z1.f90 > program p > use iso_c_binding > integer :: a(2) =3D 0 > print *, c_sizeof((a)) > print *, c_sizeof(2*a) > end >=20 >=20 > $ cat z2.f90 > program p > use iso_c_binding > character(1) :: a(2) =3D '0' > print *, c_sizeof((a)) > print *, c_sizeof(a) > end >=20 The above testcases compile with this patch. diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index bbdb5b392fc..f5fed223a23 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -2766,7 +2766,24 @@ gfc_find_array_ref (gfc_expr *e, bool allow_null) { gfc_ref *ref; - for (ref =3D e->ref; ref; ref =3D ref->next) + if (e->expr_type =3D=3D EXPR_OP && !e->ref) + { + gfc_expr *op1, *op2; + op1 =3D e->value.op.op1; + op2 =3D e->value.op.op2; + if (!op2) + { + if (op1->rank =3D=3D 0) + return NULL; + ref =3D op1->ref; + } + else + ref =3D op2->ref; + } + else + ref =3D e->ref; + + for (; ref; ref =3D ref->next) if (ref->type =3D=3D REF_ARRAY && (ref->u.ar.type =3D=3D AR_FULL || ref->u.ar.type =3D=3D AR_SECTI= ON)) break;=