__restrict vis-a-vis a function optimization behavior of popular compilers
Consider the following function: int bar(const int* __restrict x, void g()) { int result = *x; g(); result += *x; return result; } Do we need to read twice from x because of the call to g() ? Or is the __restrict ion enough to guarantee the invocation of g() does not access/does not alter the value at address x ? At this link we see the most popular compilers have to say about this (GodBolt; language standard C99, platform AMD64): clang 7.0: Restriction respected. GCC 8.3: No restriction. MSVC 19.16: No restriction. Is clang rightly optimizing the second read away, or isn't it? I'm asking both