From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4CE573858C83; Thu, 20 Apr 2023 19:36:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CE573858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682019418; bh=LQWmU6FsHgkJRPhiE7Mr/9ANo7ZwWus7HjT0dWrX/NU=; h=From:To:Subject:Date:From; b=KjE7stqg+6CYxQ0hfN1OpyxJ+HXjMs/BuhaIrNRidLnmYV/1PNsL0ThVCuTkES51c Yi5+KcDsv40WyQ2bauxHSDZVC4uocfsboMZS8Sd7alW1gmi5rGdsWBIo8kKt9UBDQi SbKMLRYp7SIuV5xsa+uEVoreupVTml7rX5H7hb1U= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109575] New: Implement runtime check for valid function result Date: Thu, 20 Apr 2023 19:36:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D109575 Bug ID: 109575 Summary: Implement runtime check for valid function result 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: --- Split off from the discussion in pr109500: consider program main implicit none integer, allocatable :: p p =3D f() ! <- this assignment may fail print *, allocated (p) contains function f() integer, allocatable :: f allocate (f, source=3D42) deallocate (f) ! <- this renders the function invalid end function end This code is invalid as the function result must be defined: F2018:15.6.2.2 On completion of execution of the function, the value returned is that of its function result. If the function result is a data pointer, the shape of the value returned by the function is determined by the shape of the function result when the execution of the function is completed. If the function result is not a pointer, its value shall be defined by the function. If the function result is a pointer, on return the pointer association status of the function result shall not be undefined. A runtime check that can detect the failing assignment needs to check that the function result is defined when the function returns.=