https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61502
--- Comment #49 from post+gcc at ralfj dot de ---
While checking whether some LLVM bugs also occur in GCC, I stumbled upon
another variant of this bug:
#include <stdio.h>
#include <stdint.h>
int main()
{
// also try swapping these
int x = 7777;
int y = 6666;
int* p = &y+1;
int* q = &x;
if (q == p) {
printf("pointers are equal!\n");
} else {
printf("pointers are NOT equal!\n");
}
uintptr_t dist = (((uintptr_t)p) - ((uintptr_t)q));
if (dist == 0) {
printf("Distance is 0 (i.e., poiners are equal)\n");
}
return 0;
}
(https://c.godbolt.org/z/TdGq4q5bK)
This prints
pointers are NOT equal!
Distance is 0 (i.e., poiners are equal)
which is logically inconsistent, i.e., a miscompilation. The pointers may be
equal or not, but they can't be sometimes equal and sometimes not just because
you look at them from a different direction.