Depending on the context, the compiler may be able to determine that memory accessed via some pointers do not overlap, even without the restrict
keyword.
For example, the compiler can determine that pointers to different stack objects cannot overlap. See https://godbolt.org/z/cs7MMoehW
In the function store_restrict
, the compiler is able to remove the first store to a (*a = 0
) thanks to restrict
. The same optimization cannot be done in store_without_restrict
. In inline_store
, pointers to different stack objects are passed to store_without_restrict
and after inlining the compiler can prove the pointers do not overlap and can perform the optimization on the inlined code, without requiring restrict
.
Also, for some optimizations, the compiler can generate runtime checks if it cannot prove statically that the accessed memory does not overlap.