]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR sanitizer/59503 (Bogus integer-overflow error with long long with -m32)
authorMarek Polacek <polacek@redhat.com>
Sat, 14 Dec 2013 12:19:56 +0000 (12:19 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sat, 14 Dec 2013 12:19:56 +0000 (12:19 +0000)
PR sanitizer/59503
* internal-fn.c (ubsan_expand_si_overflow_addsub_check): Call
expand_binop with correct optab depending on code.
testsuite/
* c-c++-common/ubsan/pr59503.c: New test.

From-SVN: r205984

gcc/ChangeLog
gcc/internal-fn.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/pr59503.c [new file with mode: 0644]

index fdb84d1d42344a51447678c102aa520badb00e80..cd64b59bf08fd40fcc1369d0595754c6bbfa847e 100644 (file)
@@ -1,3 +1,9 @@
+2013-12-14  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/59503
+       * internal-fn.c (ubsan_expand_si_overflow_addsub_check): Call
+       expand_binop with correct optab depending on code.
+
 2013-12-14  Tom de Vries  <tom@codesourcery.com>
 
        * calls.c (expand_call): Fix REG_PARM_STACK_SPACE comparison.
index ad9c9475265521db35fc658177f1a2850efc0c86..a0874d467b45290f0fc61006b15db7fd7a5e44f1 100644 (file)
@@ -214,14 +214,14 @@ ubsan_expand_si_overflow_addsub_check (tree_code code, gimple stmt)
 
       /* Compute the operation.  On RTL level, the addition is always
         unsigned.  */
-      res = expand_binop (mode, add_optab, op0, op1,
-                         NULL_RTX, false, OPTAB_LIB_WIDEN);
+      res = expand_binop (mode, code == PLUS_EXPR ? add_optab : sub_optab,
+                         op0, op1, NULL_RTX, false, OPTAB_LIB_WIDEN);
 
       /* If the op1 is negative, we have to use a different check.  */
       emit_cmp_and_jump_insns (op1, const0_rtx, LT, NULL_RTX, mode,
                               false, sub_check, PROB_EVEN);
 
-      /* Compare the result of the addition with one of the operands.  */
+      /* Compare the result of the operation with one of the operands.  */
       emit_cmp_and_jump_insns (res, op0, code == PLUS_EXPR ? GE : LE,
                               NULL_RTX, mode, false, done_label,
                               PROB_VERY_LIKELY);
index 91dcb335bb14a14335688cdf1918479d993bb97c..b5fabb2baf1d6deaa6eb3ae032fdb98376d9b76a 100644 (file)
@@ -1,3 +1,8 @@
+2013-12-14  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/59503
+       * c-c++-common/ubsan/pr59503.c: New test.
+
 2013-12-14  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/59450
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr59503.c b/gcc/testsuite/c-c++-common/ubsan/pr59503.c
new file mode 100644 (file)
index 0000000..eb921c4
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=signed-integer-overflow" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+int
+main (void)
+{
+  long long int a = 14;
+  long int b = 9;
+  asm volatile ("" : "+r" (a), "+r" (b));
+  if ((a - b) != 5)
+    __builtin_abort ();
+  return 0;
+}