Page MenuHomeFreeBSD

tty_info: Avoid warning by using logical instead of bitwise operators
ClosedPublic

Authored by dim on Feb 6 2022, 5:45 PM.
Tags
None
Referenced Files
F82088543: D34186.id102433.diff
Thu, Apr 25, 9:52 AM
Unknown Object (File)
Mon, Apr 22, 5:16 AM
Unknown Object (File)
Wed, Apr 17, 4:39 AM
Unknown Object (File)
Sun, Mar 31, 1:19 AM
Unknown Object (File)
Sun, Mar 31, 1:05 AM
Unknown Object (File)
Feb 6 2024, 2:07 AM
Unknown Object (File)
Dec 20 2023, 11:10 PM
Unknown Object (File)
Dec 20 2023, 4:37 AM
Subscribers

Details

Summary

Since TD_IS_RUNNING() and TS_ON_RUNQ() are defined as logical
expressions involving '==', clang 14 warns about them being checked with
a bitwise operator instead of a logical one:

sys/kern/tty_info.c:124:9: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
        runa = TD_IS_RUNNING(td) | TD_ON_RUNQ(td);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                 ||
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:124:9: note: cast one or both operands to int to silence this warning
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:129:9: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
        runb = TD_IS_RUNNING(td2) | TD_ON_RUNQ(td2);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  ||
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^
sys/kern/tty_info.c:129:9: note: cast one or both operands to int to silence this warning
sys/sys/proc.h:562:27: note: expanded from macro 'TD_IS_RUNNING'
                                ^

Fix this by using logical operators instead. No functional change
intended.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 44309
Build 41197: arc lint + arc unit

Event Timeline

dim requested review of this revision.Feb 6 2022, 5:45 PM
This revision is now accepted and ready to land.Feb 6 2022, 6:00 PM

Looks like TESTAB expects boolean (0 and 1) values, too.

In D34186#773402, @cem wrote:

Looks like TESTAB expects boolean (0 and 1) values, too.

Well, the interesting thing is that this macro produces values 0 through 4, and it's a sort of weird shortcut to make the switch(TESTAB()) construct possible.

Strictly speaking you should do something ugly like:

#define TESTAB(a, b)    (((a)?1:0)<<1 | ((b)?1:0))
In D34186#773413, @dim wrote:
In D34186#773402, @cem wrote:

Looks like TESTAB expects boolean (0 and 1) values, too.

Well, the interesting thing is that this macro produces values 0 through 4, and it's a sort of weird shortcut to make the switch(TESTAB()) construct possible.

0-3. Yeah, it's a little weird.

Strictly speaking you should do something ugly like:

#define TESTAB(a, b)    (((a)?1:0)<<1 | ((b)?1:0))

Yeah, if a and b are not always going to be the result of boolean expressions. Here, they are.