Page MenuHomeFreeBSD

sys: declare bit sets unsigned

Authored by on Nov 1 2021, 11:07 PM.
Referenced Files
Unknown Object (File)
Sun, Jul 14, 2:32 PM
Unknown Object (File)
Sun, Jul 14, 2:20 PM
Unknown Object (File)
Tue, Jul 9, 5:48 AM
Unknown Object (File)
Thu, Jun 27, 6:13 PM
Unknown Object (File)
Jun 24 2024, 10:20 PM
Unknown Object (File)
May 18 2024, 5:43 PM
Unknown Object (File)
May 10 2024, 9:16 AM
Unknown Object (File)
Jan 11 2024, 6:23 AM



Substantially reduce the number of signed/unsigned issues (warnings if
enabled). While these are presently disabled for FreeBSD, being able to
enable another warning would be good.

Diff Detail

rS FreeBSD src repository - subversion
Lint Passed
No Test Coverage
Build Status
Buildable 42506
Build 39394: arc lint + arc unit

Event Timeline

This needs someone knowledgeable to look and some testing. I imagine most, if not all, uses of bit sets act as if unsigned; if any do not that would be a problem.

This is specifically targeting the CPU_FOREACH(i) macro. The current definition is:

#define CPU_FOREACH(i)                                                  \
        for ((i) = 0; (i) <= mp_maxid; (i)++)                           \
                if (!CPU_ABSENT((i)))

Trick with this is mp_maxid is a u_int which means the variable should be unsigned, otherwise you would get a warning about signed/unsigned comparison. Whereas since CPU_ABSENT(i) uses a bit set, unless the variable is signed, you get a warning about signed/unsigned conversion.

As a result without this, if -Wsign-conversion and -Wsign-compare are enabled every use of CPU_FOREACH() will result in a warning. With this, if the variable is unsigned there won't be any warnings.

Trying for more reviewers since D32793 has simply been sitting out here gathering dust. Seems pretty appropriate as unsigned is by far the more common use.

This revision is now accepted and ready to land.Dec 7 2022, 9:45 PM

I suspect unsigned is also better? Maybe @jrtc27 has thoughts? This is probably a user-facing API change since it affects cpuset_t in userland and possibly some other things.

Plain unsigned would change alignment and thus potentially ABI if someone's embedding this in a bigger structure. Changing from long to unsigned long should be fine as it's a private member and the representation isn't changing (and if you get crazy with LTO across this change I believe it should still be fine given long and unsigned long can alias).

This revision was automatically updated to reflect the committed changes.