[PATCH 1/2] c++: Implement P1494 and P3641 Partial program correctness [PR119060].

Jakub Jelinek jakub@redhat.com
Fri Sep 5 09:15:48 GMT 2025


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



More information about the Libstdc++ mailing list