Date: Thu, 28 Aug 2025 21:28:04 +0000
> You need something that TBAA can be made aware of so that the
> compiler knows when it is necessary to perform reloads. The actual
> pointer value and number of elements aren't particularly important
> for that; they are more useful for sanitizers or for constant
> evaluation (if these operations were to be permitted during
> constant evaluation where UB has to be detected).
> For a more blunt instrument, see SG16 #67
> (Alias barriers; a replacement for the ICU hack) <https://github.com/sg16-unicode/sg16/issues/67>.
An alias barrier (or fence) might be a useful addition to the standard even if the standard were to relax the floating-point strict aliasing rule.
BTW, I tested the five Compiler Explorer links given in the github issue above with:
#if defined(USE_SIGNAL_FENCE)
#include <atomic>
#endif
and then in function f:
#elif defined(USE_SIGNAL_FENCE)
std::atomic_signal_fence(std::memory_order_acquire);
and all examples print Hi, as desired.
I have not thought through the implications nor the pros/cons compared to: asm volatile("" : : "rm"(p) : "memory");
Received on 2025-08-28 21:28:09