public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] PR 81271: gcc/cp/lex.c:116: wrong condition ?
@ 2024-01-24  6:02 Jasmine Tang
  0 siblings, 0 replies; 3+ messages in thread
From: Jasmine Tang @ 2024-01-24  6:02 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 999 bytes --]

Change the style from & to && to reflect boolean result with boolean
operation (instead of bitwise operation)


From 10b501ffa8a11c7f10fd6e6ab5d9a876a321fe13 Mon Sep 17 00:00:00 2001
From: Jasmine <tanghocle456@gmail.com>
Date: Tue, 23 Jan 2024 21:18:13 -0800
Subject: [PATCH] Fix compiler warning: Boolean result is used in bitwise
 operation

---
 gcc/cp/lex.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc
index 1110db7f8d0..8d94ae1e7b1 100644
--- a/gcc/cp/lex.cc
+++ b/gcc/cp/lex.cc
@@ -136,8 +136,8 @@ void
 set_identifier_kind (tree id, cp_identifier_kind kind)
 {
   gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
-       & !IDENTIFIER_KIND_BIT_1 (id)
-       & !IDENTIFIER_KIND_BIT_0 (id));
+       && !IDENTIFIER_KIND_BIT_1 (id)
+       && !IDENTIFIER_KIND_BIT_0 (id));
   IDENTIFIER_KIND_BIT_2 (id) |= (kind >> 2) & 1;
   IDENTIFIER_KIND_BIT_1 (id) |= (kind >> 1) & 1;
   IDENTIFIER_KIND_BIT_0 (id) |= (kind >> 0) & 1;
-- 
2.34.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] PR 81271: gcc/cp/lex.c:116: wrong condition ?
  2024-01-24  5:57 Jasmine Tang
@ 2024-01-24 20:52 ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2024-01-24 20:52 UTC (permalink / raw)
  To: Jasmine Tang, gcc-patches

On 1/24/24 00:57, Jasmine Tang wrote:
> Change the style from & to && to reflect boolean result with boolean 
> operation (instead of bitwise operation)
> 
> David Binderman 2017-07-01 13:24:44 UTC
> 
> trunk/gcc/cp/lex.c:116]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.
> 
> Source code is
> 
>    gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
>                 & !IDENTIFIER_KIND_BIT_1 (id)
>                 & !IDENTIFIER_KIND_BIT_0 (id));
> 
> Maybe better code
> 
>    gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
>                 && !IDENTIFIER_KIND_BIT_1 (id)
>                 && !IDENTIFIER_KIND_BIT_0 (id));
> 

Since the _BIT_n macros all produce either 0 or 1, bitwise & has the 
same meaning as &&, except possibly faster because it doesn't involve 
the shortcut semantics of &&.

I notice the warning suggests "Clarify expression with parentheses."  I 
suspect that means along the lines of IDENTIFIER_KEYWORD_P and such in 
cp-tree.h, where the ! expression is parenthesized:

> #define IDENTIFIER_KEYWORD_P(NODE)              \
>   ((!IDENTIFIER_KIND_BIT_2 (NODE))              \
>    & (!IDENTIFIER_KIND_BIT_1 (NODE))            \
>    & IDENTIFIER_KIND_BIT_0 (NODE))

Does doing that quiet the warning?

Jason


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [patch] PR 81271: gcc/cp/lex.c:116: wrong condition ?
@ 2024-01-24  5:57 Jasmine Tang
  2024-01-24 20:52 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Jasmine Tang @ 2024-01-24  5:57 UTC (permalink / raw)
  To: gcc-patches


[-- Attachment #1.1: Type: text/plain, Size: 592 bytes --]

Change the style from & to && to reflect boolean result with boolean
operation (instead of bitwise operation)

David Binderman 2017-07-01 13:24:44 UTC

trunk/gcc/cp/lex.c:116]: (style) Boolean result is used in bitwise
operation. Clarify expression with parentheses.

Source code is

  gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
               & !IDENTIFIER_KIND_BIT_1 (id)
               & !IDENTIFIER_KIND_BIT_0 (id));

Maybe better code

  gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
               && !IDENTIFIER_KIND_BIT_1 (id)
               && !IDENTIFIER_KIND_BIT_0 (id));

[-- Attachment #2: 0001-Fix-compiler-warning-Boolean-result-is-used-in-bitwi.patch --]
[-- Type: text/x-patch, Size: 896 bytes --]

From 10b501ffa8a11c7f10fd6e6ab5d9a876a321fe13 Mon Sep 17 00:00:00 2001
From: Jasmine <tanghocle456@gmail.com>
Date: Tue, 23 Jan 2024 21:18:13 -0800
Subject: [PATCH] Fix compiler warning: Boolean result is used in bitwise
 operation

---
 gcc/cp/lex.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc
index 1110db7f8d0..8d94ae1e7b1 100644
--- a/gcc/cp/lex.cc
+++ b/gcc/cp/lex.cc
@@ -136,8 +136,8 @@ void
 set_identifier_kind (tree id, cp_identifier_kind kind)
 {
   gcc_checking_assert (!IDENTIFIER_KIND_BIT_2 (id)
-		       & !IDENTIFIER_KIND_BIT_1 (id)
-		       & !IDENTIFIER_KIND_BIT_0 (id));
+		       && !IDENTIFIER_KIND_BIT_1 (id)
+		       && !IDENTIFIER_KIND_BIT_0 (id));
   IDENTIFIER_KIND_BIT_2 (id) |= (kind >> 2) & 1;
   IDENTIFIER_KIND_BIT_1 (id) |= (kind >> 1) & 1;
   IDENTIFIER_KIND_BIT_0 (id) |= (kind >> 0) & 1;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-24 20:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-24  6:02 [patch] PR 81271: gcc/cp/lex.c:116: wrong condition ? Jasmine Tang
  -- strict thread matches above, loose matches on Subject: below --
2024-01-24  5:57 Jasmine Tang
2024-01-24 20:52 ` Jason Merrill

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).