x86: Add () to silence GCC 5

Message ID CAMe9rOoUtqCn5mYbm2CzRdurJzCr6f85Q5inxAOnvnj8xkmT8Q@mail.gmail.com
State New
Headers show
Series
  • x86: Add () to silence GCC 5
Related show

Commit Message

Luis Machado via Binutils April 27, 2021, 3:20 p.m.
On Tue, Apr 27, 2021 at 12:42 AM Jan Beulich via Binutils
<binutils@sourceware.org> wrote:
>

> On 26.04.2021 19:08, Joseph Myers wrote:

> > On Fri, 23 Apr 2021, Jan Beulich via Binutils wrote:

> >

> >> +              && !i.prefix[ADDR_PREFIX] != (flag_code == CODE_32BIT))

> >

> > I'm seeing a -Werror build failure (with GCC 5):

> >

> > /scratch/jmyers/glibc-bot/src/binutils/gas/config/tc-i386.c: In function 'optimize_encoding':

> > /scratch/jmyers/glibc-bot/src/binutils/gas/config/tc-i386.c:4152:31: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]

> >      && !i.prefix[ADDR_PREFIX] != (flag_code == CODE_32BIT))

>

> Well, not sure what to say. For one I consider the warning bogus. It

> should be up to the programmer how booleans on either side of

> relational operators get expressed. ! is no worse or better than ==

> or any other relational operator. For example, personally I consider

>

>      && !i.prefix[ADDR_PREFIX] == !(flag_code == CODE_32BIT))

>

> worse.

>

> And then, if you think this is worthwhile fixing (which probably it

> is, as we're unlikely to want to state that binutils don't build

> with gcc 5), how about you submit a patch, since you've noticed the

> issue and hence you are in a position to check whether whatever

> possible change doesn't again trigger some kind of (bogus or not)

> warning?

>

> Jan


I am checking in this to silence GCC 5.

-- 
H.J.

Comments

Luis Machado via Binutils April 27, 2021, 3:34 p.m. | #1
On 27.04.2021 17:20, H.J. Lu wrote:
> On Tue, Apr 27, 2021 at 12:42 AM Jan Beulich via Binutils

> <binutils@sourceware.org> wrote:

>>

>> On 26.04.2021 19:08, Joseph Myers wrote:

>>> On Fri, 23 Apr 2021, Jan Beulich via Binutils wrote:

>>>

>>>> +              && !i.prefix[ADDR_PREFIX] != (flag_code == CODE_32BIT))

>>>

>>> I'm seeing a -Werror build failure (with GCC 5):

>>>

>>> /scratch/jmyers/glibc-bot/src/binutils/gas/config/tc-i386.c: In function 'optimize_encoding':

>>> /scratch/jmyers/glibc-bot/src/binutils/gas/config/tc-i386.c:4152:31: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]

>>>      && !i.prefix[ADDR_PREFIX] != (flag_code == CODE_32BIT))

>>

>> Well, not sure what to say. For one I consider the warning bogus. It

>> should be up to the programmer how booleans on either side of

>> relational operators get expressed. ! is no worse or better than ==

>> or any other relational operator. For example, personally I consider

>>

>>      && !i.prefix[ADDR_PREFIX] == !(flag_code == CODE_32BIT))

>>

>> worse.

>>

>> And then, if you think this is worthwhile fixing (which probably it

>> is, as we're unlikely to want to state that binutils don't build

>> with gcc 5), how about you submit a patch, since you've noticed the

>> issue and hence you are in a position to check whether whatever

>> possible change doesn't again trigger some kind of (bogus or not)

>> warning?

> 

> I am checking in this to silence GCC 5.


Interesting, thanks. I'll try to watch out for similar cases in
future changes of mine, but I don't think I can promise to avoid
introduction of further ones.

Jan

Patch

From 60cfa10c36668e3298bab35e9dc86624f3ddf61a Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 27 Apr 2021 08:16:55 -0700
Subject: [PATCH] x86: Add () to silence GCC 5

Add () to !i.prefix[ADDR_PREFIX] to silence GCC 5:

gas/config/tc-i386.c:4152:31: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
     && !i.prefix[ADDR_PREFIX] != (flag_code == CODE_32BIT))
                               ^

	* config/tc-i386.c (optimize_encoding): Add () to silence GCC 5.
---
 gas/ChangeLog        | 4 ++++
 gas/config/tc-i386.c | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 03ba1964176..64378d10666 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,7 @@ 
+2021-04-27  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* config/tc-i386.c (optimize_encoding): Add () to silence GCC 5.
+
 2021-04-26  Jan Beulich  <jbeulich@suse.com>
 
 	* config/tc-i386.c (tc_gen_reloc): Check IS_ELF for
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 99f990464cd..88b601ff742 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -4149,7 +4149,9 @@  optimize_encoding (void)
 	      if (i.op[0].disps
 		  && i.op[0].disps->X_op == O_constant
 		  && i.op[1].regs->reg_type.bitfield.dword
-		  && !i.prefix[ADDR_PREFIX] != (flag_code == CODE_32BIT))
+		  /* NB: Add () to !i.prefix[ADDR_PREFIX] to silence
+		     GCC 5. */
+		  && (!i.prefix[ADDR_PREFIX]) != (flag_code == CODE_32BIT))
 		i.op[0].disps->X_add_number &= 0xffff;
 	    }
 
-- 
2.31.1