From de83a4c14b4715f4ecd42d3f3024edf31ae8d714 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Wed, 21 Aug 2019 07:53:35 +0000 Subject: [PATCH] d/dmd: Merge upstream dmd 375ed10aa Don't crash when compiling for 16-bit platforms. Reviewed-on: https://github.com/dlang/dmd/pull/10306 gcc/d/ChangeLog: * d-target.cc: Include diagnostic.h. (Target::_init): Set Tsize_t and Tptrdiff_t as D ushort and short if the target pointer size is 2. Add sorry if the pointer size is not either 2, 4, or 8. From-SVN: r274768 --- gcc/d/ChangeLog | 7 +++++++ gcc/d/d-target.cc | 12 ++++++++++-- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/expression.c | 8 +++++--- gcc/d/dmd/hdrgen.c | 14 +++++++------- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/gcc/d/ChangeLog b/gcc/d/ChangeLog index 41ea48e8b15..011b0d44fa0 100644 --- a/gcc/d/ChangeLog +++ b/gcc/d/ChangeLog @@ -1,3 +1,10 @@ +2019-08-20 Iain Buclaw + + * d-target.cc: Include diagnostic.h. + (Target::_init): Set Tsize_t and Tptrdiff_t as D ushort and short if + the target pointer size is 2. Add sorry if the pointer size is not + either 2, 4, or 8. + 2019-08-20 Iain Buclaw PR d/90446 diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc index 8d85534f054..dfaf9bf3792 100644 --- a/gcc/d/d-target.cc +++ b/gcc/d/d-target.cc @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "memmodel.h" #include "fold-const.h" +#include "diagnostic.h" #include "stor-layout.h" #include "tm.h" #include "tm_p.h" @@ -145,17 +146,24 @@ Target::_init (void) Target::maxStaticDataSize = tree_to_shwi (TYPE_MAX_VALUE (integer_type_node)); /* Define what type to use for size_t, ptrdiff_t. */ - if (POINTER_SIZE == 64) + if (Target::ptrsize == 8) { global.params.isLP64 = true; Tsize_t = Tuns64; Tptrdiff_t = Tint64; } - else + else if (Target::ptrsize == 4) { Tsize_t = Tuns32; Tptrdiff_t = Tint32; } + else if (Target::ptrsize == 2) + { + Tsize_t = Tuns16; + Tptrdiff_t = Tint16; + } + else + sorry ("D does not support pointers on this target."); Type::tsize_t = Type::basic[Tsize_t]; Type::tptrdiff_t = Type::basic[Tptrdiff_t]; diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index d208aea3717..cb7b6bfac7f 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -792f0fdf249b21531dc91690024827f4f9ecbb97 +375ed10aa7eb28755f92775ca5c5399550cd100b The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/expression.c b/gcc/d/dmd/expression.c index c674392095e..5f1bfa8f5a9 100644 --- a/gcc/d/dmd/expression.c +++ b/gcc/d/dmd/expression.c @@ -2920,10 +2920,12 @@ void IntegerExp::normalize() case Tint64: value = (d_int64) value; break; case Tuns64: value = (d_uns64) value; break; case Tpointer: - if (Target::ptrsize == 4) - value = (d_uns32) value; - else if (Target::ptrsize == 8) + if (Target::ptrsize == 8) value = (d_uns64) value; + else if (Target::ptrsize == 4) + value = (d_uns32) value; + else if (Target::ptrsize == 2) + value = (d_uns16) value; else assert(0); break; diff --git a/gcc/d/dmd/hdrgen.c b/gcc/d/dmd/hdrgen.c index 4eaa1ae1050..395aa3212b5 100644 --- a/gcc/d/dmd/hdrgen.c +++ b/gcc/d/dmd/hdrgen.c @@ -2152,10 +2152,12 @@ public: if ((sinteger_t)uval >= 0) { dinteger_t sizemax; - if (Target::ptrsize == 4) - sizemax = 0xFFFFFFFFUL; - else if (Target::ptrsize == 8) + if (Target::ptrsize == 8) sizemax = 0xFFFFFFFFFFFFFFFFULL; + else if (Target::ptrsize == 4) + sizemax = 0xFFFFFFFFUL; + else if (Target::ptrsize == 2) + sizemax = 0xFFFFUL; else assert(0); if (uval <= sizemax && uval <= 0x7FFFFFFFFFFFFFFFULL) @@ -2296,12 +2298,10 @@ public: buf->writestring("cast("); buf->writestring(t->toChars()); buf->writeByte(')'); - if (Target::ptrsize == 4) - goto L3; - else if (Target::ptrsize == 8) + if (Target::ptrsize == 8) goto L4; else - assert(0); + goto L3; default: /* This can happen if errors, such as -- 2.30.2