Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29111 Discussions

ifx 2024.1.0 -check uninit false positive when reading namelist with multiple lines

btrettel
Novice
2,060 Views

I recently upgraded to ifx 2024.1.0 and was excited to try the new MemorySanitizer. Unfortunately, there appears to be a false positive uninitialized value when reading namelist files if a namelist is spread across multiple lines. My guess is that ifx is checking whether each line has an uninitialized variable, when it should check at the end of the namelist.

To make the reproducer simpler, I tried putting the namelist in a character variable, but the bug doesn't appear in that case for me. The bug may require an external file. I have a file which passes and a file which fails. You can see in the output where the failure occurs.

Reproducer:

passes.nml:

 

&bug x=1 /

 

 

fails.nml:

 

&bug
x=1
/

 

 

bug0005.f90:

 

program bug0005

implicit none

integer :: nml_unit, x

namelist /bug/ x

open(newunit=nml_unit, file="passes.nml", status="old", action="read")
read(unit=nml_unit, nml=bug)
close(unit=nml_unit)

print *, x

open(newunit=nml_unit, file="fails.nml", status="old", action="read")
read(unit=nml_unit, nml=bug)
close(unit=nml_unit)

print *, x

end program bug0005

 

 

Since there are multiple files, I've attached them to this post (with the .nml files renamed to .txt as they couldn't be uploaded as .nml, and the code adjusted accordingly).

Command line log (I forgot the debug flag, so add that to get the precise line with the issue):

 

$ uname -a
Linux trident 5.15.0-102-generic #112~20.04.1-Ubuntu SMP Thu Mar 14 14:28:24 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
$ ifx --version
ifx (IFX) 2024.1.0 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

$ ifx -check all bug0005.f90
$ ./a.out
           1
==481024==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x5a5d34 in for__characterize_LUB_buffer (/home/ben/git/compiler-bugs/bug0005/a.out+0x5a5d34) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #1 0x5a6495 in for__get_s (/home/ben/git/compiler-bugs/bug0005/a.out+0x5a6495) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #2 0x4e3b70 in for__lex_getc for_rseq_nml.c
    #3 0x4e6aa9 in process_numeric for_rseq_nml.c
    #4 0x4db3c4 in for__nml_lex for_rseq_nml.c
    #5 0x4d1d07 in for_read_seq_nml (/home/ben/git/compiler-bugs/bug0005/a.out+0x4d1d07) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #6 0x491cc4 in MAIN__ (/home/ben/git/compiler-bugs/bug0005/a.out+0x491cc4) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #7 0x40cf98 in main (/home/ben/git/compiler-bugs/bug0005/a.out+0x40cf98) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #8 0x7ff85f74f082 in __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:308:16
    #9 0x40ce6d in _start (/home/ben/git/compiler-bugs/bug0005/a.out+0x40ce6d) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)

  Uninitialized value was created by a heap allocation
    #0 0x41dfa6 in malloc (/home/ben/git/compiler-bugs/bug0005/a.out+0x41dfa6) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #1 0x4fa532 in for__get_vm (/home/ben/git/compiler-bugs/bug0005/a.out+0x4fa532) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #2 0x57cce3 in for__open_proc (/home/ben/git/compiler-bugs/bug0005/a.out+0x57cce3) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #3 0x4b6b56 in for_open (/home/ben/git/compiler-bugs/bug0005/a.out+0x4b6b56) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #4 0x491b03 in MAIN__ (/home/ben/git/compiler-bugs/bug0005/a.out+0x491b03) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #5 0x40cf98 in main (/home/ben/git/compiler-bugs/bug0005/a.out+0x40cf98) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff)
    #6 0x7ff85f74f082 in __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:308:16

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/ben/git/compiler-bugs/bug0005/a.out+0x5a5d34) (BuildId: 5240da28924ef6c917af7a0b0e826efb945e26ff) in for__characterize_LUB_buffer
Exiting

 

Thanks.

7 Replies
Ron_Green
Moderator
2,026 Views

I do believe this is the first time someone has tried uninit checking with namelist IO.  It does look like we need a guard in our runtime library for this case.  I will open a bug report.  Thank you for sending this to us.

 

 

