From 444cda74708a494cc814951fe29d4904cec4f7e2 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 1 Nov 2018 13:31:45 +0100 Subject: [PATCH] re PR tree-optimization/87826 (ubsan: gimple-ssa-store-merging.c:281) PR tree-optimization/87826 * gimple-ssa-store-merging.c (do_shift_rotate): Punt if count is negative or larger or equal to type's precision. * gcc.dg/pr87826.c: New test. From-SVN: r265720 --- gcc/ChangeLog | 6 ++++++ gcc/gimple-ssa-store-merging.c | 4 +++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr87826.c | 13 +++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr87826.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f104208fae6..7b0950c9db9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-11-01 Jakub Jelinek + + PR tree-optimization/87826 + * gimple-ssa-store-merging.c (do_shift_rotate): Punt if count is + negative or larger or equal to type's precision. + 2018-10-31 Alexandre Oliva * opts.c (default_options_table): Do not enable diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index e1ddcb5e558..5e5823c44a0 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -262,7 +262,9 @@ do_shift_rotate (enum tree_code code, int i, size = TYPE_PRECISION (n->type) / BITS_PER_UNIT; unsigned head_marker; - if (count % BITS_PER_UNIT != 0) + if (count < 0 + || count >= TYPE_PRECISION (n->type) + || count % BITS_PER_UNIT != 0) return false; count = (count / BITS_PER_UNIT) * BITS_PER_MARKER; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5cb637306de..2dbe48063a9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-11-01 Jakub Jelinek + + PR tree-optimization/87826 + * gcc.dg/pr87826.c: New test. + 2018-11-01 Thomas Koenig PR fortran/46020 diff --git a/gcc/testsuite/gcc.dg/pr87826.c b/gcc/testsuite/gcc.dg/pr87826.c new file mode 100644 index 00000000000..cc5f14a49e5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87826.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/87826 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -w" } */ + +int c; + +void +foo (int *b) +{ + int e; + for (e = 0; e < 16; ++e) + b[e] = c >> e * 8; +} -- 2.30.2