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)
Sat, Nov 9, 4:04 PM
Unknown Object (File)
Fri, Nov 8, 6:41 AM
Unknown Object (File)
Wed, Nov 6, 1:21 PM
Unknown Object (File)
Thu, Oct 31, 4:35 PM
Unknown Object (File)
Thu, Oct 31, 11:38 AM
Unknown Object (File)
Mon, Oct 28, 7:32 AM
Unknown Object (File)
Wed, Oct 16, 9:13 PM
Unknown Object (File)
Oct 15 2024, 12:27 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
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.