From f59be8dfbd85a7f8face7340950503750a8bfddb Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sun, 29 Nov 2020 12:49:52 +0100 Subject: [PATCH] d: Remove d_size_t from front-end sources (PR 87788) The typedef for d_size_t assumes that the implementation of the front-end is written in D itself, where size_t can map only to uint32_t or uint64_t. As that is not the case for the current D front-end, the typedef should be removed. This would fix the bootstrap on targets where in C++ size_t is a long, such as darwin i386. Reviewed-on: https://github.com/dlang/dmd/pull/12008 gcc/d/ChangeLog: PR d/87788 * dmd/MERGE: Merge upsream dmd 45fa6cfd2. --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/expression.c | 2 +- gcc/d/dmd/expression.h | 2 +- gcc/d/dmd/mtype.h | 3 +-- gcc/d/dmd/root/array.h | 28 ++++++++++++++-------------- gcc/d/dmd/root/bitarray.h | 4 ++-- gcc/d/dmd/root/dcompat.h | 12 ------------ gcc/d/dmd/root/outbuffer.h | 4 ++-- gcc/d/dmd/root/rmem.h | 10 +++++----- gcc/d/dmd/root/stringtable.h | 9 ++++----- 10 files changed, 31 insertions(+), 45 deletions(-) diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 453c5e8fd9c..4fa62a9f56a 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -db0df3f7e6f2570f81d6c91ba173daa23361ea7b +45fa6cfd20827bb4252a616dc789514a1e673687 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 2ad75edb27c..09dd3af6eac 100644 --- a/gcc/d/dmd/expression.c +++ b/gcc/d/dmd/expression.c @@ -4340,7 +4340,7 @@ Expression *ArrayLiteralExp::syntaxCopy() arraySyntaxCopy(elements)); } -Expression *ArrayLiteralExp::getElement(d_size_t i) +Expression *ArrayLiteralExp::getElement(size_t i) { Expression *el = (*elements)[i]; if (!el) diff --git a/gcc/d/dmd/expression.h b/gcc/d/dmd/expression.h index fde029ce146..ccfaa65f764 100644 --- a/gcc/d/dmd/expression.h +++ b/gcc/d/dmd/expression.h @@ -523,7 +523,7 @@ public: static ArrayLiteralExp *create(Loc loc, Expressions *elements); Expression *syntaxCopy(); bool equals(RootObject *o); - Expression *getElement(d_size_t i); + Expression *getElement(size_t i); static Expressions* copyElements(Expression *e1, Expression *e2 = NULL); bool isBool(bool result); StringExp *toStringExp(); diff --git a/gcc/d/dmd/mtype.h b/gcc/d/dmd/mtype.h index 4e28deadea7..b0878c8f730 100644 --- a/gcc/d/dmd/mtype.h +++ b/gcc/d/dmd/mtype.h @@ -12,7 +12,6 @@ #include "root/root.h" #include "root/stringtable.h" -#include "root/dcompat.h" // for d_size_t #include "arraytypes.h" #include "ast_node.h" @@ -635,7 +634,7 @@ public: static Parameters *arraySyntaxCopy(Parameters *parameters); static size_t dim(Parameters *parameters); - static Parameter *getNth(Parameters *parameters, d_size_t nth, d_size_t *pn = NULL); + static Parameter *getNth(Parameters *parameters, size_t nth, size_t *pn = NULL); const char *toChars(); bool isCovariant(bool returnByRef, const Parameter *p) const; static bool isCovariantScope(bool returnByRef, StorageClass from, StorageClass to); diff --git a/gcc/d/dmd/root/array.h b/gcc/d/dmd/root/array.h index fb838e69f4b..d4eccd86dbd 100644 --- a/gcc/d/dmd/root/array.h +++ b/gcc/d/dmd/root/array.h @@ -16,7 +16,7 @@ template struct Array { - d_size_t length; + size_t length; private: DArray data; @@ -42,8 +42,8 @@ struct Array char *toChars() const { const char **buf = (const char **)mem.xmalloc(length * sizeof(const char *)); - d_size_t len = 2; - for (d_size_t u = 0; u < length; u++) + size_t len = 2; + for (size_t u = 0; u < length; u++) { buf[u] = ((RootObject *)data.ptr[u])->toChars(); len += strlen(buf[u]) + 1; @@ -52,7 +52,7 @@ struct Array str[0] = '['; char *p = str + 1; - for (d_size_t u = 0; u < length; u++) + for (size_t u = 0; u < length; u++) { if (u) *p++ = ','; @@ -77,7 +77,7 @@ struct Array insert(length, a); } - void reserve(d_size_t nentries) + void reserve(size_t nentries) { //printf("Array::reserve: length = %d, data.length = %d, nentries = %d\n", (int)length, (int)data.length, (int)nentries); if (data.length - length < nentries) @@ -106,7 +106,7 @@ struct Array { /* Increase size by 1.5x to avoid excessive memory fragmentation */ - d_size_t increment = length / 2; + size_t increment = length / 2; if (nentries > increment) // if 1.5 is not enough increment = nentries; data.length = length + increment; @@ -115,18 +115,18 @@ struct Array } } - void remove(d_size_t i) + void remove(size_t i) { if (length - i - 1) memmove(data.ptr + i, data.ptr + i + 1, (length - i - 1) * sizeof(TYPE)); length--; } - void insert(d_size_t index, Array *a) + void insert(size_t index, Array *a) { if (a) { - d_size_t d = a->length; + size_t d = a->length; reserve(d); if (length != index) memmove(data.ptr + index + d, data.ptr + index, (length - index) * sizeof(TYPE)); @@ -135,7 +135,7 @@ struct Array } } - void insert(d_size_t index, TYPE ptr) + void insert(size_t index, TYPE ptr) { reserve(1); memmove(data.ptr + index + 1, data.ptr + index, (length - index) * sizeof(TYPE)); @@ -143,7 +143,7 @@ struct Array length++; } - void setDim(d_size_t newdim) + void setDim(size_t newdim) { if (length < newdim) { @@ -152,9 +152,9 @@ struct Array length = newdim; } - d_size_t find(TYPE ptr) const + size_t find(TYPE ptr) const { - for (d_size_t i = 0; i < length; i++) + for (size_t i = 0; i < length; i++) { if (data.ptr[i] == ptr) return i; @@ -167,7 +167,7 @@ struct Array return find(ptr) != SIZE_MAX; } - TYPE& operator[] (d_size_t index) + TYPE& operator[] (size_t index) { #ifdef DEBUG assert(index < length); diff --git a/gcc/d/dmd/root/bitarray.h b/gcc/d/dmd/root/bitarray.h index fa01dd990d9..195e3beef57 100644 --- a/gcc/d/dmd/root/bitarray.h +++ b/gcc/d/dmd/root/bitarray.h @@ -24,8 +24,8 @@ struct BitArray mem.xfree(ptr); } - d_size_t len; - d_size_t *ptr; + size_t len; + size_t *ptr; private: BitArray(const BitArray&); diff --git a/gcc/d/dmd/root/dcompat.h b/gcc/d/dmd/root/dcompat.h index 72326d5ff65..5aec84e1239 100644 --- a/gcc/d/dmd/root/dcompat.h +++ b/gcc/d/dmd/root/dcompat.h @@ -34,15 +34,3 @@ struct DString : public DArray DString(size_t length, const char *ptr) : DArray(length, ptr) { } }; - -/// Corresponding C++ type that maps to D size_t -#if __APPLE__ && __i386__ -// size_t is 'unsigned long', which makes it mangle differently than D's 'uint' -typedef unsigned d_size_t; -#elif MARS && DMD_VERSION >= 2079 && DMD_VERSION <= 2081 && \ - __APPLE__ && __SIZEOF_SIZE_T__ == 8 -// DMD versions between 2.079 and 2.081 mapped D ulong to uint64_t on OS X. -typedef uint64_t d_size_t; -#else -typedef size_t d_size_t; -#endif diff --git a/gcc/d/dmd/root/outbuffer.h b/gcc/d/dmd/root/outbuffer.h index 49b1c3e5bcf..2ff5ee9b09c 100644 --- a/gcc/d/dmd/root/outbuffer.h +++ b/gcc/d/dmd/root/outbuffer.h @@ -39,13 +39,13 @@ public: mem.xfree(data.ptr); } const DArray slice() const { return data; } - d_size_t length() const { return offset; } + size_t length() const { return offset; } char *extractData(); void reserve(size_t nbytes); void setsize(size_t size); void reset(); - void write(const void *data, d_size_t nbytes); + void write(const void *data, size_t nbytes); void writestring(const char *string); void prependstring(const char *string); void writenl(); // write newline diff --git a/gcc/d/dmd/root/rmem.h b/gcc/d/dmd/root/rmem.h index 7f5e98091e9..fdb8676c2b9 100644 --- a/gcc/d/dmd/root/rmem.h +++ b/gcc/d/dmd/root/rmem.h @@ -8,18 +8,18 @@ #pragma once -#include "dcompat.h" // for d_size_t +#include "dsystem.h" // for size_t struct Mem { Mem() { } static char *xstrdup(const char *s); - static void *xmalloc(d_size_t size); - static void *xcalloc(d_size_t size, d_size_t n); - static void *xrealloc(void *p, d_size_t size); + static void *xmalloc(size_t size); + static void *xcalloc(size_t size, size_t n); + static void *xrealloc(void *p, size_t size); static void xfree(void *p); - static void *xmallocdup(void *o, d_size_t size); + static void *xmallocdup(void *o, size_t size); static void error(); }; diff --git a/gcc/d/dmd/root/stringtable.h b/gcc/d/dmd/root/stringtable.h index 7df5c873c1c..8cbdbd8a91f 100644 --- a/gcc/d/dmd/root/stringtable.h +++ b/gcc/d/dmd/root/stringtable.h @@ -9,7 +9,6 @@ #pragma once #include "root.h" -#include "dcompat.h" // for d_size_t struct StringEntry; @@ -40,13 +39,13 @@ private: size_t count; public: - void _init(d_size_t size = 0); - void reset(d_size_t size = 0); + void _init(size_t size = 0); + void reset(size_t size = 0); ~StringTable(); - StringValue *lookup(const char *s, d_size_t len); + StringValue *lookup(const char *s, size_t len); StringValue *insert(const char *s, size_t len, void *ptrvalue); - StringValue *update(const char *s, d_size_t len); + StringValue *update(const char *s, size_t len); int apply(int (*fp)(StringValue *)); private: -- 2.30.2