diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-07-26 15:11:42 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-07-28 13:13:05 +0200 |
commit | c936c39f86c74b3bfc6831f694b3165296c99dc0 (patch) | |
tree | 1ec07b3f72bc318fa0a2e16dbdac4b544c659154 /gcc/d/d-convert.cc | |
parent | 1a2306ffe79df89389cc850ce85c586d0f1c8264 (diff) | |
download | gcc-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-convert.cc')
-rw-r--r-- | gcc/d/d-convert.cc | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc index 3073eda..237c084 100644 --- a/gcc/d/d-convert.cc +++ b/gcc/d/d-convert.cc @@ -473,13 +473,18 @@ convert_expr (tree exp, Type *etype, Type *totype) tree ptrtype = build_ctype (tbtype->nextOf ()->pointerTo ()); - if ((dim * esize) % tsize != 0) + if (esize != tsize) { - error ("cannot cast %qs to %qs since sizes do not line up", - etype->toChars (), totype->toChars ()); - return error_mark_node; + /* Array element sizes do not match, so we must adjust the + dimensions. */ + if (tsize == 0 || (dim * esize) % tsize != 0) + { + error ("cannot cast %qs to %qs since sizes do not line up", + etype->toChars (), totype->toChars ()); + return error_mark_node; + } + dim = (dim * esize) / tsize; } - dim = (dim * esize) / tsize; /* Assumes casting to dynamic array of same type or void. */ return d_array_value (build_ctype (totype), size_int (dim), |