c++ - Valgrind:数学函数中的“条件跳转或移动取决于未初始化的值”
问题描述
我在我的 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 是否可以打印更详细的回溯。
推荐阅读
- php - 如何在我的 WooCommerce 商店的某个位置显示特定产品?
- javascript - 批量替换 HTML 文章值
- r - 循环重新采样数据框中两列的组合
- reactjs - 页面变得无响应并在控制台中出现 404 错误
- angular - 如何以角度从另一个不相关的组件重置表单
- android - 使用 firebase_messaging 自定义通知(Android 和 IOS)
- php - 一个字符串出现在另一个字符串中
- scala - Scala中基于String选择案例类
- python - Seaborn 散点图在 y-tick 中的重叠点
- r - R 中是否存在类似 tab() gen() 的语法?