[gcc r16-4107] Fortran: fix uninitialized read in testcase gfortran.dg/pdt_48.f03
Harald Anlauf
anlauf@gcc.gnu.org
Fri Sep 26 17:25:43 GMT 2025
https://gcc.gnu.org/g:e6b4908c0402635c05e98bb1add0c4eaac44a02b
commit r16-4107-ge6b4908c0402635c05e98bb1add0c4eaac44a02b
Author: Harald Anlauf <anlauf@gmx.de>
Date: Fri Sep 26 19:20:39 2025 +0200
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:
---
gcc/testsuite/gfortran.dg/pdt_48.f03 | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/gcc/testsuite/gfortran.dg/pdt_48.f03 b/gcc/testsuite/gfortran.dg/pdt_48.f03
index ed60b91c8c90..41b4b045cc15 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
More information about the Gcc-cvs
mailing list