]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR sanitizer/80349 (UBSAN: compile time crash with "type mismatch in binary expres...
authorMarek Polacek <polacek@redhat.com>
Tue, 25 Apr 2017 16:39:57 +0000 (16:39 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 25 Apr 2017 16:39:57 +0000 (16:39 +0000)
PR sanitizer/80349
* fold-const.c (fold_binary_loc) <case BIT_IOR_EXPR>: Convert arg0's
first argument to type.

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

From-SVN: r247257

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

index 56da6914880b20487d5c1b3ccffad2d585a623ea..1d35b3c9c2c47f34514862e792db13743c0778c1 100644 (file)
@@ -1,3 +1,9 @@
+2017-04-25  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/80349
+       * fold-const.c (fold_binary_loc) <case BIT_IOR_EXPR>: Convert arg0's
+       first argument to type.
+
 2017-04-25  Bill Seurer  <seurer@linux.vnet.ibm.com>
 
        PR target/80482
index f0b8e7a3f1b6227416074733aba533f709ddaf60..ce4b2df8cd2c7c1756dc7a8ec81d90e8560044db 100644 (file)
@@ -9898,8 +9898,10 @@ fold_binary_loc (location_t loc,
 
          /* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2.  */
          if (msk.and_not (c1 | c2) == 0)
-           return fold_build2_loc (loc, BIT_IOR_EXPR, type,
-                                   TREE_OPERAND (arg0, 0), arg1);
+           {
+             tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
+             return fold_build2_loc (loc, BIT_IOR_EXPR, type, tem, arg1);
+           }
 
          /* Minimize the number of bits set in C1, i.e. C1 := C1 & ~C2,
             unless (C1 & ~C2) | (C2 & C3) for some C3 is a mask of some
index 6b1feffebe83e062720b4be8ccc9a9579d3c4aca..0b2e208561257017ef26102bf46e5bbbae6c0157 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-25  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/80349
+       * g++.dg/ubsan/pr80349-2.C: New test.
+
 2017-04-25  Volker Reichelt  <v.reichelt@netcologne.de>
 
        * g++.dg/cpp0x/enum34.C: New test.
diff --git a/gcc/testsuite/g++.dg/ubsan/pr80349-2.C b/gcc/testsuite/g++.dg/ubsan/pr80349-2.C
new file mode 100644 (file)
index 0000000..ca5ea4a
--- /dev/null
@@ -0,0 +1,11 @@
+// PR sanitizer/80349
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined" }
+
+unsigned long int ll;
+
+int
+foo ()
+{
+  return (2036854775807 >> ll & char(207648476159223) | 502810590243120797UL) << 0;
+}