https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109107

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
A similar problem:

#define INT_MIN (-__INT_MAX__ - 1)
int a = INT_MIN;
const int b = 676540;
int
main ()
{
  int c = a - 1 + (int) (short) b;
  return c;
}

for which I think we need:

--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -11319,7 +11319,8 @@ fold_binary_loc (location_t loc, enum tree_code code,
tree type,
     And, we need to make sure type is not saturating.  */

       if ((! FLOAT_TYPE_P (type) || flag_associative_math)
-     && !TYPE_SATURATING (type))
+     && !TYPE_SATURATING (type)
+     && !TYPE_OVERFLOW_SANITIZED (type))
    {
      tree var0, minus_var0, con0, minus_con0, lit0, minus_lit0;
      tree var1, minus_var1, con1, minus_con1, lit1, minus_lit1;

Reply via email to