diff options
author | Martin Sebor <msebor@redhat.com> | 2019-01-30 03:04:14 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-01-29 20:04:14 -0700 |
commit | 6aa238a135b3d889e3efe8d5c8ac3ad236a27924 (patch) | |
tree | 7957ace73cf42e859e1cd02afe93c3e5e019c3fb /gcc/gimple-fold.c | |
parent | 538a530848375deb14495fae5a5ccf5ae5daedba (diff) | |
download | gcc-6aa238a135b3d889e3efe8d5c8ac3ad236a27924.zip gcc-6aa238a135b3d889e3efe8d5c8ac3ad236a27924.tar.gz gcc-6aa238a135b3d889e3efe8d5c8ac3ad236a27924.tar.bz2 |
PR middle-end/88956 - ICE: Floating point exception on a memcpy from
PR middle-end/88956 - ICE: Floating point exception on a memcpy from
a zero-length constant array
gcc/ChangeLog:
PR c/88956
* gimple-fold.c (fold_array_ctor_reference): Avoid zero-length arrays.
gcc/testsuite/ChangeLog:
PR c/88956
* gcc.dg/Warray-bounds-39.c: New test.
From-SVN: r268378
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 500e551..7ef5004 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -6702,25 +6702,27 @@ fold_array_ctor_reference (tree type, tree ctor, domain_type = TYPE_DOMAIN (TREE_TYPE (ctor)); if (domain_type && TYPE_MIN_VALUE (domain_type)) { - /* Static constructors for variably sized objects makes no sense. */ + /* Static constructors for variably sized objects make no sense. */ if (TREE_CODE (TYPE_MIN_VALUE (domain_type)) != INTEGER_CST) return NULL_TREE; low_bound = wi::to_offset (TYPE_MIN_VALUE (domain_type)); } else low_bound = 0; - /* Static constructors for variably sized objects makes no sense. */ + /* Static constructors for variably sized objects make no sense. */ if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ctor)))) != INTEGER_CST) return NULL_TREE; elt_size = wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ctor)))); /* When TYPE is non-null, verify that it specifies a constant-sized - accessed not larger than size of array element. */ - if (type - && (!TYPE_SIZE_UNIT (type) - || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST - || elt_size < wi::to_offset (TYPE_SIZE_UNIT (type)) - || elt_size == 0)) + accessed not larger than size of array element. Avoid division + by zero below when ELT_SIZE is zero, such as with the result of + an initializer for a zero-length array or an empty struct. */ + if (elt_size == 0 + || (type + && (!TYPE_SIZE_UNIT (type) + || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST + || elt_size < wi::to_offset (TYPE_SIZE_UNIT (type))))) return NULL_TREE; /* Compute the array index we look for. */ |