[PATCH] Add pattern for pointer-diff on addresses with same base/offset (PR 94234)

Marc Glisse marc.glisse@inria.fr
Tue Jun 16 07:10:16 GMT 2020


On Tue, 16 Jun 2020, Feng Xue OS wrote:

> Here is an question about pointer operation: 
>
> Pointer is treated as unsigned in comparison operation, while distance between
> pointers is signed. Then we can not assume the below conclusion is true?
>
> (ptr_a > ptr_b)     =>     (ptr_a - ptr_b) >= 0

Yes you can. It is illegal to use either expression if ptr_a and ptr_b do 
not point inside the same object, and objects are not allowed to be larger 
than half the address space.

Comparing arbitrary pointers (not in the same object) is done with 
(uintptr_t)ptr_a > (uintptr_t)ptr_b.

-- 
Marc Glisse


More information about the Gcc-patches mailing list