[PATCH] D38971: Enhance libsanitizer support for invalid-pointer-pair.

Martin Liška via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 02:43:28 PDT 2017


marxin added a comment.

> What does the standard say about comparisons with zero and subtracting zero from a pointer?

I summarize that for both languages C and C++

**C**:

- Relational operators: §6.5.8 - point 5 - there's described that it's defined basically for same objects; last sentence says:

> In all other cases, the behavior is undefined.

- Additive operators - §6.5.6 - point 9 - it basically says that it's defined if it's representative in **ptrdiff_t** type

**C++**:

- Relational operators: §5.9.3 - it defined explicitly which situations are defined - comparison of pointers to a different object

and also comparison with null pointer is not listed. Thus I consider it as invalid.

- Additive operators: §5.7.6 - quite clear:

> Unless both pointers point to elements of the same array object, or

one past the last element of the array object, the behavior is undefined.

That said, we should probably skip instrumentation of additive operators in C. What do you think @kcc and @jakubjelinek
about 3 levels of detect_invalid_pointer_pairs ?


https://reviews.llvm.org/D38971





More information about the llvm-commits mailing list