[05/10] sim/ppc: fix for operator precedence warning from clang

Message ID bad971a3bda505005d02a880cd1b6c9eca87d47e.1666192979.git.aburgess@redhat.com
State Committed
Headers
Series Building the sim/ tree with clang |

Commit Message

Andrew Burgess Oct. 19, 2022, 3:24 p.m. UTC
  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.
---
 sim/ppc/altivec.igen | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Mike Frysinger Oct. 23, 2022, 1:55 p.m. UTC | #1
On 19 Oct 2022 16:24, Andrew Burgess via Gdb-patches wrote:
> --- 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);

should drop the paren around PPC_ONE_BIT_SET_P while you're here

otherwise lgtm
-mike
  
Andrew Burgess Oct. 24, 2022, 4:26 p.m. UTC | #2
Mike Frysinger <vapier@gentoo.org> writes:

> On 19 Oct 2022 16:24, Andrew Burgess via Gdb-patches wrote:
>> --- 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);
>
> should drop the paren around PPC_ONE_BIT_SET_P while you're here

Pushed with the fix you suggest.

Thanks,
Andrew
  

Patch

diff --git a/sim/ppc/altivec.igen b/sim/ppc/altivec.igen
index 63fe95a53d5..e7962027bd6 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);