From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B55EF3849ACA; Tue, 23 Apr 2024 17:22:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B55EF3849ACA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713892977; bh=mH9bgYTH2wRSXO2kmlcr0VydlP/F+ZnIbg6KzmG8roY=; h=From:To:Subject:Date:From; b=hpSjCbSPKfBplR3KOFX/m6PwZ4Si0vTiA00kALmn5o4DWHLy00Y9H4H3blSjE7q/F 5lZETVs6GNCiKOTl4jSk6Php+10hBpUg4QWOwXiB1+H6eOkcfs5tr7VW23EY+YsZ9t yBbpee89PSnGW4STonIkODvVafuK2v2Nsnz0Mq2Q= From: "neil.n.carlson at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/114827] New: Valgrind reports errors with class(*) assignment Date: Tue, 23 Apr 2024 17:22:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: neil.n.carlson at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114827 Bug ID: 114827 Summary: Valgrind reports errors with class(*) assignment Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: neil.n.carlson at gmail dot com Target Milestone: --- I'm trying to pin down a malloc corruption error ("malloc(): corrupted top size") that happens during finalization of a derived type object. I'm still working on paring things down to a reportable reproducer, but the traceback hinted at a possible problem with the assignment of a class(*) variable to another allocatable class(*) variable when the dynamic type of the rhs is character. I've turned that bit into the following example which compiles a= nd runs without error, but when run under valgrind it reports several invalid writes, which suggests to me that the executable is doing something wrong. Note that if the assignment to the allocatable class(*) variable is replace= d by a sourced-allocation, the valgrind output is completely clean. $ cat foo.f90 program main call run contains subroutine run class(*), allocatable :: y call foo('fubarfubarfubarfubarfubarfu', y) end subroutine=20 subroutine foo(a, b) class(*), intent(in) :: a class(*), allocatable :: b b =3D a !allocate(b, source=3Da) ! VALGRIND REPORTS NO INVALID WRITES=20 end subroutine end program $ gfortran -g -O0 foo.f90 $ valgrind -s ./a.out =3D=3D587107=3D=3D Memcheck, a memory error detector =3D=3D587107=3D=3D Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward= et al. =3D=3D587107=3D=3D Using Valgrind-3.22.0 and LibVEX; rerun with -h for copy= right info =3D=3D587107=3D=3D Command: ./a.out =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D Invalid write of size 2 =3D=3D587107=3D=3D at 0x484F353: memmove (vg_replace_strmem.c:1410) =3D=3D587107=3D=3D by 0x401230: __copy_character_1.0 (foo.f90:1) =3D=3D587107=3D=3D by 0x401368: foo.1 (foo.f90:11) =3D=3D587107=3D=3D by 0x4013E1: run.2 (foo.f90:6) =3D=3D587107=3D=3D by 0x401258: MAIN__ (foo.f90:2) =3D=3D587107=3D=3D by 0x401485: main (foo.f90:2) =3D=3D587107=3D=3D Address 0x4e57ac0 is 0 bytes inside a block of size 1 a= lloc'd =3D=3D587107=3D=3D at 0x484280F: malloc (vg_replace_malloc.c:442) =3D=3D587107=3D=3D by 0x4012C2: foo.1 (foo.f90:11) =3D=3D587107=3D=3D by 0x4013E1: run.2 (foo.f90:6) =3D=3D587107=3D=3D by 0x401258: MAIN__ (foo.f90:2) =3D=3D587107=3D=3D by 0x401485: main (foo.f90:2) =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D Invalid write of size 1 =3D=3D587107=3D=3D at 0x484F383: memmove (vg_replace_strmem.c:1410) =3D=3D587107=3D=3D by 0x401230: __copy_character_1.0 (foo.f90:1) =3D=3D587107=3D=3D by 0x401368: foo.1 (foo.f90:11) =3D=3D587107=3D=3D by 0x4013E1: run.2 (foo.f90:6) =3D=3D587107=3D=3D by 0x401258: MAIN__ (foo.f90:2) =3D=3D587107=3D=3D by 0x401485: main (foo.f90:2) =3D=3D587107=3D=3D Address 0x4e57ada is 10 bytes after a block of size 16 = in arena "client" =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D HEAP SUMMARY: =3D=3D587107=3D=3D in use at exit: 0 bytes in 0 blocks =3D=3D587107=3D=3D total heap usage: 22 allocs, 22 frees, 13,585 bytes al= located =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D All heap blocks were freed -- no leaks are possible =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D ERROR SUMMARY: 27 errors from 2 contexts (suppressed: 0 = from 0) =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D 1 errors in context 1 of 2: =3D=3D587107=3D=3D Invalid write of size 1 =3D=3D587107=3D=3D at 0x484F383: memmove (vg_replace_strmem.c:1410) =3D=3D587107=3D=3D by 0x401230: __copy_character_1.0 (foo.f90:1) =3D=3D587107=3D=3D by 0x401368: foo.1 (foo.f90:11) =3D=3D587107=3D=3D by 0x4013E1: run.2 (foo.f90:6) =3D=3D587107=3D=3D by 0x401258: MAIN__ (foo.f90:2) =3D=3D587107=3D=3D by 0x401485: main (foo.f90:2) =3D=3D587107=3D=3D Address 0x4e57ada is 10 bytes after a block of size 16 = in arena "client" =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D 26 errors in context 2 of 2: =3D=3D587107=3D=3D Invalid write of size 2 =3D=3D587107=3D=3D at 0x484F353: memmove (vg_replace_strmem.c:1410) =3D=3D587107=3D=3D by 0x401230: __copy_character_1.0 (foo.f90:1) =3D=3D587107=3D=3D by 0x401368: foo.1 (foo.f90:11) =3D=3D587107=3D=3D by 0x4013E1: run.2 (foo.f90:6) =3D=3D587107=3D=3D by 0x401258: MAIN__ (foo.f90:2) =3D=3D587107=3D=3D by 0x401485: main (foo.f90:2) =3D=3D587107=3D=3D Address 0x4e57ac0 is 0 bytes inside a block of size 1 a= lloc'd =3D=3D587107=3D=3D at 0x484280F: malloc (vg_replace_malloc.c:442) =3D=3D587107=3D=3D by 0x4012C2: foo.1 (foo.f90:11) =3D=3D587107=3D=3D by 0x4013E1: run.2 (foo.f90:6) =3D=3D587107=3D=3D by 0x401258: MAIN__ (foo.f90:2) =3D=3D587107=3D=3D by 0x401485: main (foo.f90:2) =3D=3D587107=3D=3D=20 =3D=3D587107=3D=3D ERROR SUMMARY: 27 errors from 2 contexts (suppressed: 0 = from 0)=