On 12/09/2015 10:08 AM, Paolo Bonzini wrote:
Left shifts into the sign bit is a kind of overflow, and the
standard chooses to treat left shifts of negative values the
same way.
However, the -fwrapv option modifies the language to one where
integers are defined as two's complement---which also defines
entirely the behavior of shifts. Disable sanitization of left
shifts when -fwrapv is in effect, using the same logic as
instrument_si_overflow. The same change was proposed
for LLVM at https://llvm.org/bugs/show_bug.cgi?id=25552.
Bootstrapped/regtested x86_64-pc-linux-gnu. Ok for trunk, and for
GCC 5 branch after 5.3 is released?
Thanks,
Paolo
gcc:
PR sanitizer/68418
* c-family/c-ubsan.c (ubsan_instrument_shift): Disable
sanitization of left shifts for wrapping signed types as well.
gcc/testsuite:
PR sanitizer/68418
* gcc.dg/ubsan/c99-wrapv-shift-1.c,
gcc.dg/ubsan/c99-wrapv-shift-2.c: New testcases.
Thanks for the pointers to the earlier code that constrains the types.
FWIW Jan Beulich is twiddling the code leading to the
ubsan_instrument_shift call. In fact, your change may make Jan's change
safe :-)
OK for the trunk.
Thanks,
Jeff