From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8F7E43858C50; Wed, 19 Apr 2023 21:03:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F7E43858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681938216; bh=6ItX95DgjIzJ+vXoripCrnbvXrlNiOmJ555tYV2BsR8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=r6/uMW+iZJu8RksKT0Suj+kQQz5RNVDryCmsmlhc2K+/0ozpyQZQSOPJyk+4psIEx VLxGE4JZvK0hmIZ8ShngLX8PcJwSd8snjp309Kwk/ghIcBpgOUrsciCyAS29DforI5 TLTsLG/4k0KhKnKbbYkoTr3HWbNmbywrJSSCo5AM= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109500] SIGABRT when calling a function that returns an unallocated value Date: Wed, 19 Apr 2023 21:03:36 +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: accepts-invalid, diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P5 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=3D109500 --- Comment #17 from anlauf at gcc dot gnu.org --- (In reply to Steve Kargl from comment #16) > First, note, 'allocated(f())' throws an error. Agree. > Now, with the original code, >=20 > is_allocated(f()) >=20 > The function reference is evaluated, and then the function result > (aka it's value) is argument associated with an allocatable dummy > argument. This is technically wrong as the actual argument (aka > value returned by the function reference) should not have the > allocatable attribute. Agree. See also the discussion on the J3 mailing list. > I'll repeat. The actual argument is the value resulting from > the function reference. The "shall" in "shall be allocatable" > applies to something the programmer must ensure. Agree. > If we go back to the original code and modify to allocate > f by say doing 'f =3D 42' in f(), gfortran produces=20 >=20 > % gfcx -o z -Wall a.f90 && ./z > T >=20 > This is the problem. Yes, f is allocated and assigned=20 > 42. The printed 'T' is bogus because 42 is value of > the function. 42 is no allocatable. Agree again. The point is that there is a bug in gfortran which currently effectively generates code which resembles integer, allocatable :: p p =3D f() print *, is_allocated(p) deallocate (p) (of course with a temporary for the function result). The technical reason for the crash is the copying of the function (non)resu= lt. The patch in comment#9 rejects all related misuses. Given the lengthy thread on the J3 mailing list, I am wondering whether the= re ever was an explicit IR on the issue, or was it considered so obvious that the clarification was deferred to the F2018 document. > One place to possibly check for an error is when=20 > gfortran resolves argument association. If a dummy > argument is allocatable, the actual argument needs=20 > to be allocatable and cannot not also be a function > result variable.=