From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4B0913842439; Mon, 1 Mar 2021 11:16:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B0913842439 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/99307] FAIL: gfortran.dg/class_assign_4.f90 -O0 execution test Date: Mon, 01 Mar 2021 11:16:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc Message-ID: In-Reply-To: References: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Mar 2021 11:16:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99307 Tobias Burnus changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #4 from Tobias Burnus --- (In reply to Dominique d'Humieres from comment #1) > Reduced test While -fsanitize=3Daddress,undefined does not find anything on x86_64-gnu-l= inux, I do see with valgrind: =3D=3D98347=3D=3D Invalid write of size 8 =3D=3D98347=3D=3D at 0x40397E: test_t1_ (ijd.f90:43) =3D=3D98347=3D=3D by 0x403A4E: MAIN__ (ijd.f90:60) =3D=3D98347=3D=3D by 0x403A85: main (ijd.f90:61) =3D=3D98347=3D=3D Address 0x4f55c98 is 8 bytes inside a block of size 12 a= lloc'd =3D=3D98347=3D=3D at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) =3D=3D98347=3D=3D by 0x402A6D: test_t1_ (ijd.f90:40) =3D=3D98347=3D=3D by 0x403A4E: MAIN__ (ijd.f90:60) =3D=3D98347=3D=3D by 0x403A85: main (ijd.f90:61) That's: x =3D [t2(1,10.0),t2(2,20.0),t2(3,30.0)] y =3D x x =3D realloc_t1 (y) ! <<< line 40, 8 bytes alloc'd inside block of size = 12 x =3D realloc_t1 (x) x =3D x(3:1:-1) + y x =3D [t2(1,10.0),t2(2,20.0),t2(3,30.0)] ! <<< line 43, invalid write of = size 8 Looking at the Fortran code, x and y have the dynamic type T2 until 'realloc_t1', which turns this into the dynamic type T1. In the last line (line 43), the dynamic type changes again to T2. In terms of memory usage: 3*8bytes before the first realloc_t1 call, then 3*4bytes and for the last line again 3*8bytes. * * * It seems as if the reallocation does not work properly if the dynamic type changes =E2=80=93 at least not if the required size increased in the assign= ment. (The valgrind message implies that shrinking did work in line 40.)=