From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id A7716385840A; Mon, 24 Oct 2022 16:19:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7716385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666628401; bh=jJ642G3+NjsbMI3zhxlsE/y6W/ULOcqwmrA8RNEBrN0=; h=From:To:Subject:Date:From; b=pQU/feVg7/2XjXf2KrbLmut8P7wHnYwk+62yav5/rYVhICHUmHAhHnMVufLmgphcb /0SVksh4PYCzU0OgyMMoQXwKS7hm8wYOTv1cePWAyqp06VCzrOgv7x31100JocHZQj mVanFc4So1+3QTHU/WZXur958ocC4MqcIJbjVKR8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] sim/ppc: fix for operator precedence warning from clang X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 548d634f1b61571f118c3133ce0e8986714c8fd6 X-Git-Newrev: e0b3df3b4d77706abf5f077477b2ca227fc4e9d1 Message-Id: <20221024162001.A7716385840A@sourceware.org> Date: Mon, 24 Oct 2022 16:19:57 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De0b3df3b4d77= 706abf5f077477b2ca227fc4e9d1 commit e0b3df3b4d77706abf5f077477b2ca227fc4e9d1 Author: Andrew Burgess Date: Wed Oct 19 15:12:57 2022 +0100 sim/ppc: fix for operator precedence warning from clang =20 In the ppc simulator, clang was warning about some code like this: =20 busy_ptr->nr_writebacks =3D 1 + (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : = 2; =20 The warning was: =20 operator '?:' has lower precedence than '+'; '+' will be evaluated fi= rst =20 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. =20 I suspect the answer the author was expecting was either 2 or 3. Why they didn't just write: =20 busy_ptr->nr_writebacks =3D (PPC_ONE_BIT_SET_P(out_vmask)) ? 2 : 3; =20 I have no clue, however, to keep the structure of the code unchanged, I've updated things to: =20 busy_ptr->nr_writebacks =3D 1 + (PPC_ONE_BIT_SET_P (out_vmask) ? 1 : = 2); =20 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 ind= ex, model_data *model_ptr busy_ptr->vscr_busy =3D 1; =20 if (out_vmask) - busy_ptr->nr_writebacks =3D 1 + (PPC_ONE_BIT_SET_P(out_vmask)) ? 1 : 2; + busy_ptr->nr_writebacks =3D 1 + (PPC_ONE_BIT_SET_P (out_vmask) ? 1 : 2); =20 if (WITH_TRACE && ppc_trace[trace_model]) model_trace_altivec_make_busy(model_ptr, vr_mask, 0);