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
Unknown Object (File)
Sun, Feb 5, 2:02 PM
Unknown Object (File)
Dec 15 2022, 8:28 PM
Unknown Object (File)
Dec 12 2022, 2:18 AM
Unknown Object (File)
Dec 12 2022, 2:16 AM
Unknown Object (File)
Dec 12 2022, 2:16 AM
Unknown Object (File)
Dec 12 2022, 2:08 AM
Unknown Object (File)
Dec 4 2022, 4:21 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
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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.