C++ clang UBsan 抑制标志名称

C++ clang UBsan suppression flag name

运行 带有 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-suppressions

https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks

-fsanitize=implicit-integer-sign-change: Implicit conversion between integer types, if that changes the sign of the value. That is, if the the original value was negative and the new value is positive (or zero), or the original value was positive, and the new value is negative. Issues caught by this sanitizer are not undefined behavior, but are often unintentional.

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

Disabling Instrumentation with__attribute__((no_sanitize("undefined")))¶

You disable UBSan checks for particular functions with __attribute__((no_sanitize("undefined"))). You can use all values of -fsanitize= flag in this attribute, e.g. if your function deliberately contains possible signed integer overflow, you can use__attribute__((no_sanitize("signed-integer-overflow"))).

This attribute may not be supported by other compilers, so consider using it together with #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

我在 llvm cfe-dev 上得到了帮助mailing list

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

找出错误类型的名称