public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gscfq@t-online.de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/100651] Weird memory corruption with multiple triggers
Date: Thu, 20 May 2021 10:23:00 +0000	[thread overview]
Message-ID: <bug-100651-4-RmXMHllTgZ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100651-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from G. Steinmetz <gscfq@t-online.de> ---

Simplified a bit :


$ cat z1.f90
module m
   type :: t
   contains
      procedure, pass(this) :: assign_to_string
      generic :: assignment(=) => assign_to_string
   end type
contains
   subroutine assign_to_string(string, this)
      character(:), allocatable, intent(out) :: string
      class(t), intent(in) :: this
   end
   subroutine assert_code(err_msg)
      character(:), optional, allocatable, intent(inout) :: err_msg
      err_msg = 'foo bar'
   end
   function to_int(err_msg) result(ptr)
      integer :: ptr
      character(:), optional, allocatable, intent(inout) :: err_msg
      ptr = 1
      call assert_code(err_msg)
   end
end
program main
   use m
   type, extends(t) :: t2
      real(8) :: value = 1
   end type
   type(t2) :: x
   integer :: n
   character(:), allocatable :: err_msg
   x = t2(2)
   n = to_int(err_msg)
   print *, 'allocated :', allocated(err_msg)
   print *, 'len :      ', len(err_msg)
!  print *, 'len_trim : ', len_trim(err_msg)
   print *, 'err_msg :  ', err_msg
end


$ cat z2.f90
module m
   type :: t
   contains
      procedure, pass(this) :: assign_to_string
      generic :: assignment(=) => assign_to_string
   end type
contains
   subroutine assign_to_string(string, this)
      character(:), allocatable, intent(out) :: string
      class(t), intent(in) :: this
   end
   subroutine assert_code(err_msg)
      character(:), allocatable, intent(inout) :: err_msg
      err_msg = 'foo bar'
   end
   function to_int(err_msg) result(ptr)
      integer :: ptr
      character(:), allocatable, intent(inout) :: err_msg
      ptr = 1
      call assert_code(err_msg)
   end
end
program main
   use m
   type, extends(t) :: t2
      real(8) :: value = 1
   end type
   type(t2) :: x
   integer :: n
   character(:), allocatable :: err_msg
   x = t2(2)
   n = to_int(err_msg)
   print *, 'allocated :', allocated(err_msg)
   print *, 'len :      ', len(err_msg)
!  print *, 'len_trim : ', len_trim(err_msg)
   print *, 'err_msg :  ', err_msg
end



$ gfortran-12-20210516 z1.f90 -g -O0 && ./a.out
 allocated : T
 len :                 0
Operating system error: Cannot allocate memory
Memory allocation failure in xrealloc

Error termination. Backtrace:
#0  0x40d1c7 in write_character
        at ../../../libgfortran/io/write.c:1416
#1  0x41222e in list_formatted_write_scalar
        at ../../../libgfortran/io/write.c:1900
#2  0x40265e in MAIN__
        at .../z1.f90:36
#3  0x4026a4 in main
        at .../z1.f90:24


$ gfortran-12-20210516 z2.f90 -g -O0 && ./a.out
 allocated : T
 len :                 7
 err_msg :  foo bar

  parent reply	other threads:[~2021-05-20 10:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 14:05 [Bug fortran/100651] New: " matthew.thompson at nasa dot gov
2021-05-20 10:21 ` [Bug fortran/100651] " gscfq@t-online.de
2021-05-20 10:23 ` gscfq@t-online.de [this message]
2021-07-29 15:35 ` iains at gcc dot gnu.org
2021-07-29 16:07 ` iains at gcc dot gnu.org
2021-07-29 17:35 ` matthew.thompson at nasa dot gov
2021-07-29 18:34 ` [Bug fortran/100651] [9/10/11/12 Regression] " iains at gcc dot gnu.org
2021-09-19 23:14 ` pinskia at gcc dot gnu.org
2022-01-17 14:41 ` rguenth at gcc dot gnu.org
2022-05-27  9:45 ` [Bug fortran/100651] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:45 ` jakub at gcc dot gnu.org
2023-07-07 10:39 ` [Bug fortran/100651] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-11-25 10:11 ` fxcoudert at gcc dot gnu.org
2023-11-25 18:59 ` [Bug fortran/100651] [11/12/13/14 Regression] Bad handling of optional, allocatable character argument anlauf at gcc dot gnu.org
2023-11-26 20:37 ` anlauf at gcc dot gnu.org
2023-11-26 20:47 ` anlauf at gcc dot gnu.org
2023-11-26 21:15 ` anlauf at gcc dot gnu.org
2023-11-27 19:33 ` anlauf at gcc dot gnu.org
2023-12-02 14:15 ` cvs-commit at gcc dot gnu.org
2023-12-10 20:14 ` cvs-commit at gcc dot gnu.org
2023-12-10 20:17 ` 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-100651-4-RmXMHllTgZ@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).