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
F103471098: D34186.id102433.diff
Mon, Nov 25, 11:16 AM
Unknown Object (File)
Sat, Nov 23, 1:23 PM
Unknown Object (File)
Fri, Nov 22, 8:15 PM
Unknown Object (File)
Thu, Nov 21, 5:40 PM
Unknown Object (File)
Wed, Nov 20, 9:46 PM
Unknown Object (File)
Wed, Nov 20, 4:04 PM
Unknown Object (File)
Wed, Nov 20, 9:03 AM
Unknown Object (File)
Fri, Nov 15, 4:00 PM
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.