From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 36B5E3870851; Tue, 23 Feb 2021 14:16:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36B5E3870851 From: "rpmcnally at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/99218] New: matmul on temporary array accesses invalid memory (segfault) Date: Tue, 23 Feb 2021 14:16:32 +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: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rpmcnally 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 attachments.created 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 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: Tue, 23 Feb 2021 14:16:32 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99218 Bug ID: 99218 Summary: matmul on temporary array accesses invalid memory (segfault) Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: rpmcnally at gmail dot com Target Milestone: --- Created attachment 50241 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50241&action=3Dedit Source file I traced a segfault in our code back to a matmul() where one of the argumen= ts is the the result of a transpose() call: fTmp(:) =3D matmul(transpose(G(:,:)), lambda(:)) Modifying the code to store the transpose in an intermediate variable appea= rs to resolve the segfault. I've reproduced the behavior in some standalone c= ode. While the standalone code doesn't segfault, running it under valgrind show= s a lot of invalid memory access. I do not see this behavior with my system GCC 4.8.5 or 7.3.0. I do see the memory issues with GCC 8.3.0, 9.3.0, and 10.2.0. The source file is attached. The output from valgrind is below. gfortran -Wall -Wextra -O0 -g -o issue issue.f90 =3D=3D13610=3D=3D Memcheck, a memory error detector =3D=3D13610=3D=3D Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward = et al. =3D=3D13610=3D=3D Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyr= ight info =3D=3D13610=3D=3D Command: ./issue =3D=3D13610=3D=3D=20 Testing Real with Transpose Inline =3D=3D13610=3D=3D Invalid write of size 4 =3D=3D13610=3D=3D at 0x4F3C754: matmul_r4_avx2 (matmul_r4.c:965) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e1f3d0 is 0 bytes after a block of size 2,048= alloc'd =3D=3D13610=3D=3D at 0x4C29F73: malloc (vg_replace_malloc.c:309) =3D=3D13610=3D=3D by 0x4F39602: matmul_r4_avx2 (matmul_r4.c:909) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid write of size 4 =3D=3D13610=3D=3D at 0x4F3C785: matmul_r4_avx2 (matmul_r4.c:965) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e1f7d0 is 960 bytes inside an unallocated blo= ck of size 4,176,848 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid write of size 4 =3D=3D13610=3D=3D at 0x4F3C7B5: matmul_r4_avx2 (matmul_r4.c:965) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e1fbd0 is 1,984 bytes inside an unallocated b= lock of size 4,176,848 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid write of size 4 =3D=3D13610=3D=3D at 0x4F3C7E6: matmul_r4_avx2 (matmul_r4.c:965) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e1ffd0 is 3,008 bytes inside an unallocated b= lock of size 4,176,848 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F3CE50: matmul_r4_avx2 (matmul_r4.c:1093) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e1f3d0 is 0 bytes after a block of size 2,048= alloc'd =3D=3D13610=3D=3D at 0x4C29F73: malloc (vg_replace_malloc.c:309) =3D=3D13610=3D=3D by 0x4F39602: matmul_r4_avx2 (matmul_r4.c:909) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F3CE5E: matmul_r4_avx2 (matmul_r4.c:1095) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e1f7d0 is 960 bytes inside an unallocated blo= ck of size 4,176,848 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F3D1A4: matmul_r4_avx2 (matmul_r4.c:1110) =3D=3D13610=3D=3D by 0x401873: test_real_transposeinline.3 (issue.f90:36) =3D=3D13610=3D=3D by 0x401932: main.4 (issue.f90:14) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e1fbd0 is 1,984 bytes inside an unallocated b= lock of size 4,176,848 in arena "client" =3D=3D13610=3D=3D=20 Testing Complex with Transpose Inline =3D=3D13610=3D=3D Invalid write of size 8 =3D=3D13610=3D=3D at 0x4F7A644: matmul_c4_avx2 (matmul_c4.c:965) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e20540 is 0 bytes after a block of size 4,096= alloc'd =3D=3D13610=3D=3D at 0x4C29F73: malloc (vg_replace_malloc.c:309) =3D=3D13610=3D=3D by 0x4F7617C: matmul_c4_avx2 (matmul_c4.c:909) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid write of size 8 =3D=3D13610=3D=3D at 0x4F7A64C: matmul_c4_avx2 (matmul_c4.c:965) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e20d40 is 1,984 bytes inside an unallocated b= lock of size 4,172,384 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid write of size 8 =3D=3D13610=3D=3D at 0x4F7A7C3: matmul_c4_avx2 (matmul_c4.c:965) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e21540 is 4,032 bytes inside an unallocated b= lock of size 4,172,384 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid write of size 8 =3D=3D13610=3D=3D at 0x4F7A7CC: matmul_c4_avx2 (matmul_c4.c:965) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e21d40 is 6,080 bytes inside an unallocated b= lock of size 4,172,384 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F7B0C2: matmul_c4_avx2 (matmul_c4.c:1092) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e20d44 is 1,988 bytes inside an unallocated b= lock of size 4,172,384 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F7B0E4: matmul_c4_avx2 (matmul_c4.c:1089) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e20540 is 0 bytes after a block of size 4,096= alloc'd =3D=3D13610=3D=3D at 0x4C29F73: malloc (vg_replace_malloc.c:309) =3D=3D13610=3D=3D by 0x4F7617C: matmul_c4_avx2 (matmul_c4.c:909) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F7B0EC: matmul_c4_avx2 (matmul_c4.c:1087) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e20d40 is 1,984 bytes inside an unallocated b= lock of size 4,172,384 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F7B0F1: matmul_c4_avx2 (matmul_c4.c:1087) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e20544 is 4 bytes after a block of size 4,096= alloc'd =3D=3D13610=3D=3D at 0x4C29F73: malloc (vg_replace_malloc.c:309) =3D=3D13610=3D=3D by 0x4F7617C: matmul_c4_avx2 (matmul_c4.c:909) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F7B833: matmul_c4_avx2 (matmul_c4.c:1110) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e21544 is 4,036 bytes inside an unallocated b= lock of size 4,172,384 in arena "client" =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D Invalid read of size 4 =3D=3D13610=3D=3D at 0x4F7B838: matmul_c4_avx2 (matmul_c4.c:1110) =3D=3D13610=3D=3D by 0x4014F4: test_complex_transposeinline.2 (issue.f90= :52) =3D=3D13610=3D=3D by 0x4019A4: main.4 (issue.f90:16) =3D=3D13610=3D=3D by 0x400D01: MAIN__ (issue.f90:5) =3D=3D13610=3D=3D by 0x401AC3: main (issue.f90:5) =3D=3D13610=3D=3D Address 0x5e21540 is 4,032 bytes inside an unallocated b= lock of size 4,172,384 in arena "client" =3D=3D13610=3D=3D=20 Testing Real with Transpose Variable Testing Complex with Transpose Variable =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D HEAP SUMMARY: =3D=3D13610=3D=3D in use at exit: 0 bytes in 0 blocks =3D=3D13610=3D=3D total heap usage: 39 allocs, 39 frees, 41,616 bytes all= ocated =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D All heap blocks were freed -- no leaks are possible =3D=3D13610=3D=3D=20 =3D=3D13610=3D=3D For lists of detected and suppressed errors, rerun with: = -s =3D=3D13610=3D=3D ERROR SUMMARY: 20 errors from 17 contexts (suppressed: 0 = from 0)=