From 587240d2494dae65fd67d5bd642a6123ecc89738 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 28 Feb 2017 15:31:30 +0000 Subject: [PATCH] re PR c/79731 (ICE: verify_gimple failed) 2017-02-28 Richard Biener PR middle-end/79731 * fold-const.c (decode_field_reference): Reject out-of-bound accesses. * c-c++-common/torture/pr79731.c: New testcase. From-SVN: r245779 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 6 +++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/torture/pr79731.c | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/torture/pr79731.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 87478eec431..b65f820950f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-02-28 Richard Biener + + PR middle-end/79731 + * fold-const.c (decode_field_reference): Reject out-of-bound + accesses. + 2017-02-28 Jakub Jelinek * config/i386/i386.c: Include intl.h. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ad4770b43d2..3d638360687 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4133,7 +4133,11 @@ decode_field_reference (location_t loc, tree *exp_, HOST_WIDE_INT *pbitsize, punsignedp, preversep, pvolatilep); if ((inner == exp && and_mask == 0) || *pbitsize < 0 || offset != 0 - || TREE_CODE (inner) == PLACEHOLDER_EXPR) + || TREE_CODE (inner) == PLACEHOLDER_EXPR + /* Reject out-of-bound accesses (PR79731). */ + || (! AGGREGATE_TYPE_P (TREE_TYPE (inner)) + && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)), + *pbitpos + *pbitsize) < 0)) return 0; *exp_ = exp; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b616b8a1738..82933d379f0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-28 Richard Biener + + PR middle-end/79731 + * c-c++-common/torture/pr79731.c: New testcase. + 2017-02-28 Richard Biener PR tree-optimization/79732 diff --git a/gcc/testsuite/c-c++-common/torture/pr79731.c b/gcc/testsuite/c-c++-common/torture/pr79731.c new file mode 100644 index 00000000000..cde26554b15 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/pr79731.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Wno-psabi -w" } */ + +typedef unsigned V __attribute__ ((vector_size (8))); +V +foo (unsigned x, V v) +{ + do { + v %= x; + x = 1; + } while (v[1]); + return v; +} +void fn2 () +{ + V x = foo (5, (V) { 0, 1 }); + if (x[0] || x[1] || x[2] || x[3]); +} -- 2.30.2