This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Clarify that -fwrapv covers all signed arithmetic overflow
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Paolo Bonzini <bonzini at gnu dot org>
- Cc: <gcc-patches at gcc dot gnu dot org>, <gerald at pfeifer dot com>
- Date: Tue, 17 Nov 2015 12:58:40 +0000
- Subject: Re: [PATCH] Clarify that -fwrapv covers all signed arithmetic overflow
- Authentication-results: sourceware.org; auth=none
- References: <1447763566-2529-1-git-send-email-bonzini at gnu dot org>
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