From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A24143858D32; Thu, 13 Apr 2023 18:32:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A24143858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681410777; bh=OyW89A9Gp71oaOWlDrguf0+5z3JqoIdTGkPKpVnSsVI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WqkkfcPiTaQWPNfS1RYtt6lV7PkOZY0TnFXwYJy2jgt+H7OcelH+4rK+DSrjmrF2X Gk7YCwvltDyCJq5YbjRdDFjMa8Y0A1PQYoKzlzx/kw2cSFToGzIhcQ8UTPC0XoAt1u 9axofcwE4/iv8xYrdRYkV2o5matC5CuTTcZckYLs= 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: Thu, 13 Apr 2023 18:32:57 +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: 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: 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 #4 from anlauf at gcc dot gnu.org --- I think one cannot achieve what the OP wants by using allocable function results. One should use a subroutine instead. Compiling the code with the NAG compiler gives: NAG Fortran Compiler Release 7.1(Hanzomon) Build 7101 Warning: pr109500.f90, line 7: Allocatable function F has not been allocate= d or assigned a value Error: pr109500.f90, line 2: Expected an ALLOCATABLE variable for argument P (no. 1) of IS_ALLOCATED [NAG Fortran Compiler error termination, 1 error, 1 warning] Not perfect, but what you are seeing is an attempt by the compiler to do argument association when you invoke function is_allocated. Now look at the following variants in the main: 1) print *, allocated(f()) You'll get: 2 | print *, allocated(f()) | 1 Error: 'array' argument of 'allocated' intrinsic at (1) must be a variable This is what the standard says. 2) integer, allocatable :: p p =3D f() print *, allocated(p) This compiles, but you get a runtime error (SIGSEGV) with gfortran and ifor= t. Why? The assignment p=3Df() is invalid for unallocated r.h.s., and you are hitting this. The running program will never reach the allocated(p). I don't see a legal way to use an allocatable function without allocating the result. So you should use a subroutine and allocate a result variable. The only potential issue I see here with gfortran is that there is no worki= ng runtime diagnostics for the non-allocated r.h.s. above. But there is none for current ifort/ifx either. If the reporter agrees, we should close this PR as invalid.=