On Fri, 2020-01-31 at 19:36 +0000, Dimitry Andric wrote: > Author: dim > Date: Fri Jan 31 19:36:14 2020 > New Revision: 357349 > URL: https://svnweb.freebsd.org/changeset/base/357349 > > Log: > Merge r357348 from the clang 10.0.0 import branch: > > Disable new clang 10.0.0 warnings about converting the result of shift > operations to a boolean in tpm(4): > > sys/dev/tpm/tpm_crb.c:301:32: error: converting the result of '<<' to a > boolean; did you mean '(1 << (0)) != 0'? [-Werror,-Wint-in-bool-context] > WR4(sc, TPM_CRB_CTRL_CANCEL, !TPM_CRB_CTRL_CANCEL_CMD); > ^ > sys/dev/tpm/tpm_crb.c:73:34: note: expanded from macro > 'TPM_CRB_CTRL_CANCEL_CMD' > #define TPM_CRB_CTRL_CANCEL_CMD BIT(0) > ^ > sys/dev/tpm/tpm20.h:60:19: note: expanded from macro 'BIT' > #define BIT(x) (1 << (x)) > ^ > > Such warnings can be useful in C++ contexts, but not so much in kernel > drivers, where this type of bit twiddling is commonplace. So disable it > for this case. >
I think the point of the compiler warning about shift in a boolean context is the same as warning about assignment in a boolean context. I.e, if (a << 3) might be a typo for if (a < 3) in the same way as "a = 3" might have been intended to be "a == 3". When this type of bit twiddling is used in drivers, it's almost always combined with an & or | operator, which I assume the compiler then won't complain about (or you would have seen thousands of warnings while compiling in dev/*). -- Ian _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"