public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "fxcoudert at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/100651] [11/12/13/14 Regression] Weird memory corruption with multiple triggers Date: Sat, 25 Nov 2023 10:11:02 +0000 [thread overview] Message-ID: <bug-100651-4-vmWzw6CZZ9@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 Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |fxcoudert at gcc dot gnu.org Last reconfirmed|2021-07-29 00:00:00 |2023-11-25 Target|x86_64-linux-gnu, | |x86_64-apple-darwin | --- Comment #10 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> --- Further reduced to this: meau /tmp $ cat a.f90 program main character(:), allocatable :: err_msg call to_int(err_msg) print *, 'allocated :', allocated(err_msg) print *, err_msg(1:7) print *, 'len : ', len(err_msg) print *, 'err_msg : ', err_msg contains subroutine assert_code(err_msg) character(:), optional, allocatable :: err_msg err_msg = 'foo bar' end subroutine to_int(err_msg) character(:), optional, allocatable :: err_msg call assert_code(err_msg) end end meau /tmp $ gfortran a.f90 -O0 -g && ./a.out allocated : T foo bar len : 39026212 Operating system error: Cannot allocate memory Memory allocation failure in xrealloc The problem is in the code generated for the to_int subroutine, handling the optional aspect. We can see above that the string is allocated and set correctly. However, the length is not correctly set. You can see from the dump: __attribute__((fn spec (". w "))) void to_int (character(kind=1)[1:*_err_msg] * * err_msg, integer(kind=8) * _err_msg) { { character(kind=1)[1:*_err_msg] * * D.3001; integer(kind=8) D.3002; D.3001 = err_msg != 0B ? err_msg : 0B; D.3002 = err_msg != 0B ? *_err_msg : 0; assert_code (D.3001, &D.3002); } } The string length passed as second argument to assert_code is a pointer to a local variable, and its value will not be propagated back into _err_msg (the string length passed to to_int).
next prev parent reply other threads:[~2023-11-25 10:11 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 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 [this message] 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-vmWzw6CZZ9@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: linkBe 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).