public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix SH sim build failures due to -Werror with GCC 7.5.x.
@ 2021-11-12 14:57 Luis Machado
  2021-11-26 18:13 ` Mike Frysinger
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Machado @ 2021-11-12 14:57 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix SH sim build failures due to -Werror with GCC 7.5.x.
  2021-11-12 14:57 [PATCH] Fix SH sim build failures due to -Werror with GCC 7.5.x Luis Machado
@ 2021-11-26 18:13 ` Mike Frysinger
  2021-11-26 19:56   ` Luis Machado
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Frysinger @ 2021-11-26 18:13 UTC (permalink / raw)
  To: Luis Machado; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 76 bytes --]

i pushed a bunch of fixes for this.  have you tried the latest tree ?
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix SH sim build failures due to -Werror with GCC 7.5.x.
  2021-11-26 18:13 ` Mike Frysinger
@ 2021-11-26 19:56   ` Luis Machado
  0 siblings, 0 replies; 3+ messages in thread
From: Luis Machado @ 2021-11-26 19:56 UTC (permalink / raw)
  To: Luis Machado, gdb-patches\@sourceware.org

Hi Mike,

Yep. It was fixed by one of your fixes a little while ago. Thanks!

On Fri, Nov 26, 2021, 15:13 Mike Frysinger <vapier@gentoo.org> wrote:

> i pushed a bunch of fixes for this.  have you tried the latest tree ?
> -mike
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-26 19:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 14:57 [PATCH] Fix SH sim build failures due to -Werror with GCC 7.5.x Luis Machado
2021-11-26 18:13 ` Mike Frysinger
2021-11-26 19:56   ` Luis Machado

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 read-only IMAP folder(s) and NNTP newsgroup(s).