c-ubsan.c (ubsan_instrument_shift): Use op1_utype for MINUS_EXPR instead of unsigned_...
authorMarek Polacek <polacek@redhat.com>
Fri, 28 Nov 2014 15:54:52 +0000 (15:54 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 28 Nov 2014 15:54:52 +0000 (15:54 +0000)
* c-ubsan.c (ubsan_instrument_shift): Use op1_utype for MINUS_EXPR
instead of unsigned_type_node.

* c-c++-common/ubsan/shift-8.c: New test.

From-SVN: r218163

gcc/c-family/ChangeLog
gcc/c-family/c-ubsan.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/shift-8.c [new file with mode: 0644]

index efb4735f01adf58ae22678015d85caea8a43a9c8..e329bf787e4addfdd47cebb46979c433e36bfd4c 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-28  Marek Polacek  <polacek@redhat.com>
+
+       * c-ubsan.c (ubsan_instrument_shift): Use op1_utype for MINUS_EXPR
+       instead of unsigned_type_node.
+
 2014-11-28  Marek Polacek  <polacek@redhat.com>
 
        PR c/63862
index 96afc674866b5f6f6d0b62d92200f7f4170253cd..5c039caa5609e7e21f4a86c94cb7e2bbc409df92 100644 (file)
@@ -166,7 +166,7 @@ ubsan_instrument_shift (location_t loc, enum tree_code code,
       && !TYPE_UNSIGNED (TREE_TYPE (op0))
       && (cxx_dialect >= cxx11))
     {
-      tree x = fold_build2 (MINUS_EXPR, unsigned_type_node, uprecm1,
+      tree x = fold_build2 (MINUS_EXPR, op1_utype, uprecm1,
                            fold_convert (op1_utype, op1));
       tt = fold_convert_loc (loc, unsigned_type_for (type0), op0);
       tt = fold_build2 (RSHIFT_EXPR, TREE_TYPE (tt), tt, x);
index 3528b18837b4dbb1706dc56afa34982ab7d352bc..39aa1789e43055f14ab31fa3ca20c33018d1c5d6 100644 (file)
@@ -1,3 +1,7 @@
+2014-11-28  Marek Polacek  <polacek@redhat.com>
+
+       * c-c++-common/ubsan/shift-8.c: New test.
+
 2014-11-28  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/64087
diff --git a/gcc/testsuite/c-c++-common/ubsan/shift-8.c b/gcc/testsuite/c-c++-common/ubsan/shift-8.c
new file mode 100644 (file)
index 0000000..8717f3f
--- /dev/null
@@ -0,0 +1,64 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined" } */
+/* { dg-additional-options "-std=gnu11" { target c } } */
+/* { dg-additional-options "-std=c++11" { target c++ } } */
+
+signed char
+fn1 (signed char x, unsigned long y)
+{
+  return x << y;
+}
+
+short int
+fn2 (short int x, unsigned long y)
+{
+  return x << y;
+}
+
+int
+fn3 (int x, unsigned long y)
+{
+  return x << y;
+}
+
+long int
+fn4 (long int x, unsigned long y)
+{
+  return x << y;
+}
+
+long long int
+fn5 (long long int x, unsigned long y)
+{
+  return x << y;
+}
+
+signed char
+fn6 (signed char x, unsigned long long y)
+{
+  return x << y;
+}
+
+short int
+fn7 (short int x, unsigned long long y)
+{
+  return x << y;
+}
+
+int
+fn8 (int x, unsigned long long y)
+{
+  return x << y;
+}
+
+long int
+fn9 (long int x, unsigned long long y)
+{
+  return x << y;
+}
+
+long long int
+fn10 (long long int x, unsigned long long y)
+{
+  return x << y;
+}