[cfe-dev] [UBsan suppression] implicit-integer-sign-change

Roman Lebedev via cfe-dev cfe-dev at lists.llvm.org
Fri Jan 25 10:25:04 PST 2019


On Fri, Jan 25, 2019 at 7:37 PM Pascal Cremer <cremer at or.uni-bonn.de> wrote:
>
> Thanks Roman,
>
> Here is a more detailed report:
>
> My program is
>
> int main() {
>      int i = 1073741824;
>      while (i > 0) {
>          i *= 2;
>      }
>
>      i = 139;
>      char c = i;
> }
>
> I use clang version 7.0.1
>
> My suppression file:
>
> #implicit-integer-sign-change:main.cpp
Let's take this one step back.
Why do you think that the sanitizer saying it's implicit-integer-sign-change?

$ export UBSAN_OPTIONS=report_error_type=1
$ ./main
main.cpp:4:12: runtime error: signed integer overflow: 1073741824 * 2
cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: signed-integer-overflow main.cpp:4:12 in
main.cpp:8:15: runtime error: implicit conversion from type 'int' of
value 139 (32-bit, signed) to type 'char' changed the value to -117
(8-bit, signed)
SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-truncation
main.cpp:8:15 in

And now:
$ cat suppression
signed-integer-overflow:main.cpp
implicit-integer-truncation:main.cpp
$ export UBSAN_OPTIONS=suppressions=suppression:report_error_type=1
$ ./main
$

Roman.

> signed-integer-overflow:main.cpp
>
> I start and compile in fish shell:
>
> export UBSAN_OPTIONS=suppressions=suppression; and clang++
> -fsanitize=address,integer main.cpp -o main; and ./main
>
> which gives the output:
>
> main.cpp:8:11: runtime error: implicit conversion from type 'int' of
> value 139 (32-bit, signed) to type 'char' changed the value to -117
> (8-bit, signed)
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior main.cpp:8:11 in
>
> If I remove the implicit-integer-sign-change suppression, I get as expected
>
> main.cpp:4:5: runtime error: signed integer overflow: 1073741824 * 2
> cannot be represented in type 'int'
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior main.cpp:4:5 in
> main.cpp:8:11: runtime error: implicit conversion from type 'int' of
> value 139 (32-bit, signed) to type 'char' changed the value to -117
> (8-bit, signed)
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior main.cpp:8:11 in
>
> If I have both suppressions active, I get:
>
> AddressSanitizer: failed to parse suppressions
>
> I double checked: changes in the suppression file need no recompilation.
>
> Pascal
>
> On 25/01/2019 14:21, Roman Lebedev wrote:
> > On Fri, Jan 25, 2019 at 4:07 PM Pascal Cremer via cfe-dev
> > <cfe-dev at lists.llvm.org> wrote:
> >> I would like to suppress implicit-integer-sign-change warnings which
> >> encounter in
> >>
> >> 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)
> > Can you please show the whole output, including "SUMMARY:
> > UndefinedBehaviorSanitizer: implicit-????" line?
> > (IIRC you need to also enable asan to get that line)
> >
> >> I tried with this line in my suppressions file (which works great for
> >> other types of warnings)
> >>
> >> implicit-integer-sign-change:/path/to/boost/*
> > Assuming that you are actually seeing the implicit-integer-sign-change
> > issue, according to
> > https://github.com/llvm-mirror/compiler-rt/blob/dd358a8a7ce65eb3189740d99b6a450605947aab/test/ubsan/TestCases/ImplicitConversion/integer-sign-change-blacklist.c#L12
> > that should work.
> >
> > I'm not sure, is that blacklist read at runtime or not, do you need to
> > recompile the code in order for it to be updated?
> >
> >> However, I get at runtime:
> >>
> >> UndefinedBehaviorSanitizer: failed to parse suppressions
> >>
> >> I also reported this on SO a while ago:
> >>
> >> https://stackoverflow.com/questions/53466501/c-clang-ubsan-suppression-flag-name
> >>
> >> Any help would be much appreciated.
> > Roman.
> >
> >> _______________________________________________
> >> cfe-dev mailing list
> >> cfe-dev at lists.llvm.org
> >> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list