public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98290] New: run-time error with optional character arguments
@ 2020-12-15 14:55 vivekrao4 at yahoo dot com
  2020-12-15 14:59 ` [Bug fortran/98290] " vivekrao4 at yahoo dot com
  2020-12-15 15:04 ` schwab@linux-m68k.org
  0 siblings, 2 replies; 3+ messages in thread
From: vivekrao4 at yahoo dot com @ 2020-12-15 14:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98290
           Summary: run-time error with optional character arguments
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vivekrao4 at yahoo dot com
  Target Milestone: ---

With GNU Fortran (GCC) 11.0.0 20200927 (experimental) on Windows from
equation.com, compiling and running the code

function c(x1,x2) result(vec)
! return array of present character variable arguments
character (len=*) , intent(in), optional     :: x1,x2
character (len=10)            , allocatable  :: vec(:)
character (len=10)            , allocatable  :: vec_(:)
integer                                      :: n
allocate (vec_(2))
vec = ""
if (present(x1)) vec_(1) = x1
if (present(x2)) vec_(2) = x2
n = count([present(x1),present(x2)])
allocate (vec(n))
if (n > 0) vec = vec_(:n)
end function c
end module util_mod
!
program xc
use util_mod, only: c
implicit none
print*,c("girl","boy")
end program xc

gives

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0xffffffff
#1  0xffffffff
#2  0xffffffff
#3  0xffffffff
#4  0xffffffff
#5  0xffffffff
#6  0xffffffff
#7  0xffffffff
#8  0xffffffff
#9  0xffffffff
#10  0xffffffff
#11  0xffffffff
#12  0xffffffff
#13  0xffffffff
#14  0xffffffff

but 

gives

 girl      boy       

with g95 and Intel Fortran.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/98290] run-time error with optional character arguments
  2020-12-15 14:55 [Bug fortran/98290] New: run-time error with optional character arguments vivekrao4 at yahoo dot com
@ 2020-12-15 14:59 ` vivekrao4 at yahoo dot com
  2020-12-15 15:04 ` schwab@linux-m68k.org
  1 sibling, 0 replies; 3+ messages in thread
From: vivekrao4 at yahoo dot com @ 2020-12-15 14:59 UTC (permalink / raw)
  To: gcc-bugs

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

Vivek Rao <vivekrao4 at yahoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Vivek Rao <vivekrao4 at yahoo dot com> ---
Sorry, never mind. When I remove the code

vec = ""

which is illegal because vec has not yet been allocated, the code runs fine
with gfortran.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/98290] run-time error with optional character arguments
  2020-12-15 14:55 [Bug fortran/98290] New: run-time error with optional character arguments vivekrao4 at yahoo dot com
  2020-12-15 14:59 ` [Bug fortran/98290] " vivekrao4 at yahoo dot com
@ 2020-12-15 15:04 ` schwab@linux-m68k.org
  1 sibling, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2020-12-15 15:04 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-15 15:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 14:55 [Bug fortran/98290] New: run-time error with optional character arguments vivekrao4 at yahoo dot com
2020-12-15 14:59 ` [Bug fortran/98290] " vivekrao4 at yahoo dot com
2020-12-15 15:04 ` schwab@linux-m68k.org

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).