char* pointer comparisons and clang12

Alan Modra amodra@gmail.com
Tue May 11 06:06:00 GMT 2021


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.

We use pointer comparisons like the one at binutils/dwarf.c:8802 in
many places in binutils to test a value derived from user imput
against an array bound.  If this UB is a concern it seems like all of
those tests will need rewriting.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list