Hi!

libsanitizer isn't right now prepared to handle vector types, and we don't
instrument vector additions/multiplications etc. for overflow etc. either,
so this patch just turns the single case that slipped through.

As I wrote in the PR, in the future we should probably change libubsan to
handle them and start instrumenting those.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-10-03  Jakub Jelinek  <ja...@redhat.com>

        PR sanitizer/77823
        * c-ubsan.c (ubsan_instrument_shift): Return NULL_TREE if type0
        is not integral.

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

--- gcc/c-family/c-ubsan.c.jj   2016-01-04 14:55:58.000000000 +0100
+++ gcc/c-family/c-ubsan.c      2016-10-03 13:49:49.423318587 +0200
@@ -114,6 +114,9 @@ ubsan_instrument_shift (location_t loc,
   tree t, tt = NULL_TREE;
   tree type0 = TREE_TYPE (op0);
   tree type1 = TREE_TYPE (op1);
+  if (!INTEGRAL_TYPE_P (type0))
+    return NULL_TREE;
+
   tree op1_utype = unsigned_type_for (type1);
   HOST_WIDE_INT op0_prec = TYPE_PRECISION (type0);
   tree uprecm1 = build_int_cst (op1_utype, op0_prec - 1);
@@ -126,8 +129,7 @@ ubsan_instrument_shift (location_t loc,
 
   /* If this is not a signed operation, don't perform overflow checks.
      Also punt on bit-fields.  */
-  if (!INTEGRAL_TYPE_P (type0)
-      || TYPE_OVERFLOW_WRAPS (type0)
+  if (TYPE_OVERFLOW_WRAPS (type0)
       || GET_MODE_BITSIZE (TYPE_MODE (type0)) != TYPE_PRECISION (type0))
     ;
 
--- gcc/testsuite/c-c++-common/ubsan/shift-9.c.jj       2016-10-03 
14:23:54.301711636 +0200
+++ gcc/testsuite/c-c++-common/ubsan/shift-9.c  2016-10-03 13:54:50.000000000 
+0200
@@ -0,0 +1,30 @@
+/* PR sanitizer/77823 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-fsanitize=undefined -Wno-psabi -w" } */
+
+typedef unsigned V __attribute__((vector_size(32)));
+typedef unsigned __int128 W __attribute__((vector_size(32)));
+
+V
+foo (V v)
+{
+  return v << 30;
+}
+
+V
+bar (V v, V w)
+{
+  return v << w;
+}
+
+W
+baz (W v)
+{
+  return v << 30;
+}
+
+W
+boo (W v, W w)
+{
+  return v << w;
+}

        Jakub

Reply via email to