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.
Posts: 374
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 44 times
Been thanked: 60 times

use offsetof from stddef.h in chRegistry

Postby faisal » Tue Jan 11, 2022 11:26 pm

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), ... def.h#L120 ... def.h#L406

Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 6 guests