[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug fortran/110505] New: Memory Problems with Array Constructor From Zero Size Allocatable Array Fu
From:       everythingfunctional at protonmail dot com via Gcc-bugs <gcc-bugs () gcc ! gnu ! org>
Date:       2023-06-30 16:43:38
Message-ID: bug-110505-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

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

            Bug ID: 110505
           Summary: Memory Problems with Array Constructor From Zero Size
                    Allocatable Array Function Result
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: everythingfunctional at protonmail dot com
  Target Milestone: ---

The following program breaks valgrind. Note that the loop is actually required
and can't be manually unrolled or it doesn't exhibit the same behavior.

program example
    integer :: i
    do i = 1, 2
        print *, [make_array(), make_array()]
    end do
contains
    function make_array()
        integer, allocatable :: make_array(:)

        allocate(make_array(0))
    end function
end program

$ gfortran -g example.f90
$ valgrind ./a.out       
==216962== Memcheck, a memory error detector
==216962== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==216962== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==216962== Command: ./a.out
==216962== 
==216962== realloc() with size 0
==216962==    at 0x4846BE0: realloc (vg_replace_malloc.c:1649)
==216962==    by 0x10960F: MAIN__ (example.f90:4)
==216962==    by 0x10976F: main (example.f90:3)
==216962==  Address 0x4e68a30 is 0 bytes after a block of size 0 alloc'd
==216962==    at 0x4846BE0: realloc (vg_replace_malloc.c:1649)
==216962==    by 0x1094BD: MAIN__ (example.f90:4)
==216962==    by 0x10976F: main (example.f90:3)
==216962== 

Error:
  unknown error code 14

Memcheck: the 'impossible' happened:
   unknown error code in mc_eq_Error

host stacktrace:
==216962==    at 0x58042CDA: show_sched_status_wrk (m_libcassert.c:406)
==216962==    by 0x58042E07: report_and_quit (m_libcassert.c:477)
==216962==    by 0x580430DF: panic (m_libcassert.c:553)
==216962==    by 0x580430DF: vgPlain_tool_panic (m_libcassert.c:568)
==216962==    by 0x58039828: vgMemCheck_eq_Error (mc_errors.c:1067)
==216962==    by 0x5803E1B7: eq_Error (m_errormgr.c:307)
==216962==    by 0x5803E1B7: vgPlain_maybe_record_error (m_errormgr.c:765)
==216962==    by 0x580390A4: vgMemCheck_record_realloc_size_zero
(mc_errors.c:896)
==216962==    by 0x5800599A: vgMemCheck_realloc (mc_malloc_wrappers.c:583)
==216962==    by 0x580A029E: do_client_request (scheduler.c:1987)
==216962==    by 0x580A029E: vgPlain_scheduler (scheduler.c:1542)
==216962==    by 0x580E58BD: thread_wrapper (syswrap-linux.c:102)
==216962==    by 0x580E58BD: run_a_thread_NORETURN (syswrap-linux.c:155)

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable (lwpid 216962)
==216962==    at 0x4846BE0: realloc (vg_replace_malloc.c:1649)
==216962==    by 0x10960F: MAIN__ (example.f90:4)
==216962==    by 0x10976F: main (example.f90:3)
client stack range: [0x1FFEFFE000 0x1FFF000FFF] client SP: 0x1FFF000130
valgrind stack range: [0x1002BAA000 0x1002CA9FFF] top usage: 10000 of 1048576


Note: see also the FAQ in the source distribution.
It contains workarounds to several common problems.
In particular, if Valgrind aborted or crashed after
identifying problems in your program, there's a good chance
that fixing those problems will prevent Valgrind aborting or
crashing, especially if it happened in m_mallocfree.c.

If that doesn't help, please report this bug to: www.valgrind.org

In the bug report, send all the above text, the valgrind
version, and what OS and version you are using.  Thanks.=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic