C++ clang UBsan suppression flag name

2.4k views Asked by At

Running the gzip.hpp code from boost version 1.64 with clang's ubsan gives the following message:

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)

I'd like to suppress this with with a suppression file. For other warnings this has worked:

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

In this case I would expect that this should work

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

but it gives at runtime

UndefinedBehaviorSanitizer: failed to parse suppressions

What is the right name of this sanatizer flag?

See also: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#runtime-suppressions

and from 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.

2

There are 2 answers

0
Elrond1337 On BEST ANSWER

I have been helped on the llvm cfe-dev mailing list

TLDR: The name of the warning type is not implicit-integer-sign-change but instead implicit-integer-truncation which can be suppressed as expected. The name of the error type can be found out using export UBSAN_OPTIONS=report_error_type=1.

6
Ezequiel Barbosa On

According to this very documentation you're reading you suppress UBSan messages using the following step :

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).

So what you should do is: check the documentation in the same page for what you want to suppress and conjugate it with use__attribute__((no_sanitize("here_goes_checks_you_want_to_suppress"))). or use__attribute__((no_sanitize("undefined"))). to disable UBSan altogether.

Apart of that seems UBSan is throwing a SIGNED integer overflow and you're trying to suppress UNSIGNED integer overflow.

LINKS: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html