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

MemorySanitizer: use-of-uninitialized-value

AlexRichert-RedLine
1,444 Views
When compiling with ifx in my GitHub CI based on the latest Intel OneAPI (2023.2.1), I get a bunch of code tests that fail, but I can make the issue go away by using 2023.1.0. Is there a way to pin down whether this is a compiler bug, an issue with the code, or both? I thought'-fno-sanitize' and/or '-nocheck' might make it go away but those did not work.
 

 

2: Uninitialized bytes in __interceptor_write at offset 0 inside [0x725000000000, 29)

2: ==8725==WARNING: MemorySanitizer: use-of-uninitialized-value

2: #0 0x4ac147 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x4ac147) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #1 0x4acebe (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x4acebe) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #2 0x496fd1 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x496fd1) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #3 0x4931f2 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x4931f2) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #4 0x489146 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x489146) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #5 0x40a578 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x40a578) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #6 0x7f01cc62ad8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)

2: #7 0x7f01cc62ae3f (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)

2: #8 0x40a444 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x40a444) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2:

2: Uninitialized value was created by a heap allocation

2: #0 0x416d36 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x416d36) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #1 0x490d72 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x490d72) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #2 0x4bbc49 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x4bbc49) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #3 0x4aa64a (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x4aa64a) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #4 0x492ca3 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x492ca3) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #5 0x489146 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x489146) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #6 0x40a578 (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x40a578) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576)

2: #7 0x7f01cc62ad8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)


SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/runner/work/NCEPLIBS-ip/NCEPLIBS-ip/ip/build/tests/test_earth_radius_4+0x4ac147) (BuildId: fb904d699e104f563ed258717dd32c7fcbbe7576) 

 

 

0 Kudos
6 Replies
Barbara_P_Intel
Employee
1,430 Views

There's a new compiler option with ifx 2023.2.0, "-check uninit". It uses the LLVM Memory Sanitizer to check for uninitialized variables.

If you use "-check all", "-check uninit" is enabled. According to the Developer Guide, "-check nouninit" disables it.

 

0 Kudos
AlexRichert-RedLine
1,420 Views

Take the following test program:

program my_program
print*,'Hello!'
print*,'Now we are here'
end program my_program

And I compile it with the following line:

/opt/intel/oneapi/compiler/2023.2.1/linux/bin/ifx -check all my_program.F90 -o my_program.x

 

When I run ./my_program.x, I get:

Hello!
Uninitialized bytes in __interceptor_write at offset 0 inside [0x725000000000, 10)
==20147==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x4a83c7 (/home/user/LLVM/SimpleTest/my_program.x+0x4a83c7) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#1 0x4a913e (/home/user/LLVM/SimpleTest/my_program.x+0x4a913e) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#2 0x493251 (/home/user/LLVM/SimpleTest/my_program.x+0x493251) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#3 0x48f472 (/home/user/LLVM/SimpleTest/my_program.x+0x48f472) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#4 0x488724 (/home/user/LLVM/SimpleTest/my_program.x+0x488724) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#5 0x40a0f8 (/home/user/LLVM/SimpleTest/my_program.x+0x40a0f8) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#6 0x7fbc47c3ad84 (/lib64/libc.so.6+0x3ad84) (BuildId: 1356e140fb964a20b0d2838960ee69ca6faeb034)
#7 0x409fcd (/home/user/LLVM/SimpleTest/my_program.x+0x409fcd) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)

Uninitialized value was created by a heap allocation
#0 0x4168b6 (/home/user/LLVM/SimpleTest/my_program.x+0x4168b6) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#1 0x48cff2 (/home/user/LLVM/SimpleTest/my_program.x+0x48cff2) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#2 0x4b7ec9 (/home/user/LLVM/SimpleTest/my_program.x+0x4b7ec9) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#3 0x4a68ca (/home/user/LLVM/SimpleTest/my_program.x+0x4a68ca) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#4 0x48ef23 (/home/user/LLVM/SimpleTest/my_program.x+0x48ef23) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#5 0x488724 (/home/user/LLVM/SimpleTest/my_program.x+0x488724) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#6 0x40a0f8 (/home/user/LLVM/SimpleTest/my_program.x+0x40a0f8) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
#7 0x7fbc47c3ad84 (/lib64/libc.so.6+0x3ad84) (BuildId: 1356e140fb964a20b0d2838960ee69ca6faeb034)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/user/LLVM/SimpleTest/my_program.x+0x4a83c7) (BuildId: 035a7267c7314bfa210b019fdcc67555458edc7e)
Exiting

 I suspect this is a bug?

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,375 Views

