https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87191

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amonakov at gcc dot gnu.org

--- Comment #1 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
It seems a bit strange to me to frame this in terms of ubsan. This is can be
reasonably diagnosed at compile time, so I'd prefer to frame this as missing
compile-time diagnostic first, and ubsan issue second (you'd need ubsan if the
offset was variable, but here it's a compile-time constant). It may be
appropriate to split the issue in two.

(note: we should diagnose regardless if 'a' is an array or not, in the example
it's an array to show how a mistake could be easy to make, in 'char a;
bar(&a+2);' the erroneous pointer of course looks unlikely to appear in real
practice)

At a minimum we should diagnose if offsetting a pointer to a toplevel object
not by 0/1 (ideally also if not by 0 and then dereferencing?), e.g.:

warning: creating out-of-bounds pointer based on complete object 'a'

If 'a' is not a toplevel object, but a field of a toplevel struct, invalid
pointer arithmetic still should be diagnosed when the resulting pointer is out
of bounds.

Reply via email to