C++ Logo

std-proposals

Advanced search

[std-proposals] Every variable is volatile, everything is laundered, no optimisation

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 25 Aug 2023 10:23:55 +0100
I've occasionally seen people use the compiler switch "-O0" with the
GNU compiler and also with LLVM.

What if we had a standardised way of marking a function as 'verbose'
to tell the compiler:
(1) All objects are to be treated as 'volatile'
(2) All pointers are automatically std::launder'ed
(3) No shortcuts are taken for aliasing

Something like as follows:

void Func(int *const p, double *const q) __verbose
{
    *p = 0;
    *q = 67.5;
    if ( *p ) DoSomething();
}

In the above function, normally the 'if' statement would be removed by
the optimiser. But since the function is marked as 'verbose', the two
pointers 'p' and 'q' are treated as pointing to volatile, and also
there's no anti-aliasing assumption between 'p' and 'q'.

Received on 2023-08-25 09:24:08