qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pan Nengyuan <pannengyuan@huawei.com>
To: <ysato@users.sourceforge.jp>
Cc: euler.robot@huawei.com, Pan Nengyuan <pannengyuan@huawei.com>,
	qemu-devel@nongnu.org, zhang.zhanghailiang@huawei.com
Subject: [PATCH] op_helper: fix some compile warnings
Date: Mon, 20 Apr 2020 01:49:59 -0400	[thread overview]
Message-ID: <20200420054959.8082-1-pannengyuan@huawei.com> (raw)

We got the following compile-time warnings(gcc7.3):
/mnt/sdb//qemu/target/rx/op_helper.c: In function ‘helper_scmpu’:
/mnt/sdb/qemu/target/rx/op_helper.c:213:24: error: ‘tmp1’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     env->psw_c = (tmp0 >= tmp1);
                  ~~~~~~^~~~~~~~
/mnt/sdb/qemu/target/rx/op_helper.c:213:24: error: ‘tmp0’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
/mnt/sdb/qemu/target/rx/op_helper.c: In function ‘helper_suntil’:
/mnt/sdb/qemu/target/rx/op_helper.c:299:23: error: ‘tmp’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     env->psw_c = (tmp <= env->regs[2]);
                  ~~~~~^~~~~~~~~~~~~~~~
/mnt/sdb/qemu/target/rx/op_helper.c: In function ‘helper_swhile’:
/mnt/sdb/qemu/target/rx/op_helper.c:318:23: error: ‘tmp’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     env->psw_c = (tmp <= env->regs[2]);

Actually, it looks like a false-positive because it will enter the body of while loop and init it for the first time.
Let's change 'while' to 'do .. while' to avoid it.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
---
 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] == 0) {
         return;
     }
-    while (env->regs[3] != 0) {
+    do {
         tmp0 = cpu_ldub_data_ra(env, env->regs[1]++, GETPC());
         tmp1 = cpu_ldub_data_ra(env, env->regs[2]++, GETPC());
         env->regs[3]--;
         if (tmp0 != tmp1 || tmp0 == '\0') {
             break;
         }
-    }
+    } while (env->regs[3] != 0);
     env->psw_z = tmp0 - tmp1;
     env->psw_c = (tmp0 >= tmp1);
 }
@@ -287,14 +287,14 @@ void helper_suntil(CPURXState *env, uint32_t sz)
     if (env->regs[3] == 0) {
         return ;
     }
-    while (env->regs[3] != 0) {
+    do {
         tmp = cpu_ldufn[sz](env, env->regs[1], GETPC());
         env->regs[1] += 1 << sz;
         env->regs[3]--;
         if (tmp == env->regs[2]) {
             break;
         }
-    }
+    } while (env->regs[3] != 0);
     env->psw_z = tmp - env->regs[2];
     env->psw_c = (tmp <= env->regs[2]);
 }
@@ -306,14 +306,14 @@ void helper_swhile(CPURXState *env, uint32_t sz)
     if (env->regs[3] == 0) {
         return ;
     }
-    while (env->regs[3] != 0) {
+    do {
         tmp = cpu_ldufn[sz](env, env->regs[1], GETPC());
         env->regs[1] += 1 << sz;
         env->regs[3]--;
         if (tmp != env->regs[2]) {
             break;
         }
-    }
+    } while (env->regs[3] != 0);
     env->psw_z = env->regs[3];
     env->psw_c = (tmp <= env->regs[2]);
 }
-- 
2.18.2



             reply	other threads:[~2020-04-20  2:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20  5:49 Pan Nengyuan [this message]
2020-04-20  3:13 ` [PATCH] op_helper: fix some compile warnings no-reply
2020-04-20  8:50 ` Yoshinori Sato
2020-04-20  9:18   ` Pan Nengyuan
2020-04-20  9:49     ` Yoshinori Sato
2020-04-20 11:04       ` Pan Nengyuan

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=20200420054959.8082-1-pannengyuan@huawei.com \
    --to=pannengyuan@huawei.com \
    --cc=euler.robot@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ysato@users.sourceforge.jp \
    --cc=zhang.zhanghailiang@huawei.com \
    /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 NNTP newsgroup(s).