From: Harald Anlauf Date: Fri, 26 Sep 2025 17:20:39 +0000 (+0200) Subject: Fortran: fix uninitialized read in testcase gfortran.dg/pdt_48.f03 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e6b4908c0402635c05e98bb1add0c4eaac44a02b;p=thirdparty%2Fgcc.git Fortran: fix uninitialized read in testcase gfortran.dg/pdt_48.f03 Running the testcase using valgrind --leak-check=full --track-origins=yes: ==28585== Conditional jump or move depends on uninitialised value(s) ==28585== at 0x400E19: MAIN__ (pdt_48.f03:48) ==28585== by 0x400EDB: main (pdt_48.f03:34) ==28585== Uninitialised value was created by a heap allocation ==28585== at 0x4841984: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==28585== by 0x400975: __pdt_m_MOD_add (pdt_48.f03:30) ==28585== by 0x400D84: MAIN__ (pdt_48.f03:44) ==28585== by 0x400EDB: main (pdt_48.f03:34) The cause was a partial initialization of a vector used in a subsequent addition. Initialize the remaining elements of the first vector by zero. gcc/testsuite/ChangeLog: * gfortran.dg/pdt_48.f03: --- diff --git a/gcc/testsuite/gfortran.dg/pdt_48.f03 b/gcc/testsuite/gfortran.dg/pdt_48.f03 index ed60b91c8c9..41b4b045cc1 100644 --- a/gcc/testsuite/gfortran.dg/pdt_48.f03 +++ b/gcc/testsuite/gfortran.dg/pdt_48.f03 @@ -16,17 +16,18 @@ contains integer :: c c=max(a,b) end function diy_max - + function add(a,b) result(c) type(vec(k=*)), intent(in) :: a,b type(vec(k=max(a%k,b%k))) :: c ! Fails !type(vec(k=diy_max(a%k,b%k))) :: c ! Worked with diy_max !type(vec(k=a%k+b%k)) :: c ! Worked with + - + c%foo(1:a%k)=a%foo + c%foo(a%k+1:) = 0 c%foo(1:b%k)=c%foo(1:b%k)+b%foo - if (c%k /= 5) stop 1 + if (c%k /= 5) stop 1 end function add end module pdt_m