While this could be a bug...

A potential explanation is this may be an optimization feature whereby the startup code is performing a "first touch" of uninitialized data pages such that the Virtual memory pages are allocated to the page file and loaded into memory. (this also might not be the case).

 

The report: Uninitialized value was created by a heap allocation

Seams nonsensical since heap allocations are not initialized (unless a special version of the heap manager is, or should be, linked with the program).

 

Jim Dempsey

0 Kudos
Barbara_P_Intel
Employee
1,372 Views

I can't duplicate what you see with that simple reproducer.

+ ifx --version
ifx (IFX) 2023.2.0 20230622
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

+ ifx -check all alex.f90
+ a.out
 Hello!
 Now we are here

+ ifx -check uninit alex.f90
+ a.out
 Hello!
 Now we are here

 

0 Kudos
Barbara_P_Intel
Employee
1,365 Views

I modified the simple reproducer a bit and got a message from the MemorySanitizer. Note that I added "-g1" to the compile as per the documentation. (Scroll down the page a bit.) I got the line number in the code that way.

New reproducer

program my_program
print*,'Hello!'
print*,'Now we are here'
print *,' a ', a
end program my_program
+ ifx -what -g1 -check uninit alex2.f90
ifx: remark #10440: Note that use of a debug option without any optimization-level option will turnoff most compiler optimizations similar to use of '-O0'
 Intel(R) Fortran 23.0-1769.01
+ a.out
 Hello!
 Now we are here
==301066==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55df7c in cvt_ieee_s_to_text_ex (/nfs/pdx/disks/cts1/quad/bperz/05943398/a.out+0x55df7c) (BuildId: 3541b0e18812457fb4220fd5626a14caecb1239a)
    #1 0x4e1363 in format_real for_fmt_val.c
    #2 0x4e0152 in for__format_value (/nfs/pdx/disks/cts1/quad/bperz/05943398/a.out+0x4e0152) (BuildId: 3541b0e18812457fb4220fd5626a14caecb1239a)
    #3 0x4adc12 in for_write_seq_lis_xmit (/nfs/pdx/disks/cts1/quad/bperz/05943398/a.out+0x4adc12) (BuildId: 3541b0e18812457fb4220fd5626a14caecb1239a)
    #4 0x48aafe in MAIN__ /nfs/site/home/bperz/quad/05943398/alex2.f90:4:1
    #5 0x40bfe8 in main (/nfs/pdx/disks/cts1/quad/bperz/05943398/a.out+0x40bfe8) (BuildId: 3541b0e18812457fb4220fd5626a14caecb1239a)
    #6 0x7fe1bd12ab49 in __libc_start_call_main (/lib64/libc.so.6+0x27b49) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #7 0x7fe1bd12ac0a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x27c0a) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #8 0x40beb4 in _start (/nfs/pdx/disks/cts1/quad/bperz/05943398/a.out+0x40beb4) (BuildId: 3541b0e18812457fb4220fd5626a14caecb1239a)

  Uninitialized value was stored to memory at
    #0 0x48aa9a in MAIN__ /nfs/site/home/bperz/quad/05943398/alex2.f90:4:1
    #1 0x40bfe8 in main (/nfs/pdx/disks/cts1/quad/bperz/05943398/a.out+0x40bfe8) (BuildId: 3541b0e18812457fb4220fd5626a14caecb1239a)
    #2 0x7fe1bd12ab49 in __libc_start_call_main (/lib64/libc.so.6+0x27b49) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #3 0x7fe1bd12ac0a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x27c0a) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #4 0x40beb4 in _start (/nfs/pdx/disks/cts1/quad/bperz/05943398/a.out+0x40beb4) (BuildId: 3541b0e18812457fb4220fd5626a14caecb1239a)

  Uninitialized value was created by an allocation of 'my_program_$A' in the stack frame
    #0 0x48a4d4 in MAIN__ /nfs/site/home/bperz/quad/05943398/alex2.f90:1

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/nfs/pdx/disks/cts1/quad/bperz/05943398/a.out+0x55df7c) (BuildId: 3541b0e18812457fb4220fd5626a14caecb1239a) in cvt_ieee_s_to_text_ex
Exiting
0 Kudos
Barbara_P_Intel
Employee
1,248 Views

I recently learned that when using -check uninit (-check=all) with ifx there will be false positives from external libraries until they are rebuilt using –fsanitize=memory by ifx or icx.



0 Kudos
Reply