public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105164] New: new warning in clang, missing in gcc: -Wbitwise-instead-of-logical
@ 2022-04-05 16:16 dcb314 at hotmail dot com
2022-04-05 21:24 ` [Bug c++/105164] " dcb314 at hotmail dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-05 16:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105164
Bug ID: 105164
Summary: new warning in clang, missing in gcc:
-Wbitwise-instead-of-logical
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dcb314 at hotmail dot com
Target Milestone: ---
For this C++ code:
extern bool f1( int);
extern void f3( int);
void
f2( int n)
{
if (!f1(n) & !f1( n + 1))
f3( n - 1);
if (!f1(n) | !f1( n + 1))
f3( n + 1);
}
recent gcc trunk says not a lot:
$ /home/dcb/gcc/results/bin/g++ -g -O2 -Wall -Wextra -pedantic -c jul01a.cc
$
However, new clang-14 says:
$ clang++ -g -O2 -Wall -Wextra -pedantic -c jul01a.cc
jul01a.cc:8:6: warning: use of bitwise '&' with boolean operands
[-Wbitwise-instead-of-logical]
if (!f1(n) & !f1( n + 1))
^~~~~~~~~~~~~~~~~~~~
&&
jul01a.cc:8:6: note: cast one or both operands to int to silence this warning
jul01a.cc:11:6: warning: use of bitwise '|' with boolean operands
[-Wbitwise-instead-of-logical]
if (!f1(n) | !f1( n + 1))
^~~~~~~~~~~~~~~~~~~~
||
jul01a.cc:11:6: note: cast one or both operands to int to silence this warning
2 warnings generated.
$
Static analyser cppcheck also finds the problem:
$ /home/dcb/cppcheck/trunk.git/cppcheck --enable=all jul01a.cc
jul01a.cc:8:13: style: Boolean result is used in bitwise operation. Clarify
expression with parentheses. [clarifyCondition]
if (!f1(n) & !f1( n + 1))
^
jul01a.cc:11:13: style: Boolean result is used in bitwise operation. Clarify
expression with parentheses. [clarifyCondition]
if (!f1(n) | !f1( n + 1))
^
jul01a.cc:6:0: style: The function 'f2' is never used. [unusedFunction]
^
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105164] new warning in clang, missing in gcc: -Wbitwise-instead-of-logical
2022-04-05 16:16 [Bug c++/105164] New: new warning in clang, missing in gcc: -Wbitwise-instead-of-logical dcb314 at hotmail dot com
@ 2022-04-05 21:24 ` dcb314 at hotmail dot com
2022-04-06 7:51 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-05 21:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105164
--- Comment #1 from David Binderman <dcb314 at hotmail dot com> ---
Interestingly, I tried a build of gcc trunk with the new clang-14
and got many cases of this warning.
$ grep "warning:.*Wbitwise-instead-of-logical" mk.out | sort | uniq -c > /tmp/0
$ wc -l /tmp/0
16 /tmp/0
$ cat /tmp/0
1 :184:13: warning: use of bitwise '&' with boolean operands
[-Wbitwise-instead-of-logical]
1 ../../trunk.git/gcc/c-family/c-attribs.cc:2384:9: warning: use of
bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
1 ../../trunk.git/gcc/cp/decl.cc:11850:7: warning: use of bitwise '&'
with boolean operands [-Wbitwise-instead-of-logical]
2 ../../trunk.git/gcc/cp/lex.cc:124:24: warning: use of bitwise '&' with
boolean operands [-Wbitwise-instead-of-logical]
1 ../../trunk.git/gcc/cp/lex.cc:571:11: warning: use of bitwise '&' with
boolean operands [-Wbitwise-instead-of-logical]
1 ../../trunk.git/gcc/cp/module.cc:16843:11: warning: use of bitwise '&'
with boolean operands [-Wbitwise-instead-of-logical]
1 ../../trunk.git/gcc/cp/name-lookup.cc:7528:12: warning: use of bitwise
'&' with boolean operands [-Wbitwise-instead-of-logical]
1 ../../trunk.git/gcc/cp/parser.cc:883:11: warning: use of bitwise '&'
with boolean operands [-Wbitwise-instead-of-logical]
51 ../../trunk.git/gcc/function-abi.h:177:13: warning: use of bitwise '&'
with boolean operands [-Wbitwise-instead-of-logical]
49 ../../trunk.git/gcc/function-abi.h:184:13: warning: use of bitwise '&'
with boolean operands [-Wbitwise-instead-of-logical]
1
../../trunk.git/gcc/function-abi.h../../trunk.git/gcc/loop-unroll.cc::1841750::1319::
warning: warning: use of bitwise '&' with boolean operands
[-Wbitwise-instead-of-logical]array index 1 is past the end of the array (which
contains 1 element) [-Warray-bounds]
1 ../../trunk.git/gcc/gimple-ssa-sprintf.cc:1225:19: warning: use of
bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
1 ../../trunk.git/gcc/gimple-ssa-sprintf.cc:1664:12: warning: use of
bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
1 ../../trunk.git/gcc/rtl.h:../../trunk.git/gcc/function-abi.h:184:13:
warning: use of bitwise '&' with boolean operands
[-Wbitwise-instead-of-logical]
1 :../../trunk.git/gcc/rtl.h warning: :use of bitwise '&' with boolean
operands [-Wbitwise-instead-of-logical]1237
5 ../../trunk.git/gcc/rtl-ssa/internals.inl:436:25: warning: use of
bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
On the evidence of the source code of gcc, this new clang warning
might be worth implementing in gcc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105164] new warning in clang, missing in gcc: -Wbitwise-instead-of-logical
2022-04-05 16:16 [Bug c++/105164] New: new warning in clang, missing in gcc: -Wbitwise-instead-of-logical dcb314 at hotmail dot com
2022-04-05 21:24 ` [Bug c++/105164] " dcb314 at hotmail dot com
@ 2022-04-06 7:51 ` rguenth at gcc dot gnu.org
2022-04-06 9:08 ` marxin at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-06 7:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105164
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Keywords| |diagnostic
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105164] new warning in clang, missing in gcc: -Wbitwise-instead-of-logical
2022-04-05 16:16 [Bug c++/105164] New: new warning in clang, missing in gcc: -Wbitwise-instead-of-logical dcb314 at hotmail dot com
2022-04-05 21:24 ` [Bug c++/105164] " dcb314 at hotmail dot com
2022-04-06 7:51 ` rguenth at gcc dot gnu.org
@ 2022-04-06 9:08 ` marxin at gcc dot gnu.org
2022-04-06 12:12 ` marxin at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-04-06 9:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105164
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |marxin at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2022-04-06
Ever confirmed|0 |1
--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
I'm going to fix the warnings in GCC compiler.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105164] new warning in clang, missing in gcc: -Wbitwise-instead-of-logical
2022-04-05 16:16 [Bug c++/105164] New: new warning in clang, missing in gcc: -Wbitwise-instead-of-logical dcb314 at hotmail dot com
` (2 preceding siblings ...)
2022-04-06 9:08 ` marxin at gcc dot gnu.org
@ 2022-04-06 12:12 ` marxin at gcc dot gnu.org
2022-04-06 16:30 ` dcb314 at hotmail dot com
2022-04-06 16:32 ` dcb314 at hotmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-04-06 12:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105164
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|marxin at gcc dot gnu.org |unassigned at gcc dot gnu.org
Status|ASSIGNED |NEW
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Well, I doubt the warning is much useful.
There are situations where we can't use short-circuit evaluation:
gcc/c-family/c-attribs.cc:2384:
else if (TREE_CODE (decl) == FUNCTION_DECL
&& (((curalign = DECL_ALIGN (decl)) > bitalign)
| ((lastalign = DECL_ALIGN (last_decl)) > bitalign)))
or we want to quickly and flags of a struct:
gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
& !IDENTIFIER_KIND_BIT_1 (id)
& !IDENTIFIER_KIND_BIT_0 (id));
Note a different code is generated for situations like:
return foo() && bar() && baz ();
and
return foo() & bar() & baz ();
So I don't think we should change the code based on the warnings.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105164] new warning in clang, missing in gcc: -Wbitwise-instead-of-logical
2022-04-05 16:16 [Bug c++/105164] New: new warning in clang, missing in gcc: -Wbitwise-instead-of-logical dcb314 at hotmail dot com
` (3 preceding siblings ...)
2022-04-06 12:12 ` marxin at gcc dot gnu.org
@ 2022-04-06 16:30 ` dcb314 at hotmail dot com
2022-04-06 16:32 ` dcb314 at hotmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-06 16:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105164
--- Comment #4 from David Binderman <dcb314 at hotmail dot com> ---
I had a quick look at the two warnings for gcc/gimple-ssa-sprintf.cc
and they look like they could move from | to || happily.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105164] new warning in clang, missing in gcc: -Wbitwise-instead-of-logical
2022-04-05 16:16 [Bug c++/105164] New: new warning in clang, missing in gcc: -Wbitwise-instead-of-logical dcb314 at hotmail dot com
` (4 preceding siblings ...)
2022-04-06 16:30 ` dcb314 at hotmail dot com
@ 2022-04-06 16:32 ` dcb314 at hotmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-06 16:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105164
--- Comment #5 from David Binderman <dcb314 at hotmail dot com> ---
Same for trunk.git/gcc/rtl-ssa/internals.inl. The result is going into a bool,
so I see no need for |, only ||.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-04-06 16:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 16:16 [Bug c++/105164] New: new warning in clang, missing in gcc: -Wbitwise-instead-of-logical dcb314 at hotmail dot com
2022-04-05 21:24 ` [Bug c++/105164] " dcb314 at hotmail dot com
2022-04-06 7:51 ` rguenth at gcc dot gnu.org
2022-04-06 9:08 ` marxin at gcc dot gnu.org
2022-04-06 12:12 ` marxin at gcc dot gnu.org
2022-04-06 16:30 ` dcb314 at hotmail dot com
2022-04-06 16:32 ` dcb314 at hotmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).