Page 1 of 1

use offsetof from stddef.h in chRegistry

Posted: Tue Jan 11, 2022 11:26 pm
by faisal
chRegistry defines its own _offsetof macro. That is technically UB, and clang compiler flags it as such. It's actually not possible to write an offsetof macro without UB, so compilers have their own implementation __builtin_offsetof which is avilable as offsetof in stddef.h .

Here's an example of the warning:

Code: Select all

../../ChibiOS_20.x.x/os/rt/src/chregistry.c:93:12: warning: performing pointer subtraction with a null pointer has undefined behavior [-Wnull-pointer-subtraction]
  (uint8_t)_offsetof(thread_t, hdr.pqueue.prio),


https://github.com/llvm-mirror/clang/bl ... def.h#L120
https://github.com/gcc-mirror/gcc/blob/ ... def.h#L406