As per C standard, the result of signed integer overflow is undefined. See a short summary on cppreference
Because of that, whatever GCC is doing is technically correct.