From: mpolacek Date: Fri, 28 Nov 2014 15:54:52 +0000 (+0000) Subject: * c-ubsan.c (ubsan_instrument_shift): Use op1_utype for MINUS_EXPR X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d2f605930dc1b75844c4bdaa97410b6d7f316bf7;p=thirdparty%2Fgcc.git * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218163 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index efb4735f01ad..e329bf787e4a 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2014-11-28 Marek Polacek + + * c-ubsan.c (ubsan_instrument_shift): Use op1_utype for MINUS_EXPR + instead of unsigned_type_node. + 2014-11-28 Marek Polacek PR c/63862 diff --git a/gcc/c-family/c-ubsan.c b/gcc/c-family/c-ubsan.c index 96afc674866b..5c039caa5609 100644 --- a/gcc/c-family/c-ubsan.c +++ b/gcc/c-family/c-ubsan.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3528b18837b4..39aa1789e430 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-11-28 Marek Polacek + + * c-c++-common/ubsan/shift-8.c: New test. + 2014-11-28 Vladimir Makarov 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 index 000000000000..8717f3f34276 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/shift-8.c @@ -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; +}