Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Luis Machado via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] Fix SH sim build failures due to -Werror with GCC 7.5.x.
Date: Fri, 12 Nov 2021 11:57:27 -0300	[thread overview]
Message-ID: <20211112145727.1855584-1-luis.machado@linaro.org> (raw)

Adjust the statements to be mindful of signed overflows and initialize the res
variable. This fixes the strict-overflow and maybe-uninitialized warnings seen
below:

binutils-gdb/sim/sh/interp.c: In function "ppi_insn":
./ppi.c:875:21: error: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Werror=strict-overflow]
         carry = res < Sy;
                 ~~~~^~~~
./ppi.c:849:21: error: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Werror=strict-overflow]
         carry = res > Sy;
                 ~~~~^~~~
./ppi.c:823:21: error: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Werror=strict-overflow]
         carry = res < Sx;
                 ~~~~^~~~
./ppi.c:797:21: error: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Werror=strict-overflow]
         carry = res > Sx;
                 ~~~~^~~~
binutils-gdb-arm64-bionic/sim/../../../repos/binutils-gdb/sim/sh/interp.c: In function "sim_resume":
./ppi.c:1178:28: warning: "res" may be used uninitialized in this function [-Wmaybe-uninitialized]
           MACL = DSP_R (z) = res;
./ppi.c:44:7: note: "res" was declared here
   int res, res_grd;
       ^~~
---
 sim/sh/gencode.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sim/sh/gencode.c b/sim/sh/gencode.c
index 80eecfdf1d3..80cf573de0c 100644
--- a/sim/sh/gencode.c
+++ b/sim/sh/gencode.c
@@ -2266,7 +2266,7 @@ op ppi_tab[] =
     "int Sx_grd = GET_DSP_GRD (x);",
     "",
     "res = Sx - 0x10000;",
-    "carry = res > Sx;",
+    "carry = (Sx < 0 && Sx < INT_MIN + 0x10000);",
     "res_grd = Sx_grd - carry;",
     "COMPUTE_OVERFLOW;",
     "ADD_SUB_GE;",
@@ -2277,7 +2277,7 @@ op ppi_tab[] =
     "int Sx_grd = GET_DSP_GRD (x);",
     "",
     "res = Sx + 0x10000;",
-    "carry = res < Sx;",
+    "carry = (Sx > 0 && Sx > INT_MAX - 0x10000);",
     "res_grd = Sx_grd + carry;",
     "COMPUTE_OVERFLOW;",
     "ADD_SUB_GE;",
@@ -2288,7 +2288,7 @@ op ppi_tab[] =
     "int Sy_grd = SIGN32 (Sy);",
     "",
     "res = Sy - 0x10000;",
-    "carry = res > Sy;",
+    "carry = (Sy < 0 && Sy < INT_MIN + 0x10000);",
     "res_grd = Sy_grd - carry;",
     "COMPUTE_OVERFLOW;",
     "ADD_SUB_GE;",
@@ -2299,7 +2299,7 @@ op ppi_tab[] =
     "int Sy_grd = SIGN32 (Sy);",
     "",
     "res = Sy + 0x10000;",
-    "carry = res < Sy;",
+    "carry = (Sy > 0 && Sy > INT_MAX - 0x10000);",
     "res_grd = Sy_grd + carry;",
     "COMPUTE_OVERFLOW;",
     "ADD_SUB_GE;",
@@ -3257,7 +3257,7 @@ ppi_gensim (void)
   printf ("  static char const u_tab[] = { 8, 10,  7,  5};\n");
   printf ("\n");
   printf ("  int z;\n");
-  printf ("  int res, res_grd;\n");
+  printf ("  int res = 0, res_grd;\n");
   printf ("  int carry, overflow, greater_equal;\n");
   printf ("\n");
   printf ("  switch (ppi_table[iword >> 4]) {\n");
-- 
2.25.1


             reply	other threads:[~2021-11-12 14:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-12 14:57 Luis Machado via Gdb-patches [this message]
2021-11-26 18:13 ` Mike Frysinger via Gdb-patches
2021-11-26 19:56   ` Luis Machado via Gdb-patches

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=20211112145727.1855584-1-luis.machado@linaro.org \
    --to=gdb-patches@sourceware.org \
    --cc=luis.machado@linaro.org \
    /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