char* pointer comparisons and clang12
Jacob Lifshay
programmerjake@gmail.com
Tue May 18 08:30:03 GMT 2021
On Tue, May 18, 2021, 00:21 Alan Modra via Binutils <binutils@sourceware.org>
wrote:
> Is it true that char* pointers cannot be compared using the relational
> operators <, >, <=, or >= except when they point into the same object
> or array (or one past)? Reading the C standard section 6.5.8 seems to
> say that. "In all other cases, the behavior is undefined." (I know
> enough computer architecture to know why the standard is written that
> way, so the question is rhetorical. The real question is below.)
>
> Are there compilers that optimize making use of that UB on flat memory
> architectures? Specifically, clang12. See pr27836.
>
Idk about when clang is in C mode, but at least for C++ mode clang gives
defined semantics to the < operator, since that's used to implement
std::less<T *>, which is required by the C++ standard to give a strict
total order on all pointers.
https://en.cppreference.com/w/cpp/utility/functional/less
libc++ 12 implementation of std::less:
https://github.com/llvm/llvm-project/blob/llvmorg-12.0.0/libcxx/include/__functional_base#L54
Jacob Lifshay
More information about the Binutils
mailing list