re PR sanitizer/80349 (UBSAN: compile time crash with "type mismatch in binary expres...
authorJakub Jelinek <jakub@redhat.com>
Wed, 12 Apr 2017 06:12:26 +0000 (08:12 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 12 Apr 2017 06:12:26 +0000 (08:12 +0200)
PR sanitizer/80349
* fold-const.c (fold_binary_loc) <case BIT_IOR_EXPR>: Convert arg0's
first argument to type.

* g++.dg/ubsan/pr80349.C: New test.

From-SVN: r246865

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

index 388db6d7ab2d6d2d82c5a2680efdabca6b55c6fe..f96256bfac997e7c708af9d060dfc7971b1403d9 100644 (file)
@@ -1,3 +1,9 @@
+2017-04-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/80349
+       * fold-const.c (fold_binary_loc) <case BIT_IOR_EXPR>: Convert arg0's
+       first argument to type.
+
 2017-04-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        PR target/80376
index 524bb0fe3fbdfb8993e48e827d3bed1eab17561d..2f2e93afb55f2d3254c6023ac5ff4d72ac3bf184 100644 (file)
@@ -9916,12 +9916,12 @@ fold_binary_loc (location_t loc,
            }
 
          if (c3 != c1)
-           return fold_build2_loc (loc, BIT_IOR_EXPR, type,
-                                   fold_build2_loc (loc, BIT_AND_EXPR, type,
-                                                    TREE_OPERAND (arg0, 0),
-                                                    wide_int_to_tree (type,
-                                                                      c3)),
-                                   arg1);
+           {
+             tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
+             tem = fold_build2_loc (loc, BIT_AND_EXPR, type, tem,
+                                    wide_int_to_tree (type, c3));
+             return fold_build2_loc (loc, BIT_IOR_EXPR, type, tem, arg1);
+           }
        }
 
       /* See if this can be simplified into a rotate first.  If that
index 354adb043148599c688224e3b403de83470a3ed6..bf315d3696e54e84eced4a78b065666e80d2dc1e 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/80349
+       * g++.dg/ubsan/pr80349.C: New test.
+
 2017-04-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/80370
diff --git a/gcc/testsuite/g++.dg/ubsan/pr80349.C b/gcc/testsuite/g++.dg/ubsan/pr80349.C
new file mode 100644 (file)
index 0000000..f705b92
--- /dev/null
@@ -0,0 +1,11 @@
+// PR sanitizer/80349
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined" }
+
+extern const long long int v;
+
+void
+foo ()
+{
+  (int)((v & 50 | 051UL) << 0) << 0;
+}