public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] doc: clarify the situation with pointer arithmetic
@ 2020-01-20 15:50 Alexander Monakov
  2020-01-20 21:53 ` Sandra Loosemore
  2020-01-21  0:44 ` Joseph Myers
  0 siblings, 2 replies; 31+ messages in thread
From: Alexander Monakov @ 2020-01-20 15:50 UTC (permalink / raw)
  To: gcc-patches

Hi,

we have this paragraph in the documentation that attempts to prohibit something
that is allowed by the language.  Instead, I think we should say that this
generally should work and explain that a problem in GCC implementation
breaks this.

OK to apply?

Thanks.
Alexander


	* doc/implement-c.texi (Arrays and Pointers): Rewrite the paragraph
	about pointer-as-integer arithmetic.

diff --git a/gcc/doc/implement-c.texi b/gcc/doc/implement-c.texi
index 692297b69c4..beee2510670 100644
--- a/gcc/doc/implement-c.texi
+++ b/gcc/doc/implement-c.texi
@@ -401,11 +401,15 @@ pointer representation is smaller than the integer type, extends according
 to the signedness of the integer type if the pointer representation
 is larger than the integer type, otherwise the bits are unchanged.
 
-When casting from pointer to integer and back again, the resulting
-pointer must reference the same object as the original pointer, otherwise
-the behavior is undefined.  That is, one may not use integer arithmetic to
-avoid the undefined behavior of pointer arithmetic as proscribed in
-C99 and C11 6.5.6/8.
+Arithmetic on integers derived from pointers can produce a value such
+that casting it back produces a valid pointer corresponding to one of
+the original pointers.  Thus, integer arithmetic allows to express
+computations that might not be expressible as pointer arithmetic without
+undefined behavior.  However, at a certain point the distinction between
+pointers and integers is lost (when GCC translates from GIMPLE internal
+representation to RTL), but some optimizations still attempt to track
+pointer arithmetic beyond that point.  In some cases this may cause
+valid code to be incorrectly optimized.
 
 @item
 @cite{The size of the result of subtracting two pointers to elements

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

end of thread, other threads:[~2020-01-31 12:26 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 15:50 [PATCH] doc: clarify the situation with pointer arithmetic Alexander Monakov
2020-01-20 21:53 ` Sandra Loosemore
2020-01-20 23:11   ` Alexander Monakov
2020-01-21  0:44 ` Joseph Myers
2020-01-21 13:57   ` Alexander Monakov
2020-01-21 14:59     ` Richard Biener
2020-01-21 15:08       ` Alexander Monakov
2020-01-22  8:04         ` Richard Biener
2020-01-22 12:09           ` Martin Sebor
2020-01-23 13:47             ` Richard Biener
2020-01-24  0:06               ` Uecker, Martin
2020-01-27 15:14                 ` Richard Biener
2020-01-28  4:02                   ` Uecker, Martin
2020-01-28  8:28                     ` Alexander Monakov
2020-01-28 10:16                       ` Richard Biener
2020-01-28 13:28                         ` Uecker, Martin
2020-01-29  9:01                           ` Richard Biener
2020-01-29 14:28                             ` Uecker, Martin
2020-01-30  9:47                               ` Richard Biener
2020-01-30 14:42                                 ` Uecker, Martin
2020-01-30 16:59                                   ` Michael Matz
2020-01-30 17:27                                     ` Michael Matz
2020-01-30 17:29                                     ` Uecker, Martin
2020-01-31  9:31                                       ` Richard Biener
2020-01-31 12:26                                         ` Uecker, Martin
2020-01-31 13:22                                           ` Richard Biener
2020-01-28 13:08                       ` Uecker, Martin
2020-01-28 18:04                         ` Alexander Monakov
2020-01-22  1:37       ` Joseph Myers
2020-01-22  8:15         ` Richard Biener
2020-01-22  1:29     ` 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).