On Fri, Sep 05, 2025 at 11:07:01AM +0200, Florian Weimer wrote:
> > +int x = 0;
> > +
> > +int
> > +here_b_ub ()
> > +{
> > +  // missing return triggers UB (we must ignore the warning for this 
> > test). 
> > +}
> > +
> > +int
> > +main ()
> > +{
> > +  __builtin_printf (" start \n");
> > +  x += 42;
> > +  // Without this checkpoint the addition above is elided (along with the 
> > rest
> > +  // of main).
> > +  __builtin_observable_checkpoint ();
> > +  here_b_ub ();
> > +}
> 
> What happens if you have this?
> 
> static int x = 0;
> 
> Does the linkage matter?

It does.  If it is static, then it is just fine to optimize it away.  You
can see all the code that accesses it.

BTW, I think this testcase should show why expanding it into RTL as nothing
is not a good idea.  here_b_ub(); should be turned into
__builtin_unreachable(); call and there is no reason why to increment the
memory when it just invokes UB right after it without anything that could
observe the change.

        Jakub

Reply via email to