Fix PR82488 - signed integer overflow in expr.c
authorMarkus Trippelsdorf <markus@trippelsdorf.de>
Mon, 27 Nov 2017 05:20:43 +0000 (05:20 +0000)
committerMarkus Trippelsdorf <trippels@gcc.gnu.org>
Mon, 27 Nov 2017 05:20:43 +0000 (05:20 +0000)
bootstrap-ubsan shows:
 gcc/expr.c:4103:17: runtime error: signed integer overflow: 0 - -9223372036854775808 cannot be represented in type 'long int'

Fix by handling the saw_unknown case earlier.

PR rtl-optimization/82488
* expr.c (fixup_args_size_notes): Avoid signed integer overflow.

diff --git a/gcc/expr.c b/gcc/expr.c
index ee07de5aaa44..e9d8555c9452 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -4100,10 +4100,13 @@ fixup_args_size_notes (rtx_insn *prev, rtx_insn *last, int end_args_size)
       if (STACK_GROWS_DOWNWARD)
  this_delta = -(unsigned HOST_WIDE_INT) this_delta;

-      args_size -= this_delta;
+      if (saw_unknown)
+ args_size = INT_MIN;
+      else
+ args_size -= this_delta;
     }

-  return saw_unknown ? INT_MIN : args_size;
+  return args_size;
 }

 #ifdef PUSH_ROUNDING
--
Markus

From-SVN: r255159

gcc/ChangeLog
gcc/expr.c

index 20c4ab61f1fa91c9881c1ccdb6e4765082d31adf..dc980a96a0d2c83de40444ab2a5633636d377a67 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-27  Markus Trippelsdorf  <markus@trippelsdorf.de>
+
+       PR rtl-optimization/82488
+       * expr.c (fixup_args_size_notes): Avoid signed integer overflow.
+
 2017-11-26  Julia Koval  <julia.koval@intel.com>
 
        * config/i386/i386.c (processor_target_table): Add skylake_cost for
index ee07de5aaa44f3648aa8a3fbbeda79a6c448c2f9..e9d8555c9452d3cd3b6c3c298e4ed428dd69f3e8 100644 (file)
@@ -4100,10 +4100,13 @@ fixup_args_size_notes (rtx_insn *prev, rtx_insn *last, int end_args_size)
       if (STACK_GROWS_DOWNWARD)
        this_delta = -(unsigned HOST_WIDE_INT) this_delta;
 
-      args_size -= this_delta;
+      if (saw_unknown)
+       args_size = INT_MIN;
+      else
+       args_size -= this_delta;
     }
 
-  return saw_unknown ? INT_MIN : args_size;
+  return args_size;
 }
 
 #ifdef PUSH_ROUNDING