使用 Clang 的 UB 消毒器构建的程序的附加输出

Additional output from program built with the UB sanitizer of Clang

在我使用已经安装的 clang version 3.4 (tags/RELEASE_34/final) 的 travis CI 上,我用这个构建我的代码:

clang++ main.cpp -m64 -fsanitize=undefined -Werror -std=c++98 -pedantic -pedantic-errors -fvisibility=hidden -fstrict-aliasing -Weverything -Qunused-arguments -fcolor-diagnostics -O3 -DNDEBUG

(此命令取自cmake生成的compile_commands.json)

并且在程序退出后的输出中出现一些数字(如内存的十六进制表示):

00 00 00  10 70 fb 01 00 00 00 00  10 70 fb 01

我猜这是来自 UB sanitizer,因为当我使用 ASAN 构建时或根本没有使用任何 sanitizer 时,所有这些数字都不存在。

它们是什么意思?如何诊断我的 UB 错误(如果确实如此)?

我想当消毒剂遇到错误时它会使程序崩溃并打印一条带有解释的大消息。那这是什么?

这对我来说是一个破坏交易的因素,因为我将文本文件中的参考输出与当前构建的程序输出进行比较,而这种额外的输出会破坏一切。

我尝试在本地使用 Clang 3.6,这是我 Ubuntu 使用相同构建命令的默认设置,但是当我 运行 可执行文件时,我没有收到任何错误或此类额外输出。

here 是 travis 上的失败构建 - 我认为我的代码不相关,因为我的问题是消毒剂输出根本没有帮助。

我还使用 clang 3.5/3.6/3.7/3.8 启用了构建,结果 clang 3.5 的行为方式相同...

clang 3.6 但是输出更多!

  20 6c 98 01 00 00 00 00  20 6c 98 01 00 00 00 00  20 6c 98 01
              ^ 
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/bits/stl_tree.h:247:17: runtime error: upcast of address 0x00000115e090 with insufficient space for an object of type 'std::_Rb_tree_node<doctest::detail::TestData>'
0x00000115e090: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  20 6c 98 01 00 00 00 00  20 6c 98 01 00 00 00 00  20 6c 98 01

clang 3.7 和 3.8 给出与 3.6 相同的输出

我正在使用 libstdc++ 所以我将切换到 libc++ 以希望消除此错误(我认为这不是我的代码!)

我在 std::set<>...

中使用了一个简单的 TestData 结构