This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Clarify that -fwrapv covers all signed arithmetic overflow


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
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]