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)
Feb 6 2024, 2:07 AM
Unknown Object (File)
Dec 20 2023, 11:10 PM
Unknown Object (File)
Dec 20 2023, 4:37 AM
Unknown Object (File)
Dec 14 2023, 4:16 PM
Unknown Object (File)
Nov 5 2023, 7:53 PM
Unknown Object (File)
Oct 4 2023, 8:29 AM
Unknown Object (File)
Sep 14 2023, 8:42 PM
Unknown Object (File)
Aug 4 2023, 6:05 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.