If I change the variable types by arrays of 1 int, I get the same result : https://godbolt.org/z/YWTvTPr4W You are right, it is certainly a UB, but it seems that the GCC optimizer treats scalars and arrays the same way, as soon as it can statically deduce the arithmetic goes past the end of the object memory space.