re PR sanitizer/80403 (UBSAN: compile time crash with "type mismatch in binary expres...
authorJakub Jelinek <jakub@redhat.com>
Thu, 13 Apr 2017 19:52:58 +0000 (21:52 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 13 Apr 2017 19:52:58 +0000 (21:52 +0200)
PR sanitizer/80403
* fold-const.c (fold_ternary_loc): Revert
use op0 instead of fold_convert_loc (loc, type, arg0) part of
2017-04-12 change.

* g++.dg/ubsan/pr80403-2.C: New test.

From-SVN: r246917

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ubsan/pr80403-2.C [new file with mode: 0644]

index ca93f9bf21eb932e54f160e4d0184608c0822513..33b094e56f5fd8dce95ee25e492588ca4bcc3380 100644 (file)
@@ -1,3 +1,10 @@
+2017-04-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/80403
+       * fold-const.c (fold_ternary_loc): Revert
+       use op0 instead of fold_convert_loc (loc, type, arg0) part of
+       2017-04-12 change.
+
 2017-04-13  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/80343
index fb0b1a6afc302b78f687847537f553d3148b78f8..770162251f2e270e75bb7978b5c43cc60d0d411c 100644 (file)
@@ -11544,7 +11544,7 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
          && (code == VEC_COND_EXPR || !VECTOR_TYPE_P (type)))
        return fold_build2_loc (loc, code == VEC_COND_EXPR ? BIT_AND_EXPR
                                                           : TRUTH_ANDIF_EXPR,
-                               type, op0, op1);
+                               type, fold_convert_loc (loc, type, arg0), op1);
 
       /* Convert A ? B : 1 into !A || B if A and B are truth values.  */
       if (code == VEC_COND_EXPR ? integer_all_onesp (op2) : integer_onep (op2)
index 4f46db8091fe9e997c5cd899eb84939268b9d4d3..07902c1657668d874b2689bc63de0abdcd37b10a 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/80403
+       * g++.dg/ubsan/pr80403-2.C: New test.
+
 2017-04-13  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/80343
diff --git a/gcc/testsuite/g++.dg/ubsan/pr80403-2.C b/gcc/testsuite/g++.dg/ubsan/pr80403-2.C
new file mode 100644 (file)
index 0000000..434a883
--- /dev/null
@@ -0,0 +1,14 @@
+// PR sanitizer/80403
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined" }
+
+extern const long long int v;
+extern unsigned long int w;
+
+int
+foo ()
+{
+  int a = (0 - 40U <= (0 == 8)) << !w << (0 < v) == 0;
+  int b = ((0 ^ 0) < (long) (1066066618772207110 <= 0)) / 0 << 0;      // { dg-warning "division by zero" }
+  return a + b;
+}