aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/d-codegen.cc
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2021-07-26 15:11:42 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2021-07-28 13:13:05 +0200
commitc936c39f86c74b3bfc6831f694b3165296c99dc0 (patch)
tree1ec07b3f72bc318fa0a2e16dbdac4b544c659154 /gcc/d/d-codegen.cc
parent1a2306ffe79df89389cc850ce85c586d0f1c8264 (diff)
downloadgcc-c936c39f86c74b3bfc6831f694b3165296c99dc0.zip
gcc-c936c39f86c74b3bfc6831f694b3165296c99dc0.tar.gz
gcc-c936c39f86c74b3bfc6831f694b3165296c99dc0.tar.bz2
d: fix ICE at convert_expr(tree_node*, Type*, Type*) (PR101490)
Both the front-end and code generator had a modulo by zero bug when testing if a conversion from a static array to dynamic array was valid. PR d/101490 gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 27e388b4c. * d-codegen.cc (build_array_index): Handle void arrays same as byte. * d-convert.cc (convert_expr): Handle converting to zero-sized arrays. gcc/testsuite/ChangeLog: * gdc.dg/pr101490.d: New test.
Diffstat (limited to 'gcc/d/d-codegen.cc')
-rw-r--r--gcc/d/d-codegen.cc16
1 files changed, 2 insertions, 14 deletions
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index ce7c17b..f35de90 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1639,21 +1639,9 @@ build_array_index (tree ptr, tree index)
/* Array element size. */
tree size_exp = size_in_bytes (target_type);
- if (integer_zerop (size_exp))
+ if (integer_zerop (size_exp) || integer_onep (size_exp))
{
- /* Test for array of void. */
- if (TYPE_MODE (target_type) == TYPE_MODE (void_type_node))
- index = fold_convert (type, index);
- else
- {
- /* Should catch this earlier. */
- error ("invalid use of incomplete type %qD", TYPE_NAME (target_type));
- ptr_type = error_mark_node;
- }
- }
- else if (integer_onep (size_exp))
- {
- /* Array of bytes -- No need to multiply. */
+ /* Array of void or bytes -- No need to multiply. */
index = fold_convert (type, index);
}
else