public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-109500-4-dWWMyH6RpX@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109500-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109500

--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to Leandro Lupori from comment #2)
> Thanks for the quick response.
> 
> What if 'f' is changed to this:
> 
> function f()
>   integer, allocatable :: f
> 
>   allocate(f)
>   f = 123
>   deallocate(f)
> end function
> 
> Is the program still invalid? gfortran -Wall doesn't complain in this case,
> 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 
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.

  parent reply	other threads:[~2023-04-13 18:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 13:24 [Bug fortran/109500] New: " leandro.lupori at linaro dot org
2023-04-13 15:05 ` [Bug fortran/109500] " kargl at gcc dot gnu.org
2023-04-13 17:06 ` leandro.lupori at linaro dot org
2023-04-13 18:12 ` kargl at gcc dot gnu.org [this message]
2023-04-13 18:32 ` anlauf at gcc dot gnu.org
2023-04-13 19:44 ` leandro.lupori at linaro dot org
2023-04-13 21:28 ` anlauf at gcc dot gnu.org
2023-04-13 21:34 ` sgk at troutmask dot apl.washington.edu
2023-04-14 19:24 ` anlauf at gcc dot gnu.org
2023-04-16 19:42 ` anlauf at gcc dot gnu.org
2023-04-17 12:14 ` leandro.lupori at linaro dot org
2023-04-17 20:20 ` anlauf at gcc dot gnu.org
2023-04-19 17:25 ` leandro.lupori at linaro dot org
2023-04-19 19:02 ` sgk at troutmask dot apl.washington.edu
2023-04-19 19:06 ` anlauf at gcc dot gnu.org
2023-04-19 19:15 ` anlauf at gcc dot gnu.org
2023-04-19 19:42 ` sgk at troutmask dot apl.washington.edu
2023-04-19 21:03 ` anlauf at gcc dot gnu.org
2023-04-20  5:22 ` kargl at gcc dot gnu.org
2023-04-20 16:29 ` sgk at troutmask dot apl.washington.edu
2023-04-20 19:02 ` anlauf at gcc dot gnu.org
2023-04-20 19:04 ` anlauf at gcc dot gnu.org
2023-04-20 20:02 ` anlauf at gcc dot gnu.org
2023-04-22 18:50 ` cvs-commit at gcc dot gnu.org
2023-04-23 18:59 ` anlauf at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109500-4-dWWMyH6RpX@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).