When reading in a file, I usually check if read
returns a negative iostat
to see if I reached the end of the file.
If an intel compiler is used (2022 or 2023 versions of ifort and ifx), Valgrind complains that Conditional jump or move depends on uninitialised value(s)
. A minimal example would be:
program test_reading
implicit none
integer :: err_flag
character(len = 5) :: input
do
read (*, *, iostat = err_flag) input
if (err_flag < 0) exit ! EOF
end do
end program
For any arbitrary input (here I tested it with the letter 'e') I get the following warning from Valgrind:
$ valgrind ./a.out
==630192== Memcheck, a memory error detector
==630192== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==630192== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==630192== Command: ./a.out
==630192==
e
==630192== Conditional jump or move depends on uninitialised value(s)
==630192== at 0x41C8FD: for__characterize_LUB_buffer (in /path/to/a.out)
==630192== by 0x41CB70: for__get_s (in /path/to/a.out)
==630192== by 0x409495: for_read_seq_lis (in /path/to/a.out)
==630192== by 0x40422D: MAIN__ (test2.f90:6)
==630192== by 0x40419C: main (in /path/to/a.out)
==630192==
Why is that and what is the recommended way to read in a file until its end without any warnings from Valgrind?
I don't get this warning when I use gfortran. The optimization level does not have an influence.
This is due to Intel's implementation, and there is nothing you can do about it.
I remember similar Valgrind warnings resulting from write
(or print
) statements with ifort
.
Consider using a Valgrind suppression file that ignores for__characterize_LUB_buffer
.
See, for example, this answer.