From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 191453857C72; Tue, 30 Aug 2022 06:57:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 191453857C72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661842659; bh=GtfkRgo75i5EF7fnJdwXDfFjMhgZgufe7OC/n5QcDDw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=larlu7PeDjxhxJiq6sA7a8+wTWJCcFpse2g2rZ/IwxRXCk2fKdizqttNxljboo7Pp 3e3OlC1BdspElbmtqXZpYYzxIAJ85zMqwKswyNkDZDCJetbDLh37+J8mWwpyjf5ysq eXeow73OD6N5tlk5Em/MVvIbEa6l+ZLZEenDDFew= From: "federico.perini at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/106771] [OOP] ICE with PACK intrinsic, in gfc_conv_expr_descriptor, at fortran/trans-array.c:7328 Date: Tue, 30 Aug 2022 06:57:38 +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: 9.2.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: federico.perini at gmail dot com X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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=3D106771 --- Comment #5 from federico --- My bad, the SEGFAULT is my mistake, I've made a half-baked example that does not work. Here's the fixed one:=20 module test implicit none type::t integer, allocatable :: iloc(:) contains=20 procedure :: is_active =3D> isa procedure :: list2loc =3D> myfun_poly end type t contains elemental logical function isa(this,i) class(t), intent(in) :: this integer, intent(in) :: i integer :: n n =3D merge(size(this%iloc),0,allocated(this%iloc)) if (i>0 .and. i<=3Dn) then ! Segmentation fault here=20 isa =3D this%iloc(i)>0 else isa =3D .false. endif=20=20 end function isa ! internal compiler error: in gfc_conv_expr_descriptor, at fortran/trans-array.c:7328 function myfun_poly(this,IDs) result (ilocs) class(t), intent(in) :: this integer, intent(in) :: IDs(:) integer, allocatable :: ilocs(:) if (size(IDs)<=3D0) then allocate(ilocs(0)) else ilocs =3D pack(this%iloc(IDs),this%is_active(IDs)) endif end function myfun_poly ! WORKS function myfun(this,IDs) result (ilocs) type(t), intent(in) :: this integer, intent(in) :: IDs(:) integer, allocatable :: ilocs(:) if (size(IDs)<=3D0) then allocate(ilocs(0)) else ilocs =3D pack(this%iloc(IDs),this%is_active(IDs)) endif end function myfun end module test=20=20=20=20 program testp use test implicit none type(t) :: a integer :: rnd(100),i real :: x(100) integer, allocatable :: list(:) ! Create a dummy initialization a%iloc =3D [(i,i=3D1,100)] call random_number(x); rnd =3D ceiling(x*99) ! Works print *, 'rnd=3D',rnd list =3D myfun(a,rnd) ! ICE list =3D a%list2loc(rnd) print *, 'list=3D',list end program testp The segfault is now gone, but the ICE remains for all versions until 10.3.0 (see https://godbolt.org/z/6TKa4sEe9)=