[Bug tree-optimization/82946] member pointer defeats strlen optimization involving a string literal

joseph at codesourcery dot com gcc-bugzilla@gcc.gnu.org
Mon Nov 13 01:11:00 GMT 2017


--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Sat, 11 Nov 2017, msebor at gcc dot gnu.org wrote:

> other string literal) cannot be a valid representation of a pointer.  (The only
> way for a conforming program to obtain a valid pointer is by assigning to it
> the value of another valid pointer.  Even if the bit pattern of the literal
> "123" happened to match a valid address in a program, copying the literal into
> a pointer and then using that pointer is undefined.)

Well, GCC should support bare-metal programs that construct a valid 
pointer by casting an integer known to be the address of something, e.g. 
*(volatile int *)0xSOMETHING = VALUE; (where 0xSOMETHING is known to be 
e.g. a memory-mapped I/O address on that particular board).  That sort of 
thing should not be considered undefined in C as used in practice, at 
least as long as pointers to the object in question are only constructed 
from integers (rather than accessing the same object both by conversion 
from integer, and by having a linker script to give it a name).

More information about the Gcc-bugs mailing list