https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126386
Bug ID: 126386
Summary: matmul in combination with multiplication and
transpose fails to correctly reallocate result array
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
Created attachment 65123
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65123&action=edit
Sourcefile triggering the bug
* A is rectangular matrix (ALLOCATABLE)
* x,y are allocatable arrays
The code performs the operation y = matmul(transpose(2*A),x) but y is already
allocated to a larger size than the result of the multiplication.
The reallocation of y to the correct size does not happen and y keeps the size
as it was before matmul.
In the attached source coed A has size (3,2), x has size (3), then the result
of
matmul(transpose(2*A),x) should have size (2). y is already allocated to size
(3). After the above operation it still has size (3) and no reallocation to
size (2) is performed.
Note: Removing the "2*" gives a correct result.
Compilation line:
gfortran -O3 reallocation_bug.f90 -o reallocation_bug
No Warnings/No errors produced
Operating System: Rocky Linux 8.10 (Green Obsidian)
Output of gfortran -v:
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/rh/gcc-toolset-15/root/usr/libexec/gcc/x86_64-redhat-linux/15/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,lto --prefix=/opt/rh/gcc-toolset-15/root/usr
--mandir=/opt/rh/gcc-toolset-15/root/usr/share/man
--infodir=/opt/rh/gcc-toolset-15/root/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-15.2.1-20260123/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
--enable-host-pie --enable-host-bind-now
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.2.1 20260123 (Red Hat 15.2.1-7) (GCC)
Note, the same bug appears also in 14.2.1
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/rh/gcc-toolset-14/root/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,lto --prefix=/opt/rh/gcc-toolset-14/root/usr
--mandir=/opt/rh/gcc-toolset-14/root/usr/share/man
--infodir=/opt/rh/gcc-toolset-14/root/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-14.2.1-20250110/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-offload-defaulted --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20250110 (Red Hat 14.2.1-7) (GCC)