public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] sim/ppc: fix for operator precedence warning from clang
Date: Mon, 24 Oct 2022 16:19:57 +0000 (GMT)	[thread overview]
Message-ID: <20221024162001.A7716385840A@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e0b3df3b4d77706abf5f077477b2ca227fc4e9d1

commit e0b3df3b4d77706abf5f077477b2ca227fc4e9d1
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed Oct 19 15:12:57 2022 +0100

    sim/ppc: fix for operator precedence warning from clang
    
    In the ppc simulator, clang was warning about some code like this:
    
      busy_ptr->nr_writebacks = 1 + (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
    
    The warning was:
    
      operator '?:' has lower precedence than '+'; '+' will be evaluated first
    
    I suspect that this is not the original authors intention.
    PPC_ONE_BIT_SET_P is going to be 0 or 1, so if we evaluate the '+'
    first, the condition will always be non-zero, so true.  The whole
    expression could then be simplified to just '1', which doesn't make
    much sense.
    
    I suspect the answer the author was expecting was either 2 or 3.  Why
    they didn't just write:
    
      busy_ptr->nr_writebacks = (PPC_ONE_BIT_SET_P(out_vmask)) ? 2 : 3;
    
    I have no clue, however, to keep the structure of the code unchanged,
    I've updated things to:
    
      busy_ptr->nr_writebacks = 1 + (PPC_ONE_BIT_SET_P (out_vmask) ? 1 : 2);
    
    which silences the warning from clang, and is, I am guessing, what the
    original author intended.

Diff:
---
 sim/ppc/altivec.igen | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sim/ppc/altivec.igen b/sim/ppc/altivec.igen
index 63fe95a53d5..f3ad32d8825 100644
--- a/sim/ppc/altivec.igen
+++ b/sim/ppc/altivec.igen
@@ -231,7 +231,7 @@ void::model-function::ppc_insn_vr_vscr:itable_index index, model_data *model_ptr
 	busy_ptr->vscr_busy = 1;
 
 	if (out_vmask)
-	  busy_ptr->nr_writebacks = 1 + (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2;
+	  busy_ptr->nr_writebacks = 1 + (PPC_ONE_BIT_SET_P (out_vmask) ? 1 : 2);
 
 	if (WITH_TRACE && ppc_trace[trace_model])
 	  model_trace_altivec_make_busy(model_ptr, vr_mask, 0);

                 reply	other threads:[~2022-10-24 16:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221024162001.A7716385840A@sourceware.org \
    --to=aburgess@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).