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 E1045C3815B for ; Mon, 20 Apr 2020 08:51: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 B535F20A8B for ; Mon, 20 Apr 2020 08:51:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B535F20A8B 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]:59810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQS9R-0002AK-TH for qemu-devel@archiver.kernel.org; Mon, 20 Apr 2020 04:51:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59782 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQS8Z-0001RH-KT for qemu-devel@nongnu.org; Mon, 20 Apr 2020 04:50:44 -0400 Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQS8Y-0000Sy-Cy for qemu-devel@nongnu.org; Mon, 20 Apr 2020 04:50:43 -0400 Received: from mail03.asahi-net.or.jp ([202.224.55.15]:55088) by eggs1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQS8X-0000Lu-Qz for qemu-devel@nongnu.org; Mon, 20 Apr 2020 04:50:42 -0400 Received: from sakura.ysato.name (ik1-413-38519.vs.sakura.ne.jp [153.127.30.23]) (Authenticated sender: PQ4Y-STU) by mail03.asahi-net.or.jp (Postfix) with ESMTPA id D7947E8C47; Mon, 20 Apr 2020 17:50:36 +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 0AF0A1C080F; Mon, 20 Apr 2020 17:50:36 +0900 (JST) Date: Mon, 20 Apr 2020 17:50:32 +0900 Message-ID: <87o8rmv8vb.wl-ysato@users.sourceforge.jp> From: Yoshinori Sato To: Pan Nengyuan Subject: Re: [PATCH] op_helper: fix some compile warnings In-Reply-To: <20200420054959.8082-1-pannengyuan@huawei.com> References: <20200420054959.8082-1-pannengyuan@huawei.com> 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.15; envelope-from=ysato@users.sourceforge.jp; helo=mail03.asahi-net.or.jp X-detected-operating-system: by eggs1p.gnu.org: First seen = 2020/04/20 04:50:37 X-ACL-Warn: Detected OS = ??? X-Received-From: 202.224.55.15 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 14:49:59 +0900, Pan Nengyuan wrote: >=20 > 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 used= 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 used= 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 used = 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 used = uninitialized in this function [-Werror=3Dmaybe-uninitialized] > env->psw_c =3D (tmp <=3D env->regs[2]); >=20 > Actually, it looks like a false-positive because it will enter the body o= f while loop and init it for the first time. > Let's change 'while' to 'do .. while' to avoid it. OK. > Reported-by: Euler Robot > Signed-off-by: Pan Nengyuan > --- > target/rx/op_helper.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) >=20 > 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 >=20 It looks different result in env->regs[3] is zero. In such a case, nothing changes. I think that the warning of the uninitialized variable will disappear by fixing as follows. =46rom 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. Signed-off-by: Yoshinori Sato --- target/rx/op_helper.c | 101 ++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 52 deletions(-) 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 2.20.1 --=20 Yosinori Sato