【问题标题】:C++ clang UBsan suppression flag nameC++ clang UBsan 抑制标志名称
【发布时间】:2019-04-27 05:39:23
【问题描述】:

使用 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:整数类型之间的隐式转换,如果这改变了值的符号。也就是说,如果 原始值为负,新值为正(或 零),或者原值为正,而新值为 消极的。此消毒剂捕获的问题不是未定义的行为, 但往往是无意的。

【问题讨论】:

    标签: c++ clang++ ubsan


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      禁用检测 with__attribute__((no_sanitize("undefined")))¶

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

      其他编译器可能不支持此属性,因此请考虑 与 #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

      【讨论】:

      • __attribute__ 方式只是抑制 UBsan 消息的一种方式。运行时抑制是我想使用的替代方案,因为我不想更改 boost 库。至于unsigned-integer-overflow:这是我能够用于不同增强警告的标志。
      • 您是否尝试过使用signed-integer-overflow:path/to/boost/1_64_0/include/boost/iostreams/filter/gzip.hpp
      • 我个人非常怀疑您是否可以使用 signed-integer-overflow 以外的任何其他内容来抑制此特定错误,因为这显然是 UBSan 正在解决的问题
      • 我必须让你失望,signed-integer-overflow 确实被解析了,但 gzip.hpp 仍然被报告。
      • 这个问题专门针对运行时 UBSan 抑制。
      猜你喜欢
      • 1970-01-01
      • 2018-02-02
      • 2010-10-28
      • 1970-01-01
      • 2021-02-25
      • 2019-05-08
      • 2017-01-24
      • 2021-09-04
      • 2013-08-30
      相关资源
      最近更新 更多