re PR middle-end/56956 (ftrapv traps on valid abs-like code)
authorRichard Biener <rguenther@suse.de>
Thu, 29 Oct 2015 08:21:50 +0000 (08:21 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 29 Oct 2015 08:21:50 +0000 (08:21 +0000)
2015-10-29  Richard Biener  <rguenther@suse.de>

PR middle-end/56956
* fold-const.c (fold_cond_expr_with_comparison): Do not fold
unsigned conditonal negation to ABS_EXPR.

* c-c++-common/ubsan/pr56956.c: New testcase.

From-SVN: r229517

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/pr56956.c [new file with mode: 0644]

index 9dfd43434b8e035be491bd3c437592261aa5e782..72d61adc5dca28a726c3463a4117566d830a4e61 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-29  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/56956
+       * fold-const.c (fold_cond_expr_with_comparison): Do not fold
+       unsigned conditonal negation to ABS_EXPR.
+
 2015-10-29  Richard Biener  <rguenther@suse.de>
 
        * gimple-match-head.c (gimple_simplify): Remove premature checking
index 71d72f19ece0fa31bc3c1f496f9fbed285d35a7c..d88bffc2bc67b5e50841655d081e8edd2ab2678c 100644 (file)
@@ -4963,8 +4963,7 @@ fold_cond_expr_with_comparison (location_t loc, tree type,
       case GE_EXPR:
       case GT_EXPR:
        if (TYPE_UNSIGNED (TREE_TYPE (arg1)))
-         arg1 = fold_convert_loc (loc, signed_type_for
-                              (TREE_TYPE (arg1)), arg1);
+         break;
        tem = fold_build1_loc (loc, ABS_EXPR, TREE_TYPE (arg1), arg1);
        return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, tem));
       case UNLE_EXPR:
@@ -4974,8 +4973,7 @@ fold_cond_expr_with_comparison (location_t loc, tree type,
       case LE_EXPR:
       case LT_EXPR:
        if (TYPE_UNSIGNED (TREE_TYPE (arg1)))
-         arg1 = fold_convert_loc (loc, signed_type_for
-                              (TREE_TYPE (arg1)), arg1);
+         break;
        tem = fold_build1_loc (loc, ABS_EXPR, TREE_TYPE (arg1), arg1);
        return negate_expr (fold_convert_loc (loc, type, tem));
       default:
index 43f6007e9e27c737edc8863ef60e44e7e3ae9f4c..8c3f4ade88c9d84819c514307f961bee5072ff2a 100644 (file)
@@ -1,3 +1,8 @@
+2015-10-29  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/56956
+       * c-c++-common/ubsan/pr56956.c: New testcase.
+
 2015-10-28  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/discr44.adb: New test.
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr56956.c b/gcc/testsuite/c-c++-common/ubsan/pr56956.c
new file mode 100644 (file)
index 0000000..996e1dd
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
+
+unsigned int __attribute__((noinline,noclone))
+foo (unsigned int x)
+{
+  return x <= __INT_MAX__ ? x : -x;
+}
+
+int
+main ()
+{
+  volatile unsigned int tem = foo (-__INT_MAX__ - 1);
+  return 0;
+}