让我们考虑这个简单的测试程序:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char buf[256];
int i;
strcpy(buf,"Hello world!");
i = strlen(buf);
printf("Length of string is %d.\n",i);
return 0;
}
使用 Intel c++ 编译器进行编译并打开优化 (O3) 时,我从 valgrind 收到以下错误:
==8727== Conditional jump or move depends on uninitialised value(s)
==8727== at 0x4009EF: main (strtest.cpp:11)
==8727== Use of uninitialised value of size 8
==8727== at 0x4FC61ED: _itoa_word (in /lib64/libc-2.4.so)
==8727== by 0x4FC9317: vfprintf (in /lib64/libc-2.4.so)
==8727== by 0x4FD02A9: printf (in /lib64/libc-2.4.so)
==8727== by 0x400A09: main (strtest.cpp:13)
==8727== Conditional jump or move depends on uninitialised value(s)
==8727== at 0x4FC61F7: _itoa_word (in /lib64/libc-2.4.so)
==8727== by 0x4FC9317: vfprintf (in /lib64/libc-2.4.so)
==8727== by 0x4FD02A9: printf (in /lib64/libc-2.4.so)
==8727== by 0x400A09: main (strtest.cpp:13)
==8727== Conditional jump or move depends on uninitialised value(s)
==8727== at 0x4FC9386: vfprintf (in /lib64/libc-2.4.so)
==8727== by 0x4FD02A9: printf (in /lib64/libc-2.4.so)
==8727== by 0x400A09: main (strtest.cpp:13)
==8727== Conditional jump or move depends on uninitialised value(s)
==8727== at 0x4FC990F: vfprintf (in /lib64/libc-2.4.so)
==8727== by 0x4FD02A9: printf (in /lib64/libc-2.4.so)
==8727== by 0x400A09: main (strtest.cpp:13)
==8727== Conditional jump or move depends on uninitialised value(s)
==8727== at 0x4FC82F2: vfprintf (in /lib64/libc-2.4.so)
==8727== by 0x4FD02A9: printf (in /lib64/libc-2.4.so)
==8727== by 0x400A09: main (strtest.cpp:13)
我正在使用最新版本的 valgrind (3.6.1)。关闭优化 (-O0) 时不会发生这种情况,g++ 也不会发生这种情况。但是,它出现在我迄今为止尝试过的所有英特尔编译器(11.0、11.1、12)中。
似乎错误与字符串函数的 SIMD 加速有关,如C 字符串 strlen 和 Valgrind中讨论的那样。
据说这是 valgrind 中的一个错误,现在已修复。但是,尽管使用了最新的 valgrind 版本,我仍然有这些错误。有人知道这方面的帮助吗?