> On 5 Sep 2025, at 10:15, Jakub Jelinek <ja...@redhat.com> wrote:
> 
> 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.

Well the intent of the testcase was to demonstate that we correctly prevent
time-traveling UB from doing so.  We cannot use any output calls since those
already behave as checkpoints - manipulating a global seemed a reasonable
solution.

Iain

> 
>       Jakub
> 

Reply via email to