https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91300
Bug ID: 91300
Summary: Wrong runtime error message with allocate and errmsg=
Product: gcc
Version: 9.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: zed.three at gmail dot com
Target Milestone: ---
Created attachment 46644
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46644&action=edit
MVCE for wrong runtime error message from allocate
The following two allocates give different error messages:
use, intrinsic :: iso_fortran_env, only : real64, int64
integer(int64), parameter :: bignumber = huge(1) * 2
real(real64), allocatable :: bigarray(:)
allocate(bigarray(bignumber))
allocate(bigarray(bignumber), stat=stat, errmsg=errmsg)
The first `allocate` terminates with the following message:
Operating system error: Cannot allocate memory
Allocation would exceed memory limit
(followed by a backtrace). The second `allocate` puts the following in
`errmsg`:
Attempt to allocate an allocated object
which is not correct.
I've attached a full MVCE. Uncomment line 10 to see the correct error message.
Also note that if you do attempt to allocate an allocated object, the value of
`stat` is the same as if you attempted to allocate too much memory, but from
looking in trans.c and trans-stmt.c, I think that is a separate issue.