From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BBE6C3815B for ; Mon, 20 Apr 2020 09:50:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4CE0720CC7 for ; Mon, 20 Apr 2020 09:50:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CE0720CC7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=users.sourceforge.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQT4X-0004T7-Eg for qemu-devel@archiver.kernel.org; Mon, 20 Apr 2020 05:50:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47980 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQT3J-0003nd-RX for qemu-devel@nongnu.org; Mon, 20 Apr 2020 05:49:22 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQT3I-0008Ub-MD for qemu-devel@nongnu.org; Mon, 20 Apr 2020 05:49:21 -0400 Received: from mail02.asahi-net.or.jp ([202.224.55.14]:47881) by eggs1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQT3I-0008Pb-43 for qemu-devel@nongnu.org; Mon, 20 Apr 2020 05:49:20 -0400 Received: from sakura.ysato.name (ik1-413-38519.vs.sakura.ne.jp [153.127.30.23]) (Authenticated sender: PQ4Y-STU) by mail02.asahi-net.or.jp (Postfix) with ESMTPA id 827C5E9AB7; Mon, 20 Apr 2020 18:49:16 +0900 (JST) Received: from yo-satoh-debian.ysato.ml (ZM005235.ppp.dion.ne.jp [222.8.5.235]) by sakura.ysato.name (Postfix) with ESMTPSA id 0587B1C0DD4; Mon, 20 Apr 2020 18:49:15 +0900 (JST) Date: Mon, 20 Apr 2020 18:49:14 +0900 Message-ID: <87mu76v65h.wl-ysato@users.sourceforge.jp> From: Yoshinori Sato To: Pan Nengyuan Subject: Re: [PATCH] op_helper: fix some compile warnings In-Reply-To: References: <20200420054959.8082-1-pannengyuan@huawei.com> <87o8rmv8vb.wl-ysato@users.sourceforge.jp> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.8 EasyPG/1.0.0 Emacs/26 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable Received-SPF: softfail client-ip=202.224.55.14; envelope-from=ysato@users.sourceforge.jp; helo=mail02.asahi-net.or.jp X-detected-operating-system: by eggs1p.gnu.org: First seen = 2020/04/20 05:49:17 X-ACL-Warn: Detected OS = ??? X-Received-From: 202.224.55.14 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, euler.robot@huawei.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Mon, 20 Apr 2020 18:18:39 +0900, Pan Nengyuan wrote: >=20 >=20 >=20 > On 4/20/2020 4:50 PM, Yoshinori Sato wrote: > > On Mon, 20 Apr 2020 14:49:59 +0900, > > Pan Nengyuan wrote: > >> > >> We got the following compile-time warnings(gcc7.3): > >> /mnt/sdb//qemu/target/rx/op_helper.c: In function =A1helper_scmpu=A2: > >> /mnt/sdb/qemu/target/rx/op_helper.c:213:24: error: =A1tmp1=A2 may be u= sed uninitialized in this function [-Werror=3Dmaybe-uninitialized] > >> env->psw_c =3D (tmp0 >=3D tmp1); > >> ~~~~~~^~~~~~~~ > >> /mnt/sdb/qemu/target/rx/op_helper.c:213:24: error: =A1tmp0=A2 may be u= sed uninitialized in this function [-Werror=3Dmaybe-uninitialized] > >> /mnt/sdb/qemu/target/rx/op_helper.c: In function =A1helper_suntil=A2: > >> /mnt/sdb/qemu/target/rx/op_helper.c:299:23: error: =A1tmp=A2 may be us= ed uninitialized in this function [-Werror=3Dmaybe-uninitialized] > >> env->psw_c =3D (tmp <=3D env->regs[2]); > >> ~~~~~^~~~~~~~~~~~~~~~ > >> /mnt/sdb/qemu/target/rx/op_helper.c: In function =A1helper_swhile=A2: > >> /mnt/sdb/qemu/target/rx/op_helper.c:318:23: error: =A1tmp=A2 may be us= ed uninitialized in this function [-Werror=3Dmaybe-uninitialized] > >> env->psw_c =3D (tmp <=3D env->regs[2]); > >> > >> Actually, it looks like a false-positive because it will enter the bod= y of while loop and init it for the first time. > >> Let's change 'while' to 'do .. while' to avoid it. > >=20 > > OK. > >=20 > >> Reported-by: Euler Robot > >> Signed-off-by: Pan Nengyuan > >> --- > >> target/rx/op_helper.c | 12 ++++++------ > >> 1 file changed, 6 insertions(+), 6 deletions(-) > >> > >> diff --git a/target/rx/op_helper.c b/target/rx/op_helper.c > >> index f89d294f2b..b612ab1da8 100644 > >> --- a/target/rx/op_helper.c > >> +++ b/target/rx/op_helper.c > >> @@ -201,14 +201,14 @@ void helper_scmpu(CPURXState *env) > >> if (env->regs[3] =3D=3D 0) { > >> return; > >> } > >> - while (env->regs[3] !=3D 0) { > >> + do { > >> tmp0 =3D cpu_ldub_data_ra(env, env->regs[1]++, GETPC()); > >> tmp1 =3D cpu_ldub_data_ra(env, env->regs[2]++, GETPC()); > >> env->regs[3]--; > >> if (tmp0 !=3D tmp1 || tmp0 =3D=3D '\0') { > >> break; > >> } > >> - } > >> + } while (env->regs[3] !=3D 0); > >> env->psw_z =3D tmp0 - tmp1; > >> env->psw_c =3D (tmp0 >=3D tmp1); > >> } > >> @@ -287,14 +287,14 @@ void helper_suntil(CPURXState *env, uint32_t sz) > >> if (env->regs[3] =3D=3D 0) { > >> return ; > >> } > >> - while (env->regs[3] !=3D 0) { > >> + do { > >> tmp =3D cpu_ldufn[sz](env, env->regs[1], GETPC()); > >> env->regs[1] +=3D 1 << sz; > >> env->regs[3]--; > >> if (tmp =3D=3D env->regs[2]) { > >> break; > >> } > >> - } > >> + } while (env->regs[3] !=3D 0); > >> env->psw_z =3D tmp - env->regs[2]; > >> env->psw_c =3D (tmp <=3D env->regs[2]); > >> } > >> @@ -306,14 +306,14 @@ void helper_swhile(CPURXState *env, uint32_t sz) > >> if (env->regs[3] =3D=3D 0) { > >> return ; > >> } > >> - while (env->regs[3] !=3D 0) { > >> + do { > >> tmp =3D cpu_ldufn[sz](env, env->regs[1], GETPC()); > >> env->regs[1] +=3D 1 << sz; > >> env->regs[3]--; > >> if (tmp !=3D env->regs[2]) { > >> break; > >> } > >> - } > >> + } while (env->regs[3] !=3D 0); > >> env->psw_z =3D env->regs[3]; > >> env->psw_c =3D (tmp <=3D env->regs[2]); > >> } > >> --=20 > >> 2.18.2 > >> > >> > >=20 > > It looks different result in env->regs[3] is zero. >=20 > If env->regs[3] is zero, it will return at the begin of these functions: >=20 > if (env->regs[3] =3D=3D 0) { > return; > } >=20 > Thus, the while loop will not be reached. > In this case, I think 'while' and 'do .. while' will get the same result = and it will disappear the warnings. Oh. Sorry. I misunderstood. Since the pseudo code described in the manual uses while, I think it's easier for everyone to understand by following the description. > > In such a case, nothing changes. > >=20 > > I think that the warning of the uninitialized variable > > will disappear by fixing as follows. > >=20 >=20 > Yes, it also can fix these warnings. OK. Thanks. > Thanks. >=20 > >>From 5de0c54a970e01e96b41870252d0ea54ec61c540 Mon Sep 17 00:00:00 2001 > > From: Yoshinori Sato > > Date: Mon, 20 Apr 2020 17:41:04 +0900 > > Subject: [PATCH] target/rx/op_helper: Fix uninitialized warning. > >=20 > > Signed-off-by: Yoshinori Sato > > --- > > target/rx/op_helper.c | 101 ++++++++++++++++++++---------------------- > > 1 file changed, 49 insertions(+), 52 deletions(-) > >=20 > > diff --git a/target/rx/op_helper.c b/target/rx/op_helper.c > > index f89d294f2b..f84f6c706c 100644 > > --- a/target/rx/op_helper.c > > +++ b/target/rx/op_helper.c > > @@ -284,38 +284,36 @@ void helper_suntil(CPURXState *env, uint32_t sz) > > { > > uint32_t tmp; > > tcg_debug_assert(sz < 3); > > - if (env->regs[3] =3D=3D 0) { > > - return ; > > - } > > - while (env->regs[3] !=3D 0) { > > - tmp =3D cpu_ldufn[sz](env, env->regs[1], GETPC()); > > - env->regs[1] +=3D 1 << sz; > > - env->regs[3]--; > > - if (tmp =3D=3D env->regs[2]) { > > - break; > > + if (env->regs[3] > 0) { > > + while (env->regs[3] !=3D 0) { > > + tmp =3D cpu_ldufn[sz](env, env->regs[1], GETPC()); > > + env->regs[1] +=3D 1 << sz; > > + env->regs[3]--; > > + if (tmp =3D=3D env->regs[2]) { > > + break; > > + } > > } > > + env->psw_z =3D tmp - env->regs[2]; > > + env->psw_c =3D (tmp <=3D env->regs[2]); > > } > > - env->psw_z =3D tmp - env->regs[2]; > > - env->psw_c =3D (tmp <=3D env->regs[2]); > > } > > =20 > > void helper_swhile(CPURXState *env, uint32_t sz) > > { > > uint32_t tmp; > > tcg_debug_assert(sz < 3); > > - if (env->regs[3] =3D=3D 0) { > > - return ; > > - } > > - while (env->regs[3] !=3D 0) { > > - tmp =3D cpu_ldufn[sz](env, env->regs[1], GETPC()); > > - env->regs[1] +=3D 1 << sz; > > - env->regs[3]--; > > - if (tmp !=3D env->regs[2]) { > > - break; > > + if (env->regs[3] > 0) { > > + while (env->regs[3] !=3D 0) { > > + tmp =3D cpu_ldufn[sz](env, env->regs[1], GETPC()); > > + env->regs[1] +=3D 1 << sz; > > + env->regs[3]--; > > + if (tmp !=3D env->regs[2]) { > > + break; > > + } > > } > > + env->psw_z =3D env->regs[3]; > > + env->psw_c =3D (tmp <=3D env->regs[2]); > > } > > - env->psw_z =3D env->regs[3]; > > - env->psw_c =3D (tmp <=3D env->regs[2]); > > } > > =20 > > /* accumlator operations */ > > @@ -325,40 +323,39 @@ void helper_rmpa(CPURXState *env, uint32_t sz) > > int32_t result_h; > > int64_t tmp0, tmp1; > > =20 > > - if (env->regs[3] =3D=3D 0) { > > - return; > > - } > > - result_l =3D env->regs[5]; > > - result_l <<=3D 32; > > - result_l |=3D env->regs[4]; > > - result_h =3D env->regs[6]; > > - env->psw_o =3D 0; > > + if (env->regs[3] > 0) { > > + result_l =3D env->regs[5]; > > + result_l <<=3D 32; > > + result_l |=3D env->regs[4]; > > + result_h =3D env->regs[6]; > > + env->psw_o =3D 0; > > =20 > > - while (env->regs[3] !=3D 0) { > > - tmp0 =3D cpu_ldfn[sz](env, env->regs[1], GETPC()); > > - tmp1 =3D cpu_ldfn[sz](env, env->regs[2], GETPC()); > > - tmp0 *=3D tmp1; > > - prev =3D result_l; > > - result_l +=3D tmp0; > > - /* carry / bollow */ > > - if (tmp0 < 0) { > > - if (prev > result_l) { > > - result_h--; > > - } > > - } else { > > - if (prev < result_l) { > > - result_h++; > > + while (env->regs[3] !=3D 0) { > > + tmp0 =3D cpu_ldfn[sz](env, env->regs[1], GETPC()); > > + tmp1 =3D cpu_ldfn[sz](env, env->regs[2], GETPC()); > > + tmp0 *=3D tmp1; > > + prev =3D result_l; > > + result_l +=3D tmp0; > > + /* carry / bollow */ > > + if (tmp0 < 0) { > > + if (prev > result_l) { > > + result_h--; > > + } > > + } else { > > + if (prev < result_l) { > > + result_h++; > > + } > > } > > - } > > =20 > > - env->regs[1] +=3D 1 << sz; > > - env->regs[2] +=3D 1 << sz; > > + env->regs[1] +=3D 1 << sz; > > + env->regs[2] +=3D 1 << sz; > > + } > > + env->psw_s =3D result_h; > > + env->psw_o =3D (result_h !=3D 0 && result_h !=3D -1) << 31; > > + env->regs[6] =3D result_h; > > + env->regs[5] =3D result_l >> 32; > > + env->regs[4] =3D result_l & 0xffffffff; > > } > > - env->psw_s =3D result_h; > > - env->psw_o =3D (result_h !=3D 0 && result_h !=3D -1) << 31; > > - env->regs[6] =3D result_h; > > - env->regs[5] =3D result_l >> 32; > > - env->regs[4] =3D result_l & 0xffffffff; > > } > > =20 > > void helper_racw(CPURXState *env, uint32_t imm) > >=20 --=20 Yosinori Sato