C++clang UBsan抑制标志名称



使用clang的ubsan从boost版本1.64运行gzip.hpp代码会给出以下消息:

path/to/boost/1_64_0/include/boost/iostreams/filter/gzip.hpp:674:16: runtime error: implicit conversion from type 'int' of value 139 (32-bit, signed) to type 'char' changed the value to -117 (8-bit, signed)
#0 0x7fed40b77bc2 in boost::iostreams::basic_gzip_compressor<std::allocator<char> >::basic_gzip_compressor(boost::iostreams::gzip_params const&, long)

我想用抑制文件来抑制这个。对于其他警告,这已经奏效:

unsigned-integer-overflow:path/to/boost/*

在这种情况下,我希望这应该工作

implicit-integer-sign-change:/lfs/vlsi/tools/boost/*

但它在运行时提供

UndefinedBehaviorSanitizer: failed to parse suppressions

这面疗养旗帜的正确名称是什么?

另请参阅:https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#runtime-抑制

和来自https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-检查

-fsanitize=隐式整数符号更改:整数类型之间的隐式转换,如果这会更改值的符号。也就是说,如果原始值为负值,而新值为正值(或零(,或者原始值为正,而新值为消极的此消毒液发现的问题不是未定义的行为,但往往是无意的。

我在llvm cfe dev邮件列表上得到了帮助

TLDR:警告类型的名称不是implicit-integer-sign-change,而是可以按预期抑制的implicit-integer-truncation。错误类型的名称可以使用export UBSAN_OPTIONS=report_error_type=1找到。

根据您正在阅读的文档,您可以使用以下步骤抑制UBSan消息:

禁用仪器 ,带有__attribute__((no_sisalize("未定义"((¶

您禁用特定功能的UBSan检查使用__attribute__((no_sanitize("undefined"))).可以使用所有值of-fsanitize=此属性中的标志,例如,如果您的函数故意包含可能的有符号整数溢出,您可以use__attribute__((no_sanize("有符号整数溢出"(((。

其他编译器可能不支持此属性,因此请考虑将其与#ifdefined(clang(一起使用。

因此,您应该做的是:检查同一页中的文档中要抑制的内容,并将其与use__attribute__((no_sanitize("here_goes_checks_you_want_to_suppress"))).use__attribute__((no_sanitize("undefined"))).结合以完全禁用UBSan。

除此之外,UBSan似乎正在引发SIGNED整数溢出,而您正试图抑制UNSIGNED整数溢出。

链接:https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html

最新更新