From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9B2293858D33; Thu, 13 Apr 2023 18:12:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B2293858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681409528; bh=jpVjBQXO1GdVDhVf1Qmz0B3vcGS/NvGyuiDDkiYSNYk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Gpe43RFgwWsg8xZigsy9aqRx80kOmyu2QUCRBt1d9+GdNotvsGv33i5ovoj++iuqK Ya2LPxzCRcsGBvglZdwm/AfA6X6pRZOzBDMzw5Ge+hf2jY4t+omYroiKKhA78IdHbK ROzBi4pyBwkxIbejagTCgyxiDFCpHR3buX1hIzo8= From: "kargl 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: Thu, 13 Apr 2023 18:12:08 +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: UNCONFIRMED 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=3D109500 --- Comment #3 from kargl at gcc dot gnu.org --- (In reply to Leandro Lupori from comment #2) > Thanks for the quick response. >=20 > What if 'f' is changed to this: >=20 > function f() > integer, allocatable :: f >=20 > allocate(f) > f =3D 123 > deallocate(f) > end function >=20 > Is the program still invalid? gfortran -Wall doesn't complain in this cas= e, > but I get a SIGSEGV instead of SIGABRT. Yes. It is not valid Fortran. You've deallocated 'f', which means the function result is not set. Your example is also likely why the warning is hidden=20 behind -Wall. I suspect there are too many false positive and with your code you're getting a false negative (ie., no warning). F2023, p. 331 15.5.3 Function reference A function is invoked during expression evaluation by a function-reference or by a defined operation (10.1.6). When it is invoked, all actual argument expressions are evaluated, then the arguments are associated, and then the function is executed. When execution of the function is complete, the value of the function result is available for use in the expression that caused the function to be invoked. In 'print *, is_allocated(f())', the function-reference is evaluated. F2023, p. 336 On completion of execution of the function, the value returned is that of its function result. ... If the function result is not a pointer, its value shall be defined by the function. 19.6.6 Events that cause variables to become undefined ... (10) When an allocatable entity is deallocated, it becomes undefined.=