public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2] Clarify promises about undefined behavior with signed <<
@ 2015-11-25 13:25 Paolo Bonzini
  2015-11-25 17:14 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2015-11-25 13:25 UTC (permalink / raw)
  To: gcc-patches, joseph, gerald

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.

Make the documentation of -fwrapv consistent with the existing
text under -fstrict-overflow ("Using '-fwrapv' means that integer
signed overflow is fully defined: it wraps.").

Ok for trunk, and for GCC 5 branch after 5.3 is released?

Paolo

* doc/implement-c.texi (Integers Implementation): Make GCC's promises
about signed left shift stronger and clarify the cases when they're
broken.

Index: doc/implement-c.texi
===================================================================
--- doc/implement-c.texi	(revision 230466)
+++ doc/implement-c.texi	(working copy)
@@ -266,9 +266,11 @@
 immediately above the highest-value value bit.  Signed @samp{>>} acts
 on negative numbers by sign extension.
 
-GCC does not use the latitude given in C99 and C11 only to treat certain
-aspects of signed @samp{<<} as undefined, but this is subject to
-change.
+As an extension to the C language, GCC does not use the latitude given in
+C99 and C11 only to treat certain aspects of signed @samp{<<} as undefined.
+However, @option{-fsanitize=shift} (and @option{-fsanitize=undefined}) will
+diagnose such cases.  They are also diagnosed where constant
+expressions are required.
 
 @item
 @cite{The sign of the remainder on integer division (C90 6.3.5).}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] Clarify promises about undefined behavior with signed <<
  2015-11-25 13:25 [PATCH v2] Clarify promises about undefined behavior with signed << Paolo Bonzini
@ 2015-11-25 17:14 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2015-11-25 17:14 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: gcc-patches, gerald

On Wed, 25 Nov 2015, Paolo Bonzini wrote:

> * doc/implement-c.texi (Integers Implementation): Make GCC's promises
> about signed left shift stronger and clarify the cases when they're
> broken.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-25 17:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-25 13:25 [PATCH v2] Clarify promises about undefined behavior with signed << Paolo Bonzini
2015-11-25 17:14 ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).