0 Kudos
Ron_Green
Moderator
2,016 Views

bug id CMPLRLIBS-34927


0 Kudos
btrettel
Novice
1,860 Views

A thought I had later: My reproducer wasn't made quite as I had intended, and seems to have exposed a different bug than what I thought I was showing. My intention was to show that if x is undefined before a namelist read, uninit checking worked only if the namelist is on one line. I did show that to myself, but that's not quite what my posted reproducer showed. In my reproducer, x was already defined by the second namelist read, where the error was. So the error is wrong for a second reason: x was already defined by that point.

0 Kudos
Ron_Green
Moderator
1,828 Views

I did investigate your code.  And yes I saw the same multi-line error. That is what the bug report is for, the multi-line namelist.  The bug is in our Fortran Runtime Library processing of the multi-line case.

Ron_Green
Moderator
1,605 Views

@btrettel we have a fix for your bug CMPLRLLVM-34927 

It went into our main code branch Friday.  This code branch is for the 2025.0 release due out in November.  It will NOT be in the 2024.2 update release that is due in July.  that code was frozen some weeks back and that fix didn't make it into 2024.2.0

 

Thank you for sending in this bug report!

0 Kudos
bellenlau
Novice
798 Views

Dear staff,

 

I am encountering a similar error in reading a namelist file, when compiling with ifx -check uninit (version 2025.0.4).

By using the same reproducer as above, but with x defined as "real" instead of "integer", I get the following error 

 

[lbellen1@login01 intel-env]$ ./bug.exe
==2227822==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x5e9277 in cvtas_a_to_s (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x5e9277) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #1 0x5dfadf in cvt_text_to_ieee_s_ex (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x5dfadf) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #2 0x5a8277 in for__cvt_value (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x5a8277) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #3 0x4ec2c3 in process_numeric for_rseq_nml.c
    #4 0x4dfde0 in for__nml_lex for_rseq_nml.c
    #5 0x4d603e in for_read_seq_nml (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x4d603e) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #6 0x497fab in MAIN__ (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x497fab) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #7 0x40be78 in main (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x40be78) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #8 0x7f50575047e4 in __libc_start_main (/lib64/libc.so.6+0x3a7e4) (BuildId: b81415c1738806b536fb1599d7af2d15bf6a86b7)
    #9 0x40bd4d in _start (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x40bd4d) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)

  Uninitialized value was created by a heap allocation
    #0 0x41df56 in malloc (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x41df56) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #1 0x4ff342 in for__get_vm (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x4ff342) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #2 0x4d5a47 in for_read_seq_nml (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x4d5a47) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #3 0x497fab in MAIN__ (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x497fab) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #4 0x40be78 in main (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x40be78) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78)
    #5 0x7f50575047e4 in __libc_start_main (/lib64/libc.so.6+0x3a7e4) (BuildId: b81415c1738806b536fb1599d7af2d15bf6a86b7)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/leonardo_scratch/large/userinternal/lbellen1/spack-env/intel-env/bug.exe+0x5e9277) (BuildId: b9756f4dcbb2921e29cd01dd25d16c481a769d78) in cvtas_a_to_s
Exiting

 

the modified reproducer

 

program bug0005

implicit none

integer :: nml_unit
real :: x

namelist /bug/ x

open(newunit=nml_unit, file="passes.nml", status="old", action="read")
read(unit=nml_unit, nml=bug)
close(unit=nml_unit)

print *, x

end program bug0005

 

 the modified input namelist

 

&bug
x=1.5
/

 

 How should I define the real, not to raise the error? 

 

Thank you for your attention

0 Kudos
Manodeep
Beginner
233 Views

I came across this thread while researching valgrind reported errors in `for_read_seq_nml` within application code. The code was compiled with ifx 2025.0.4.

 

Both examples run fine for me with 2025.0.4. However, valgrind identifies errors in both executables (regardless of the `-check all` compiler flag) . For both cases, valgrind identifies a memory leak:

 

==3035163==    at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3035163==    by 0x41FECB: for__get_vm (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/bug0005_nocheck)
==3035163==    by 0x40EEC9: for__get_free_newunit (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/bug0005_nocheck)
==3035163==    by 0x40FF16: for_open (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/bug0005_nocheck)
==3035163==    by 0x4044E9: MAIN__ (bug0005.f90:10)
==3035163==    by 0x4043DC: main (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/bug0005_nocheck)

 

