Valgrind:数学函数中的 "Conditional jump or move depends on uninitialised value(s)"

Valgrind: "Conditional jump or move depends on uninitialised value(s)" in math functions

我找不到导致我的 C++ 程序中的条件跳转的原因。我正在用 Valgrind 3.11.0 测试它,程序是用 gcc 5.4.0 编译的。

问题是这些条件跳转似乎发生在使用 AVX 指令的三角函数中,但也发生在 sqrt() 函数中,而不是在我的代码中。下面我粘贴了 Valgrind 消息:

==29490== Conditional jump or move depends on uninitialised value(s)
==29490==    at 0x54436DD: __sin_avx (s_sin.c:482)
...

==29490== Conditional jump or move depends on uninitialised value(s)
==29490==    at 0x54449D4: __cos_avx (s_sin.c:597)
...
==28458== Conditional jump or move depends on uninitialised value(s)
==28458==    at 0x543F7B7: __ieee754_atan2_avx (e_atan2.c:434)
==28458==    by 0x53F746F: atan2 (w_atan2.c:36)
...

==29490== Conditional jump or move depends on uninitialised value(s)
==29490==    at 0x53F8258: sqrt (w_sqrt.c:27)

希望有人能帮忙。谢谢

atan2这样的函数在内部将参数与一些常量进行比较(例如,if (x < 0) ...)。如果你传递的是一个未初始化的值,valgrind 会正确地抱怨(例如尝试 double x, y; atan2(x, y);)。问题不在于数学函数,而在于调用者。

您需要确保参数已正确初始化,这可能很重要,因为未初始化的值可能会从意想不到的地方传播开来。尝试使用调试符号编译您的代码,看看 valgrind 是否可以打印更详细的回溯。