[Bug c/27214] The C frontend introduces undefined pointer overflow

joseph at codesourcery dot com gcc-bugzilla@gcc.gnu.org
Wed Apr 19 17:15:00 GMT 2006



------- Comment #7 from joseph at codesourcery dot com  2006-04-19 17:15 -------
Subject: Re:  The C frontend introduces undefined pointer overflow

On Wed, 19 Apr 2006, rakdver at gcc dot gnu dot org wrote:

> Andrew, please do not mark PRs as invalid until the people involved in the
> discussion do not agree on the common interpretation of the standard.

This bug is about the interpretation of GCC's internal representation, not 
that of the standard.

Valid pointer offsets range from -SIZE_MAX to +SIZE_MAX - thus they 
require one bit more than pointers to store.  An internal representation 
not allowing for this range of offsets is problematic.

(As for the C language issues, subtraction of two pointers involves 
undefined behavior if the result is outside the range PTRDIFF_MIN to 
PTRDIFF_MAX, but you can still have an array using more than half of 
memory as long as you don't subtract pointers to elements too far apart.  
You could also have an array using almost all of memory, and subtract 
elements at opposite ends, as long as the element size is not 1; only the 
final result needs to be in range.  Such subtraction of pointers more 
than half of memory apart is not however an important case, and probably 
not one it's feasible to get right efficiently.)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27214



More information about the Gcc-bugs mailing list