public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Boyce at engineer dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/108652] New: type-bound procedure that returns integer used to allocate character on stack
Date: Fri, 03 Feb 2023 00:23:19 +0000	[thread overview]
Message-ID: <bug-108652-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108652
           Summary: type-bound procedure that returns integer used to
                    allocate character on stack
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Boyce at engineer dot com
  Target Milestone: ---

Created attachment 54400
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54400&action=edit
Source code, bash file to compile, and error message

type-bound procedure that returns integer used to allocate character on stack

This is similar to 
    Bug 59450 - [OOP] ICE for type-bound-procedure expression in module
procedure interface 

But the error still occurs for the following code:

---------------------------------------------------------------
module character_stack_error
    implicit none
    type char
       character(:), allocatable:: str
    contains
       procedure, pass(ch):: char_sub
       procedure, pass(ch):: char_len
    end type
    !
    contains
    !
    subroutine char_sub(ch, ch2)
      class(char), intent(in):: ch
      character(*), intent(out):: ch2
      character(ch%char_len()):: work   ! ch%char_len() -> internal compiler
error: Segmentation fault
      !character(char_len(ch)):: work   ! This raises: Error: MODULE-PROC
procedure at (1) is already declared as EXTERNAL-PROC procedure 
      !character(len(ch%str)):: work    ! while not correct, this works fine
      !character(char_len2(ch)):: work  ! this works too
      !character(char_len3(ch)):: work  ! this works too
      work = ch%str
      ch2 = work
    end subroutine
    !
    pure function char_len(ch) result(siz)
      class(char), intent(in):: ch
      integer:: siz
      if(allocated(ch%str)) then
        siz = len(ch%str)
      else
          siz = 0
      end if
    end function
    !
    pure function char_len2(ch) result(siz)
      class(char), intent(in):: ch
      integer:: siz
      if(allocated(ch%str)) then
        siz = len(ch%str)
      else
          siz = 0
      end if
    end function
    !
    pure function char_len3(ch) result(siz)
      class(char), intent(in):: ch
      integer:: siz
      siz = char_len(ch)
    end function
end module

program MAIN
  use character_stack_error
  implicit none
  type(char):: ch1
  character(5):: ch2
  ch1%str = 'abc'
  call ch1%char_sub(ch2)
end program

---------------------------------------------------------------

which gives the following error is given:

f951: internal compiler error: Segmentation fault
0xd41627 internal_error(char const*, ...)
        ???:0
0x14c28f0 gfc_find_derived_vtab(gfc_symbol*)
        ???:0
0x14f619e gfc_reduce_init_expr(gfc_expr*)
        ???:0
0x14d0afa gfc_match_char_spec(gfc_typespec*)
        ???:0
0x14fdc8f gfc_match_decl_type_spec(gfc_typespec*, int)
        ???:0
0x158cb55 gfc_parse_file()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.

---------------------------------------------------------------

where the error is because ch%char_len() returns an integer used to make work
in:
   character(ch%char_len()):: work


I have in the code commented different versions that will work, but the
original should also.
I tested this code with with 11.3.0 and 12.1.0 

I attached a simple code, the resulting error message, and bash file for
compiling to create the error.

                 reply	other threads:[~2023-02-03  0:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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-108652-4@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).