-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Closed
Labels
compiler-rt:msanMemory sanitizerMemory sanitizerfalse-positiveWarning fires when it should notWarning fires when it should not
Description
Referencing the time obtained with timespec_get results in a false positive detection of an uninitialized variable by MemorySanitizer.
In contrast, the time obtained with clock_gettime works correctly without issues.
Environment
Ubuntu 24.04.3
Clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Reproduction steps
Compile and run the following program with the command below:
#include <time.h>
int main(void) {
struct timespec tv1, tv2;
clock_gettime(CLOCK_MONOTONIC, &tv1); /* OK */
if(tv1.tv_sec == 0) { return 0; }
timespec_get(&tv2, TIME_UTC); /* NG */
if(tv2.tv_sec == 0) { return 0; }
return 1;
}clang -fsanitize=memory -fsanitize-memory-track-origins -fPIE -fno-common test.c && ./a.out
Error message
==3898142==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55555561e57e in main (/tmp/a.out+0xca57e) (BuildId: 5c4a39751b635480181bc84a227f82ab740f925c)
#1 0x7ffff7c2a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#2 0x7ffff7c2a28a in __libc_start_main csu/../csu/libc-start.c:360:3
#3 0x555555586304 in _start (/tmp/a.out+0x32304) (BuildId: 5c4a39751b635480181bc84a227f82ab740f925c)
Uninitialized value was created by an allocation of 'tv2' in the stack frame
#0 0x55555561e435 in main (/tmp/a.out+0xca435) (BuildId: 5c4a39751b635480181bc84a227f82ab740f925c)
SUMMARY: MemorySanitizer: use-of-uninitialized-value (/tmp/a.out+0xca57e) (BuildId: 5c4a39751b635480181bc84a227f82ab740f925c) in main
Exiting
Metadata
Metadata
Assignees
Labels
compiler-rt:msanMemory sanitizerMemory sanitizerfalse-positiveWarning fires when it should notWarning fires when it should not