On Tue, 17 Nov 2015, Paolo Bonzini wrote: > GCC's -fwrapv option does not affect code generation for shifts > because currently GCC does not rely on the fact that certain > signed shifts trigger undefined behavior. However, the definition > of signed arithmetic overflow does extend to shifts; it is only > code generation that is limited to addition, subtraction and > multiplication.
It is part of the GNU C language, independent of -fwrapv, that shifts where the shift amount is in the range [0, width - 1] are fully defined (although ubsan will still sanitize those not defined in ISO C) - they are considered to be defined in terms of bits, not integers, so overflow is not a meaningful concept for them. -fwrapv *should* however affect division and modulo -1, although it doesn't at present (see bug 30484). -- Joseph S. Myers jos...@codesourcery.com