The second case with the "real" var shows the following two use of uninitialised variables (which is not reported by ifx because

-check all implies -check all,nouninit). Here's what is reported by valgrind:

 

==3038689== Conditional jump or move depends on uninitialised value(s)
==3038689==    at 0x45453C: cvtas_a_to_s (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x451E08: cvt_text_to_ieee_s_ex (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x443C76: for__cvt_value (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x41B280: process_numeric (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x418105: for__nml_lex (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x416AD2: for_read_seq_nml (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x40457D: MAIN__ (new_bug0005.f90:11)
==3038689==    by 0x4043DC: main (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==  Uninitialised value was created by a heap allocation
==3038689==    at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3038689==    by 0x41FC4B: for__get_vm (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x4168B9: for_read_seq_nml (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x40457D: MAIN__ (new_bug0005.f90:11)
==3038689==    by 0x4043DC: main (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689== 
==3038689== Use of uninitialised value of size 8
==3038689==    at 0x45453E: cvtas_a_to_s (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x451E08: cvt_text_to_ieee_s_ex (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x443C76: for__cvt_value (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x41B280: process_numeric (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x418105: for__nml_lex (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x416AD2: for_read_seq_nml (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x40457D: MAIN__ (new_bug0005.f90:11)
==3038689==    by 0x4043DC: main (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==  Uninitialised value was created by a heap allocation
==3038689==    at 0x4C39185: malloc (vg_replace_malloc.c:442)
==3038689==    by 0x41FC4B: for__get_vm (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x4168B9: for_read_seq_nml (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689==    by 0x40457D: MAIN__ (new_bug0005.f90:11)
==3038689==    by 0x4043DC: main (in /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_nocheck)
==3038689== 
   1.500000    

 

These valgrind reported uninitialised error is what I am attempting to fix in my application - please consider this a bug report with a minimum failing example.

 

Thanks in advance,
Manodeep Sinha

 

P.S. I get the following error after compiling the "real" case with `-check all -check uninit` and running:

[~/temp/test_valgrind_reported_error_in_for-read-seq-nml @gadi01] ./new_bug0005_check_all_and_uninit 
==3124073==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x5e9397 in cvtas_a_to_s (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x5e9397) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #1 0x5dfbff in cvt_text_to_ieee_s_ex (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x5dfbff) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #2 0x5a8397 in for__cvt_value (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x5a8397) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #3 0x4ec3e3 in process_numeric for_rseq_nml.c
    #4 0x4dff00 in for__nml_lex for_rseq_nml.c
    #5 0x4d615e in for_read_seq_nml (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x4d615e) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #6 0x49806b in MAIN__ /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005.f90:11:5
    #7 0x40be08 in main (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x40be08) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #8 0x7fe38f8627e4 in __libc_start_main (/lib64/libc.so.6+0x3a7e4) (BuildId: 889235a2805b8308b2d0274921bbe1890e9a1986)
    #9 0x40bcdd in _start (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x40bcdd) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)

  Uninitialized value was created by a heap allocation
    #0 0x41dee6 in malloc (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x41dee6) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #1 0x4ff462 in for__get_vm (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x4ff462) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #2 0x4d5b67 in for_read_seq_nml (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x4d5b67) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #3 0x49806b in MAIN__ /home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005.f90:11:5
    #4 0x40be08 in main (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x40be08) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042)
    #5 0x7fe38f8627e4 in __libc_start_main (/lib64/libc.so.6+0x3a7e4) (BuildId: 889235a2805b8308b2d0274921bbe1890e9a1986)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/593/ms2335/temp/test_valgrind_reported_error_in_for-read-seq-nml/new_bug0005_check_all_and_uninit+0x5e9397) (BuildId: ddab31c3e12aa2adda0eeebea015a8f02f949042) in cvtas_a_to_s
Exiting
[~/temp/test_valgrind_reported_error_in_for-read-seq-nml @gadi01] ifx --version
ifx (IFX) 2025.0.4 20241205
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

 

 

0 Kudos
Reply