use offsetof from stddef.h in chRegistry

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

use offsetof from stddef.h in chRegistry

Post 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
Post Reply