On Thu, Aug 03, 2023 at 23:30:31 +0900, Rin Okuyama wrote:

> On 2023/08/03 23:23, Valery Ushakov wrote:
> > On Thu, Aug 03, 2023 at 13:33:27 +0000, Rin Okuyama wrote:
> > 
> > > -Wuse-after-free for GCC 12 is premature. It fires on a common idiom:
> > > 
> > >   newbuf = realloc(buf, size);
> > >   p = newbuf + (p - buf);
> > > 
> > > Let shut this up for GCC 12 (with hoping it gets improved for 13!).
> > 
> > C99 says
> > 
> >         J.2  Undefined behavior
> > 
> >         [#1]   The   behavior   is   undefined   in   the  following
> >         circumstances:
> > [...]
> >           -- The  value of a pointer to an object whose lifetime has
> >              ended is used (6.2.4).
> > 
> > 
> > Yes, for the "obvious" implementation of pointers as addresses the
> > above idiom happens to work, but it doesn't make that idiom any less
> > UB.
> 
> Ah, I only thought about "obvious" impl. Thank you for kind
> explanation! I will revert them for now.

We should fix those cases that gcc12 found.

While it may seem like a stretch of imagination (e.g. compiling C to
JVM or something like that, where the pointer is actually a nontrivial
object), "fat" function pointers on itanium were a mundane thing and
caused their fair share of problems for code that naively assumed
trivial "address-only" pointers.  I would imagine UB sanitizers will
trip up on that idiom too...

Thanks!

-uwe

Reply via email to