diff options
author | Jakub Jelinek <jakub@redhat.com> | 2016-10-05 19:47:34 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2016-10-05 19:47:34 +0200 |
commit | 04a324433515f0b1076cb84b2a8e27c2025cd9d4 (patch) | |
tree | fc63c16bd7f5f9e56b8b863515dd226fa4500cc4 /gcc | |
parent | 743a9cf79aee4f5a645991a9fda20e15050d32f3 (diff) | |
download | gcc-04a324433515f0b1076cb84b2a8e27c2025cd9d4.zip gcc-04a324433515f0b1076cb84b2a8e27c2025cd9d4.tar.gz gcc-04a324433515f0b1076cb84b2a8e27c2025cd9d4.tar.bz2 |
re PR sanitizer/77823 (ICE: in ubsan_encode_value, at ubsan.c:137 with -fsanitize=undefined and vector types)
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.
From-SVN: r240796
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/c-family/c-ubsan.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/ubsan/shift-9.c | 30 |
4 files changed, 43 insertions, 2 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index ea4278c..d3c7cd5 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,5 +1,9 @@ 2016-10-05 Jakub Jelinek <jakub@redhat.com> + PR sanitizer/77823 + * c-ubsan.c (ubsan_instrument_shift): Return NULL_TREE if type0 + is not integral. + * c-common.c (c_common_reswords): Update comment for C++11. 2016-10-04 Jason Merrill <jason@redhat.com> diff --git a/gcc/c-family/c-ubsan.c b/gcc/c-family/c-ubsan.c index 4022bdf..df7b932 100644 --- a/gcc/c-family/c-ubsan.c +++ b/gcc/c-family/c-ubsan.c @@ -114,6 +114,9 @@ ubsan_instrument_shift (location_t loc, enum tree_code code, 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, enum tree_code code, /* 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)) ; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 722fb82..54d64ee 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-10-05 Jakub Jelinek <jakub@redhat.com> + + PR sanitizer/77823 + * c-c++-common/ubsan/shift-9.c: New test. + 2016-10-05 Senthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com> * gcc.dg/torture/pr69941.c: Use __INT32_TYPE__ instead diff --git a/gcc/testsuite/c-c++-common/ubsan/shift-9.c b/gcc/testsuite/c-c++-common/ubsan/shift-9.c new file mode 100644 index 0000000..5f3fc3a --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/shift-9.c @@ -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; +} |