From dc5a4621600e650b89deb92c79eaacc73fcc767a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 11 Nov 2021 19:30:41 -0500 Subject: [PATCH] sim: sh: rework carry checks to not rely on integer overflows In <=gcc-7 versions, -fstrict-overflow is enabled by default, and that triggers warnings in this code that relies on integer overflows to test for carries. Change the logic to test against the limit directly. --- sim/sh/gencode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sim/sh/gencode.c b/sim/sh/gencode.c index 80eecfdf1d3..5eb7caf2589 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 < (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 > (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 < (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 > (INT_MAX - 0x10000);", "res_grd = Sy_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", -- 2.30.2