From 6aa238a135b3d889e3efe8d5c8ac3ad236a27924 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Wed, 30 Jan 2019 03:04:14 +0000 Subject: 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 --- gcc/gimple-fold.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'gcc/gimple-fold.c') 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. */ -- cgit v1.1