Commit 255b2d91 by Iain Buclaw Committed by Iain Buclaw

Merge dmd upstream 180465274

Reduces the memory footprint of the CTFE interpreter by replacing new
with emplacement new in many places.

gcc/d/ChangeLog:

2019-01-21  Iain Buclaw  <ibuclaw@gdcproject.org>

	* d-frontend.cc (Compiler::paintAsType): Update for new signature.

From-SVN: r268124
parent d5011496
2019-01-21 Iain Buclaw <ibuclaw@gdcproject.org>
* d-frontend.cc (Compiler::paintAsType): Update for new signature.
2019-01-20 Iain Buclaw <ibuclaw@gdcproject.org> 2019-01-20 Iain Buclaw <ibuclaw@gdcproject.org>
* d-builtins.cc (d_init_versions): Check value of * d-builtins.cc (d_init_versions): Check value of
......
...@@ -446,7 +446,7 @@ Compiler::genCmain (Scope *sc) ...@@ -446,7 +446,7 @@ Compiler::genCmain (Scope *sc)
so we just lower the value to GCC and return the converted CST. */ so we just lower the value to GCC and return the converted CST. */
Expression * Expression *
Compiler::paintAsType (Expression *expr, Type *type) Compiler::paintAsType (UnionExp *, Expression *expr, Type *type)
{ {
/* We support up to 512-bit values. */ /* We support up to 512-bit values. */
unsigned char buffer[64]; unsigned char buffer[64];
......
cd2034cd7b157dd8f3e94c684061bb1aa630b2b6 180465274b72a2ff218449f6793af0fbaabbcaa3
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository. merge done from the dlang/dmd repository.
...@@ -19,6 +19,7 @@ class Expression; ...@@ -19,6 +19,7 @@ class Expression;
class Module; class Module;
class Type; class Type;
struct Scope; struct Scope;
struct UnionExp;
// DMD-generated module `__entrypoint` where the C main resides // DMD-generated module `__entrypoint` where the C main resides
extern Module *entrypoint; extern Module *entrypoint;
...@@ -28,7 +29,7 @@ extern Module *rootHasMain; ...@@ -28,7 +29,7 @@ extern Module *rootHasMain;
struct Compiler struct Compiler
{ {
// CTFE support for cross-compilation. // CTFE support for cross-compilation.
static Expression *paintAsType(Expression *, Type *); static Expression *paintAsType(UnionExp *, Expression *, Type *);
// Backend // Backend
static void loadModule(Module *); static void loadModule(Module *);
static void genCmain(Scope *); static void genCmain(Scope *);
......
...@@ -1457,8 +1457,7 @@ UnionExp Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr) ...@@ -1457,8 +1457,7 @@ UnionExp Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
memcpy(elements->tdata(), memcpy(elements->tdata(),
es1->elements->tdata() + ilwr, es1->elements->tdata() + ilwr,
(size_t)(iupr - ilwr) * sizeof((*es1->elements)[0])); (size_t)(iupr - ilwr) * sizeof((*es1->elements)[0]));
new(&ue) ArrayLiteralExp(e1->loc, elements); new(&ue) ArrayLiteralExp(e1->loc, type, elements);
ue.exp()->type = type;
} }
} }
else else
...@@ -1606,6 +1605,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1606,6 +1605,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
new(&ue) StringExp(loc, s, len); new(&ue) StringExp(loc, s, len);
StringExp *es = (StringExp *)ue.exp(); StringExp *es = (StringExp *)ue.exp();
es->type = type;
es->sz = sz; es->sz = sz;
es->committed = 1; es->committed = 1;
} }
...@@ -1614,9 +1614,8 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1614,9 +1614,8 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
// Create an ArrayLiteralExp // Create an ArrayLiteralExp
Expressions *elements = new Expressions(); Expressions *elements = new Expressions();
elements->push(e); elements->push(e);
new(&ue) ArrayLiteralExp(e->loc, elements); new(&ue) ArrayLiteralExp(e->loc, type, elements);
} }
ue.exp()->type = type;
assert(ue.exp()->type); assert(ue.exp()->type);
return ue; return ue;
} }
...@@ -1627,8 +1626,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1627,8 +1626,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
// Handle null ~= null // Handle null ~= null
if (t1->ty == Tarray && t2 == t1->nextOf()) if (t1->ty == Tarray && t2 == t1->nextOf())
{ {
new(&ue) ArrayLiteralExp(e1->loc, e2); new(&ue) ArrayLiteralExp(e1->loc, type, e2);
ue.exp()->type = type;
assert(ue.exp()->type); assert(ue.exp()->type);
return ue; return ue;
} }
...@@ -1695,9 +1693,8 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1695,9 +1693,8 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
{ {
(*elems)[i] = ea->getElement(i); (*elems)[i] = ea->getElement(i);
} }
new(&ue) ArrayLiteralExp(e1->loc, elems); new(&ue) ArrayLiteralExp(e1->loc, type, elems);
ArrayLiteralExp *dest = (ArrayLiteralExp *)ue.exp(); ArrayLiteralExp *dest = (ArrayLiteralExp *)ue.exp();
dest->type = type;
sliceAssignArrayLiteralFromString(dest, es, ea->elements->dim); sliceAssignArrayLiteralFromString(dest, es, ea->elements->dim);
assert(ue.exp()->type); assert(ue.exp()->type);
return ue; return ue;
...@@ -1715,9 +1712,8 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1715,9 +1712,8 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
{ {
(*elems)[es->len + i] = ea->getElement(i); (*elems)[es->len + i] = ea->getElement(i);
} }
new(&ue) ArrayLiteralExp(e1->loc, elems); new(&ue) ArrayLiteralExp(e1->loc, type, elems);
ArrayLiteralExp *dest = (ArrayLiteralExp *)ue.exp(); ArrayLiteralExp *dest = (ArrayLiteralExp *)ue.exp();
dest->type = type;
sliceAssignArrayLiteralFromString(dest, es, 0); sliceAssignArrayLiteralFromString(dest, es, 0);
assert(ue.exp()->type); assert(ue.exp()->type);
return ue; return ue;
...@@ -1783,7 +1779,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1783,7 +1779,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
// Concatenate the arrays // Concatenate the arrays
Expressions *elems = ArrayLiteralExp::copyElements(e1, e2); Expressions *elems = ArrayLiteralExp::copyElements(e1, e2);
new(&ue) ArrayLiteralExp(e1->loc, elems); new(&ue) ArrayLiteralExp(e1->loc, NULL, elems);
e = ue.exp(); e = ue.exp();
if (type->toBasetype()->ty == Tsarray) if (type->toBasetype()->ty == Tsarray)
...@@ -1809,7 +1805,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1809,7 +1805,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
// Concatenate the array with null // Concatenate the array with null
Expressions *elems = ArrayLiteralExp::copyElements(e); Expressions *elems = ArrayLiteralExp::copyElements(e);
new(&ue) ArrayLiteralExp(e->loc, elems); new(&ue) ArrayLiteralExp(e->loc, NULL, elems);
e = ue.exp(); e = ue.exp();
if (type->toBasetype()->ty == Tsarray) if (type->toBasetype()->ty == Tsarray)
...@@ -1829,7 +1825,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1829,7 +1825,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
? ArrayLiteralExp::copyElements(e1) : new Expressions(); ? ArrayLiteralExp::copyElements(e1) : new Expressions();
elems->push(e2); elems->push(e2);
new(&ue) ArrayLiteralExp(e1->loc, elems); new(&ue) ArrayLiteralExp(e1->loc, NULL, elems);
e = ue.exp(); e = ue.exp();
if (type->toBasetype()->ty == Tsarray) if (type->toBasetype()->ty == Tsarray)
...@@ -1846,7 +1842,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1846,7 +1842,7 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
{ {
Expressions *elems = ArrayLiteralExp::copyElements(e1, e2); Expressions *elems = ArrayLiteralExp::copyElements(e1, e2);
new(&ue) ArrayLiteralExp(e2->loc, elems); new(&ue) ArrayLiteralExp(e2->loc, NULL, elems);
e = ue.exp(); e = ue.exp();
if (type->toBasetype()->ty == Tsarray) if (type->toBasetype()->ty == Tsarray)
...@@ -1874,9 +1870,8 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2) ...@@ -1874,9 +1870,8 @@ UnionExp Cat(Type *type, Expression *e1, Expression *e2)
{ {
Expressions *expressions = new Expressions(); Expressions *expressions = new Expressions();
expressions->push(e); expressions->push(e);
new(&ue) ArrayLiteralExp(loc, expressions); new(&ue) ArrayLiteralExp(loc, t, expressions);
e = ue.exp(); e = ue.exp();
e->type = t;
} }
else else
{ {
......
...@@ -134,6 +134,7 @@ UnionExp copyLiteral(Expression *e); ...@@ -134,6 +134,7 @@ UnionExp copyLiteral(Expression *e);
/// Set this literal to the given type, copying it if necessary /// Set this literal to the given type, copying it if necessary
Expression *paintTypeOntoLiteral(Type *type, Expression *lit); Expression *paintTypeOntoLiteral(Type *type, Expression *lit);
Expression *paintTypeOntoLiteral(UnionExp *pue, Type *type, Expression *lit);
UnionExp paintTypeOntoLiteralCopy(Type *type, Expression *lit); UnionExp paintTypeOntoLiteralCopy(Type *type, Expression *lit);
/// Convert from a CTFE-internal slice, into a normal Expression /// Convert from a CTFE-internal slice, into a normal Expression
...@@ -143,11 +144,11 @@ Expression *resolveSlice(Expression *e, UnionExp *pue = NULL); ...@@ -143,11 +144,11 @@ Expression *resolveSlice(Expression *e, UnionExp *pue = NULL);
uinteger_t resolveArrayLength(Expression *e); uinteger_t resolveArrayLength(Expression *e);
/// Create an array literal consisting of 'elem' duplicated 'dim' times. /// Create an array literal consisting of 'elem' duplicated 'dim' times.
ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type, ArrayLiteralExp *createBlockDuplicatedArrayLiteral(UnionExp *pue, Loc loc, Type *type,
Expression *elem, size_t dim); Expression *elem, size_t dim);
/// Create a string literal consisting of 'value' duplicated 'dim' times. /// Create a string literal consisting of 'value' duplicated 'dim' times.
StringExp *createBlockDuplicatedStringLiteral(Loc loc, Type *type, StringExp *createBlockDuplicatedStringLiteral(UnionExp *pue, Loc loc, Type *type,
unsigned value, size_t dim, unsigned char sz); unsigned value, size_t dim, unsigned char sz);
...@@ -209,7 +210,7 @@ UnionExp pointerArithmetic(Loc loc, TOK op, Type *type, ...@@ -209,7 +210,7 @@ UnionExp pointerArithmetic(Loc loc, TOK op, Type *type,
bool isFloatIntPaint(Type *to, Type *from); bool isFloatIntPaint(Type *to, Type *from);
// Reinterpret float/int value 'fromVal' as a float/integer of type 'to'. // Reinterpret float/int value 'fromVal' as a float/integer of type 'to'.
Expression *paintFloatInt(Expression *fromVal, Type *to); Expression *paintFloatInt(UnionExp *pue, Expression *fromVal, Type *to);
/// Return true if t is an AA /// Return true if t is an AA
bool isAssocArray(Type *t); bool isAssocArray(Type *t);
...@@ -264,4 +265,4 @@ UnionExp ctfeCat(Loc loc, Type *type, Expression *e1, Expression *e2); ...@@ -264,4 +265,4 @@ UnionExp ctfeCat(Loc loc, Type *type, Expression *e1, Expression *e2);
Expression *ctfeIndex(Loc loc, Type *type, Expression *e1, uinteger_t indx); Expression *ctfeIndex(Loc loc, Type *type, Expression *e1, uinteger_t indx);
/// Cast 'e' of type 'type' to type 'to'. /// Cast 'e' of type 'type' to type 'to'.
Expression *ctfeCast(Loc loc, Type *type, Type *to, Expression *e); Expression *ctfeCast(UnionExp *pue, Loc loc, Type *type, Type *to, Expression *e);
...@@ -264,10 +264,9 @@ UnionExp copyLiteral(Expression *e) ...@@ -264,10 +264,9 @@ UnionExp copyLiteral(Expression *e)
ArrayLiteralExp *ale = (ArrayLiteralExp *)e; ArrayLiteralExp *ale = (ArrayLiteralExp *)e;
Expressions *elements = copyLiteralArray(ale->elements, ale->basis); Expressions *elements = copyLiteralArray(ale->elements, ale->basis);
new(&ue) ArrayLiteralExp(e->loc, elements); new(&ue) ArrayLiteralExp(e->loc, e->type, elements);
ArrayLiteralExp *r = (ArrayLiteralExp *)ue.exp(); ArrayLiteralExp *r = (ArrayLiteralExp *)ue.exp();
r->type = e->type;
r->ownedByCtfe = OWNEDctfe; r->ownedByCtfe = OWNEDctfe;
return ue; return ue;
} }
...@@ -314,7 +313,10 @@ UnionExp copyLiteral(Expression *e) ...@@ -314,7 +313,10 @@ UnionExp copyLiteral(Expression *e)
{ {
TypeSArray *tsa = (TypeSArray *)v->type; TypeSArray *tsa = (TypeSArray *)v->type;
size_t len = (size_t)tsa->dim->toInteger(); size_t len = (size_t)tsa->dim->toInteger();
m = createBlockDuplicatedArrayLiteral(e->loc, v->type, m, len); UnionExp uex;
m = createBlockDuplicatedArrayLiteral(&uex, e->loc, v->type, m, len);
if (m == uex.exp())
m = uex.copy();
} }
} }
(*newelems)[i] = m; (*newelems)[i] = m;
...@@ -414,6 +416,14 @@ Expression *paintTypeOntoLiteral(Type *type, Expression *lit) ...@@ -414,6 +416,14 @@ Expression *paintTypeOntoLiteral(Type *type, Expression *lit)
return paintTypeOntoLiteralCopy(type, lit).copy(); return paintTypeOntoLiteralCopy(type, lit).copy();
} }
Expression *paintTypeOntoLiteral(UnionExp *pue, Type *type, Expression *lit)
{
if (lit->type->equals(type))
return lit;
*pue = paintTypeOntoLiteralCopy(type, lit);
return pue->exp();
}
UnionExp paintTypeOntoLiteralCopy(Type *type, Expression *lit) UnionExp paintTypeOntoLiteralCopy(Type *type, Expression *lit)
{ {
UnionExp ue; UnionExp ue;
...@@ -539,6 +549,7 @@ uinteger_t resolveArrayLength(Expression *e) ...@@ -539,6 +549,7 @@ uinteger_t resolveArrayLength(Expression *e)
* Helper for NewExp * Helper for NewExp
* Create an array literal consisting of 'elem' duplicated 'dim' times. * Create an array literal consisting of 'elem' duplicated 'dim' times.
* Params: * Params:
* pue = where to store result
* loc = source location where the interpretation occurs * loc = source location where the interpretation occurs
* type = target type of the result * type = target type of the result
* elem = the source of array element, it will be owned by the result * elem = the source of array element, it will be owned by the result
...@@ -546,7 +557,7 @@ uinteger_t resolveArrayLength(Expression *e) ...@@ -546,7 +557,7 @@ uinteger_t resolveArrayLength(Expression *e)
* Returns: * Returns:
* Constructed ArrayLiteralExp * Constructed ArrayLiteralExp
*/ */
ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type, ArrayLiteralExp *createBlockDuplicatedArrayLiteral(UnionExp *pue, Loc loc, Type *type,
Expression *elem, size_t dim) Expression *elem, size_t dim)
{ {
if (type->ty == Tsarray && type->nextOf()->ty == Tsarray && elem->type->ty != Tsarray) if (type->ty == Tsarray && type->nextOf()->ty == Tsarray && elem->type->ty != Tsarray)
...@@ -554,7 +565,10 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type, ...@@ -554,7 +565,10 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type,
// If it is a multidimensional array literal, do it recursively // If it is a multidimensional array literal, do it recursively
TypeSArray *tsa = (TypeSArray *)type->nextOf(); TypeSArray *tsa = (TypeSArray *)type->nextOf();
size_t len = (size_t)tsa->dim->toInteger(); size_t len = (size_t)tsa->dim->toInteger();
elem = createBlockDuplicatedArrayLiteral(loc, type->nextOf(), elem, len); UnionExp ue;
elem = createBlockDuplicatedArrayLiteral(&ue, loc, type->nextOf(), elem, len);
if (elem == ue.exp())
elem = ue.copy();
} }
// Buzilla 15681 // Buzilla 15681
...@@ -567,8 +581,8 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type, ...@@ -567,8 +581,8 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type,
{ {
(*elements)[i] = mustCopy ? copyLiteral(elem).copy() : elem; (*elements)[i] = mustCopy ? copyLiteral(elem).copy() : elem;
} }
ArrayLiteralExp *ale = new ArrayLiteralExp(loc, elements); new(pue) ArrayLiteralExp(loc, type, elements);
ale->type = type; ArrayLiteralExp *ale = (ArrayLiteralExp *)pue->exp();
ale->ownedByCtfe = OWNEDctfe; ale->ownedByCtfe = OWNEDctfe;
return ale; return ale;
} }
...@@ -577,7 +591,7 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type, ...@@ -577,7 +591,7 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type,
* Helper for NewExp * Helper for NewExp
* Create a string literal consisting of 'value' duplicated 'dim' times. * Create a string literal consisting of 'value' duplicated 'dim' times.
*/ */
StringExp *createBlockDuplicatedStringLiteral(Loc loc, Type *type, StringExp *createBlockDuplicatedStringLiteral(UnionExp *pue, Loc loc, Type *type,
unsigned value, size_t dim, unsigned char sz) unsigned value, size_t dim, unsigned char sz)
{ {
utf8_t *s = (utf8_t *)mem.xcalloc(dim + 1, sz); utf8_t *s = (utf8_t *)mem.xcalloc(dim + 1, sz);
...@@ -591,7 +605,8 @@ StringExp *createBlockDuplicatedStringLiteral(Loc loc, Type *type, ...@@ -591,7 +605,8 @@ StringExp *createBlockDuplicatedStringLiteral(Loc loc, Type *type,
default: assert(0); default: assert(0);
} }
} }
StringExp *se = new StringExp(loc, s, dim); new(pue) StringExp(loc, s, dim);
StringExp *se = (StringExp *)pue->exp();
se->type = type; se->type = type;
se->sz = sz; se->sz = sz;
se->committed = true; se->committed = true;
...@@ -984,13 +999,13 @@ bool isFloatIntPaint(Type *to, Type *from) ...@@ -984,13 +999,13 @@ bool isFloatIntPaint(Type *to, Type *from)
} }
// Reinterpret float/int value 'fromVal' as a float/integer of type 'to'. // Reinterpret float/int value 'fromVal' as a float/integer of type 'to'.
Expression *paintFloatInt(Expression *fromVal, Type *to) Expression *paintFloatInt(UnionExp *pue, Expression *fromVal, Type *to)
{ {
if (exceptionOrCantInterpret(fromVal)) if (exceptionOrCantInterpret(fromVal))
return fromVal; return fromVal;
assert(to->size() == 4 || to->size() == 8); assert(to->size() == 4 || to->size() == 8);
return Compiler::paintAsType(fromVal, to); return Compiler::paintAsType(pue, fromVal, to);
} }
/******** Constant folding, with support for CTFE ***************************/ /******** Constant folding, with support for CTFE ***************************/
...@@ -1512,10 +1527,9 @@ UnionExp ctfeCat(Loc loc, Type *type, Expression *e1, Expression *e2) ...@@ -1512,10 +1527,9 @@ UnionExp ctfeCat(Loc loc, Type *type, Expression *e1, Expression *e2)
ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1;
ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
new(&ue) ArrayLiteralExp(es1->loc, copyLiteralArray(es1->elements)); new(&ue) ArrayLiteralExp(es1->loc, type, copyLiteralArray(es1->elements));
es1 = (ArrayLiteralExp *)ue.exp(); es1 = (ArrayLiteralExp *)ue.exp();
es1->elements->insert(es1->elements->dim, copyLiteralArray(es2->elements)); es1->elements->insert(es1->elements->dim, copyLiteralArray(es2->elements));
es1->type = type;
return ue; return ue;
} }
if (e1->op == TOKarrayliteral && e2->op == TOKnull && if (e1->op == TOKarrayliteral && e2->op == TOKnull &&
...@@ -1587,29 +1601,33 @@ Expression *ctfeIndex(Loc loc, Type *type, Expression *e1, uinteger_t indx) ...@@ -1587,29 +1601,33 @@ Expression *ctfeIndex(Loc loc, Type *type, Expression *e1, uinteger_t indx)
} }
} }
Expression *ctfeCast(Loc loc, Type *type, Type *to, Expression *e) Expression *ctfeCast(UnionExp *pue, Loc loc, Type *type, Type *to, Expression *e)
{ {
if (e->op == TOKnull) if (e->op == TOKnull)
return paintTypeOntoLiteral(to, e); return paintTypeOntoLiteral(pue, to, e);
if (e->op == TOKclassreference) if (e->op == TOKclassreference)
{ {
// Disallow reinterpreting class casts. Do this by ensuring that // Disallow reinterpreting class casts. Do this by ensuring that
// the original class can implicitly convert to the target class // the original class can implicitly convert to the target class
ClassDeclaration *originalClass = ((ClassReferenceExp *)e)->originalClass(); ClassDeclaration *originalClass = ((ClassReferenceExp *)e)->originalClass();
if (originalClass->type->implicitConvTo(to->mutableOf())) if (originalClass->type->implicitConvTo(to->mutableOf()))
return paintTypeOntoLiteral(to, e); return paintTypeOntoLiteral(pue, to, e);
else else
return new NullExp(loc, to); {
new(pue) NullExp(loc, to);
return pue->exp();
}
} }
// Allow TypeInfo type painting // Allow TypeInfo type painting
if (isTypeInfo_Class(e->type) && e->type->implicitConvTo(to)) if (isTypeInfo_Class(e->type) && e->type->implicitConvTo(to))
return paintTypeOntoLiteral(to, e); return paintTypeOntoLiteral(pue, to, e);
// Allow casting away const for struct literals // Allow casting away const for struct literals
if (e->op == TOKstructliteral && if (e->op == TOKstructliteral &&
e->type->toBasetype()->castMod(0) == to->toBasetype()->castMod(0)) e->type->toBasetype()->castMod(0) == to->toBasetype()->castMod(0))
{ return paintTypeOntoLiteral(pue, to, e);
return paintTypeOntoLiteral(to, e);
}
Expression *r; Expression *r;
if (e->type->equals(type) && type->equals(to)) if (e->type->equals(type) && type->equals(to))
...@@ -1617,22 +1635,28 @@ Expression *ctfeCast(Loc loc, Type *type, Type *to, Expression *e) ...@@ -1617,22 +1635,28 @@ Expression *ctfeCast(Loc loc, Type *type, Type *to, Expression *e)
// necessary not to change e's address for pointer comparisons // necessary not to change e's address for pointer comparisons
r = e; r = e;
} }
else if (to->toBasetype()->ty == Tarray && type->toBasetype()->ty == Tarray && else if (to->toBasetype()->ty == Tarray &&
type->toBasetype()->ty == Tarray &&
to->toBasetype()->nextOf()->size() == type->toBasetype()->nextOf()->size()) to->toBasetype()->nextOf()->size() == type->toBasetype()->nextOf()->size())
{ {
// Bugzilla 12495: Array reinterpret casts: eg. string to immutable(ubyte)[] // Bugzilla 12495: Array reinterpret casts: eg. string to immutable(ubyte)[]
return paintTypeOntoLiteral(to, e); return paintTypeOntoLiteral(pue, to, e);
} }
else else
{ {
r = Cast(loc, type, to, e).copy(); *pue = Cast(loc, type, to, e);
r = pue->exp();
} }
if (CTFEExp::isCantExp(r)) if (CTFEExp::isCantExp(r))
error(loc, "cannot cast %s to %s at compile time", e->toChars(), to->toChars()); error(loc, "cannot cast %s to %s at compile time", e->toChars(), to->toChars());
if (e->op == TOKarrayliteral) if (e->op == TOKarrayliteral)
((ArrayLiteralExp *)e)->ownedByCtfe = OWNEDctfe; ((ArrayLiteralExp *)e)->ownedByCtfe = OWNEDctfe;
if (e->op == TOKstring) if (e->op == TOKstring)
((StringExp *)e)->ownedByCtfe = OWNEDctfe; ((StringExp *)e)->ownedByCtfe = OWNEDctfe;
return r; return r;
} }
...@@ -1816,9 +1840,8 @@ UnionExp changeArrayLiteralLength(Loc loc, TypeArray *arrayType, ...@@ -1816,9 +1840,8 @@ UnionExp changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
for (size_t i = copylen; i < newlen; i++) for (size_t i = copylen; i < newlen; i++)
(*elements)[i] = defaultElem; (*elements)[i] = defaultElem;
} }
new(&ue) ArrayLiteralExp(loc, elements); new(&ue) ArrayLiteralExp(loc, arrayType, elements);
ArrayLiteralExp *aae = (ArrayLiteralExp *)ue.exp(); ArrayLiteralExp *aae = (ArrayLiteralExp *)ue.exp();
aae->type = arrayType;
aae->ownedByCtfe = OWNEDctfe; aae->ownedByCtfe = OWNEDctfe;
} }
return ue; return ue;
...@@ -2078,9 +2101,8 @@ UnionExp voidInitLiteral(Type *t, VarDeclaration *var) ...@@ -2078,9 +2101,8 @@ UnionExp voidInitLiteral(Type *t, VarDeclaration *var)
elem = copyLiteral(elem).copy(); elem = copyLiteral(elem).copy();
(*elements)[i] = elem; (*elements)[i] = elem;
} }
new(&ue) ArrayLiteralExp(var->loc, elements); new(&ue) ArrayLiteralExp(var->loc, tsa, elements);
ArrayLiteralExp *ae = (ArrayLiteralExp *)ue.exp(); ArrayLiteralExp *ae = (ArrayLiteralExp *)ue.exp();
ae->type = tsa;
ae->ownedByCtfe = OWNEDctfe; ae->ownedByCtfe = OWNEDctfe;
} }
else if (t->ty == Tstruct) else if (t->ty == Tstruct)
......
...@@ -1189,23 +1189,26 @@ void ScopeDsymbol::importScope(Dsymbol *s, Prot protection) ...@@ -1189,23 +1189,26 @@ void ScopeDsymbol::importScope(Dsymbol *s, Prot protection)
} }
} }
#define BITS_PER_INDEX (sizeof(size_t) * CHAR_BIT)
static void bitArraySet(BitArray *array, size_t idx) static void bitArraySet(BitArray *array, size_t idx)
{ {
array->ptr[idx / (sizeof(size_t) * CHAR_BIT)] |= 1ULL << (idx & (sizeof(size_t) * CHAR_BIT - 1)); array->ptr[idx / BITS_PER_INDEX] |= 1ULL << (idx % BITS_PER_INDEX);
} }
static bool bitArrayGet(BitArray *array, size_t idx) static bool bitArrayGet(BitArray *array, size_t idx)
{ {
return (array->ptr[idx / (sizeof(size_t) * CHAR_BIT)] & (1ULL << (idx & (sizeof(size_t) * CHAR_BIT - 1)))) != 0; const size_t boffset = idx % BITS_PER_INDEX;
return (array->ptr[idx / BITS_PER_INDEX] & (1ULL << boffset)) >> boffset;
} }
static void bitArrayLength(BitArray *array, size_t len) static void bitArrayLength(BitArray *array, size_t len)
{ {
size_t obytes = (array->len + CHAR_BIT - 1) / CHAR_BIT; if (array->len < len)
size_t nbytes = (len + CHAR_BIT - 1) / CHAR_BIT;
if (obytes < nbytes)
{ {
const size_t obytes = (array->len + BITS_PER_INDEX - 1) / BITS_PER_INDEX;
const size_t nbytes = (len + BITS_PER_INDEX - 1) / BITS_PER_INDEX;
if (!array->ptr) if (!array->ptr)
array->ptr = (size_t *)mem.xmalloc(nbytes * sizeof(size_t)); array->ptr = (size_t *)mem.xmalloc(nbytes * sizeof(size_t));
else else
...@@ -1213,8 +1216,9 @@ static void bitArrayLength(BitArray *array, size_t len) ...@@ -1213,8 +1216,9 @@ static void bitArrayLength(BitArray *array, size_t len)
for (size_t i = obytes; i < nbytes; i++) for (size_t i = obytes; i < nbytes; i++)
array->ptr[i] = 0; array->ptr[i] = 0;
array->len = nbytes * BITS_PER_INDEX;
} }
array->len = len;
} }
void ScopeDsymbol::addAccessiblePackage(Package *p, Prot protection) void ScopeDsymbol::addAccessiblePackage(Package *p, Prot protection)
......
...@@ -1493,7 +1493,6 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction *tf, ...@@ -1493,7 +1493,6 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
* is now optimized. See Bugzilla 2356. * is now optimized. See Bugzilla 2356.
*/ */
Type *tbn = ((TypeArray *)tb)->next; Type *tbn = ((TypeArray *)tb)->next;
Type *tsa = tbn->sarrayOf(nargs - i);
Expressions *elements = new Expressions(); Expressions *elements = new Expressions();
elements->setDim(nargs - i); elements->setDim(nargs - i);
...@@ -1511,8 +1510,7 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction *tf, ...@@ -1511,8 +1510,7 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
(*elements)[u] = a; (*elements)[u] = a;
} }
// Bugzilla 14395: Convert to a static array literal, or its slice. // Bugzilla 14395: Convert to a static array literal, or its slice.
arg = new ArrayLiteralExp(loc, elements); arg = new ArrayLiteralExp(loc, tbn->sarrayOf(nargs - i), elements);
arg->type = tsa;
if (tb->ty == Tarray) if (tb->ty == Tarray)
{ {
arg = new SliceExp(loc, arg, NULL, NULL); arg = new SliceExp(loc, arg, NULL, NULL);
...@@ -3741,34 +3739,37 @@ unsigned StringExp::charAt(uinteger_t i) const ...@@ -3741,34 +3739,37 @@ unsigned StringExp::charAt(uinteger_t i) const
// [ e1, e2, e3, ... ] // [ e1, e2, e3, ... ]
ArrayLiteralExp::ArrayLiteralExp(Loc loc, Expressions *elements) ArrayLiteralExp::ArrayLiteralExp(Loc loc, Type *type, Expressions *elements)
: Expression(loc, TOKarrayliteral, sizeof(ArrayLiteralExp)) : Expression(loc, TOKarrayliteral, sizeof(ArrayLiteralExp))
{ {
this->basis = NULL; this->basis = NULL;
this->type = type;
this->elements = elements; this->elements = elements;
this->ownedByCtfe = OWNEDcode; this->ownedByCtfe = OWNEDcode;
} }
ArrayLiteralExp::ArrayLiteralExp(Loc loc, Expression *e) ArrayLiteralExp::ArrayLiteralExp(Loc loc, Type *type, Expression *e)
: Expression(loc, TOKarrayliteral, sizeof(ArrayLiteralExp)) : Expression(loc, TOKarrayliteral, sizeof(ArrayLiteralExp))
{ {
this->basis = NULL; this->basis = NULL;
this->type = type;
elements = new Expressions; elements = new Expressions;
elements->push(e); elements->push(e);
this->ownedByCtfe = OWNEDcode; this->ownedByCtfe = OWNEDcode;
} }
ArrayLiteralExp::ArrayLiteralExp(Loc loc, Expression *basis, Expressions *elements) ArrayLiteralExp::ArrayLiteralExp(Loc loc, Type *type, Expression *basis, Expressions *elements)
: Expression(loc, TOKarrayliteral, sizeof(ArrayLiteralExp)) : Expression(loc, TOKarrayliteral, sizeof(ArrayLiteralExp))
{ {
this->basis = basis; this->basis = basis;
this->type = type;
this->elements = elements; this->elements = elements;
this->ownedByCtfe = OWNEDcode; this->ownedByCtfe = OWNEDcode;
} }
ArrayLiteralExp *ArrayLiteralExp::create(Loc loc, Expressions *elements) ArrayLiteralExp *ArrayLiteralExp::create(Loc loc, Expressions *elements)
{ {
return new ArrayLiteralExp(loc, elements); return new ArrayLiteralExp(loc, NULL, elements);
} }
bool ArrayLiteralExp::equals(RootObject *o) bool ArrayLiteralExp::equals(RootObject *o)
...@@ -3806,6 +3807,7 @@ bool ArrayLiteralExp::equals(RootObject *o) ...@@ -3806,6 +3807,7 @@ bool ArrayLiteralExp::equals(RootObject *o)
Expression *ArrayLiteralExp::syntaxCopy() Expression *ArrayLiteralExp::syntaxCopy()
{ {
return new ArrayLiteralExp(loc, return new ArrayLiteralExp(loc,
NULL,
basis ? basis->syntaxCopy() : NULL, basis ? basis->syntaxCopy() : NULL,
arraySyntaxCopy(elements)); arraySyntaxCopy(elements));
} }
...@@ -4082,8 +4084,7 @@ Expression *StructLiteralExp::getField(Type *type, unsigned offset) ...@@ -4082,8 +4084,7 @@ Expression *StructLiteralExp::getField(Type *type, unsigned offset)
z->setDim(length); z->setDim(length);
for (size_t q = 0; q < length; ++q) for (size_t q = 0; q < length; ++q)
(*z)[q] = e->copy(); (*z)[q] = e->copy();
e = new ArrayLiteralExp(loc, z); e = new ArrayLiteralExp(loc, type, z);
e->type = type;
} }
else else
{ {
......
...@@ -410,9 +410,9 @@ public: ...@@ -410,9 +410,9 @@ public:
Expressions *elements; Expressions *elements;
OwnedBy ownedByCtfe; OwnedBy ownedByCtfe;
ArrayLiteralExp(Loc loc, Expressions *elements); ArrayLiteralExp(Loc loc, Type *type, Expressions *elements);
ArrayLiteralExp(Loc loc, Expression *e); ArrayLiteralExp(Loc loc, Type *type, Expression *e);
ArrayLiteralExp(Loc loc, Expression *basis, Expressions *elements); ArrayLiteralExp(Loc loc, Type *type, Expression *basis, Expressions *elements);
static ArrayLiteralExp *create(Loc loc, Expressions *elements); static ArrayLiteralExp *create(Loc loc, Expressions *elements);
Expression *syntaxCopy(); Expression *syntaxCopy();
bool equals(RootObject *o); bool equals(RootObject *o);
......
...@@ -6632,8 +6632,7 @@ public: ...@@ -6632,8 +6632,7 @@ public:
if (tb2->ty == Tarray || tb2->ty == Tsarray) if (tb2->ty == Tarray || tb2->ty == Tsarray)
{ {
// Make e2 into [e2] // Make e2 into [e2]
exp->e2 = new ArrayLiteralExp(exp->e2->loc, exp->e2); exp->e2 = new ArrayLiteralExp(exp->e2->loc, exp->type, exp->e2);
exp->e2->type = exp->type;
} }
result = exp->optimize(WANTvalue); result = exp->optimize(WANTvalue);
return; return;
...@@ -6669,8 +6668,7 @@ public: ...@@ -6669,8 +6668,7 @@ public:
if (tb1->ty == Tarray || tb1->ty == Tsarray) if (tb1->ty == Tarray || tb1->ty == Tsarray)
{ {
// Make e1 into [e1] // Make e1 into [e1]
exp->e1 = new ArrayLiteralExp(exp->e1->loc, exp->e1); exp->e1 = new ArrayLiteralExp(exp->e1->loc, exp->type, exp->e1);
exp->e1->type = exp->type;
} }
result = exp->optimize(WANTvalue); result = exp->optimize(WANTvalue);
return; return;
......
...@@ -267,6 +267,9 @@ Msgtable msgtable[] = ...@@ -267,6 +267,9 @@ Msgtable msgtable[] =
{ "_ArrayEq", NULL }, { "_ArrayEq", NULL },
{ "_ArrayPostblit", NULL }, { "_ArrayPostblit", NULL },
{ "_ArrayDtor", NULL }, { "_ArrayDtor", NULL },
{ "dup", NULL },
{ "_aaApply", NULL },
{ "_aaApply2", NULL },
// For pragma's // For pragma's
{ "Pinline", "inline" }, { "Pinline", "inline" },
......
...@@ -612,7 +612,7 @@ public: ...@@ -612,7 +612,7 @@ public:
assert((*elements)[i]->op != TOKerror); assert((*elements)[i]->op != TOKerror);
} }
Expression *e = new ArrayLiteralExp(init->loc, elements); Expression *e = new ArrayLiteralExp(init->loc, NULL, elements);
ExpInitializer *ei = new ExpInitializer(init->loc, e); ExpInitializer *ei = new ExpInitializer(init->loc, e);
result = inferType(ei, sc); result = inferType(ei, sc);
return; return;
...@@ -857,8 +857,7 @@ public: ...@@ -857,8 +857,7 @@ public:
elements2->setDim(dim); elements2->setDim(dim);
for (size_t j = 0; j < dim; j++) for (size_t j = 0; j < dim; j++)
(*elements2)[j] = e; (*elements2)[j] = e;
e = new ArrayLiteralExp(e->loc, elements2); e = new ArrayLiteralExp(e->loc, tn, elements2);
e->type = tn;
(*elements)[i] = e; (*elements)[i] = e;
} }
} }
...@@ -877,8 +876,7 @@ public: ...@@ -877,8 +876,7 @@ public:
} }
} }
Expression *e = new ArrayLiteralExp(init->loc, elements); Expression *e = new ArrayLiteralExp(init->loc, init->type, elements);
e->type = init->type;
result = e; result = e;
return; return;
} }
...@@ -902,8 +900,7 @@ public: ...@@ -902,8 +900,7 @@ public:
elements->setDim(d); elements->setDim(d);
for (size_t i = 0; i < d; i++) for (size_t i = 0; i < d; i++)
(*elements)[i] = e; (*elements)[i] = e;
ArrayLiteralExp *ae = new ArrayLiteralExp(e->loc, elements); ArrayLiteralExp *ae = new ArrayLiteralExp(e->loc, itype, elements);
ae->type = itype;
result = ae; result = ae;
return; return;
} }
......
...@@ -2324,16 +2324,11 @@ Identifier *Type::getTypeInfoIdent() ...@@ -2324,16 +2324,11 @@ Identifier *Type::getTypeInfoIdent()
size_t namelen = 19 + sizeof(len) * 3 + len + 1; size_t namelen = 19 + sizeof(len) * 3 + len + 1;
char *name = namelen <= sizeof(namebuf) ? namebuf : (char *)mem.xmalloc(namelen); char *name = namelen <= sizeof(namebuf) ? namebuf : (char *)mem.xmalloc(namelen);
sprintf(name, "_D%lluTypeInfo_%s6__initZ", (unsigned long long) 9 + len, buf.data); int length = sprintf(name, "_D%lluTypeInfo_%s6__initZ", (unsigned long long) 9 + len, buf.data);
//printf("%p, deco = %s, name = %s\n", this, deco, name); //printf("%p, deco = %s, name = %s\n", this, deco, name);
assert(strlen(name) < namelen); // don't overflow the buffer assert(0 < length && length < namelen); // don't overflow the buffer
size_t off = 0; Identifier *id = Identifier::idPool(name, length);
#ifndef IN_GCC
if (global.params.isOSX || (global.params.isWindows && !global.params.is64bit))
++off; // C mangling will add '_' back in
#endif
Identifier *id = Identifier::idPool(name + off);
if (name != namebuf) if (name != namebuf)
free(name); free(name);
...@@ -4340,8 +4335,7 @@ Expression *TypeSArray::defaultInitLiteral(Loc loc) ...@@ -4340,8 +4335,7 @@ Expression *TypeSArray::defaultInitLiteral(Loc loc)
elements->setDim(d); elements->setDim(d);
for (size_t i = 0; i < d; i++) for (size_t i = 0; i < d; i++)
(*elements)[i] = NULL; (*elements)[i] = NULL;
ArrayLiteralExp *ae = new ArrayLiteralExp(Loc(), elementinit, elements); ArrayLiteralExp *ae = new ArrayLiteralExp(Loc(), this, elementinit, elements);
ae->type = this;
return ae; return ae;
} }
......
...@@ -7020,7 +7020,7 @@ Expression *Parser::parsePrimaryExp() ...@@ -7020,7 +7020,7 @@ Expression *Parser::parsePrimaryExp()
if (keys) if (keys)
e = new AssocArrayLiteralExp(loc, keys, values); e = new AssocArrayLiteralExp(loc, keys, values);
else else
e = new ArrayLiteralExp(loc, values); e = new ArrayLiteralExp(loc, NULL, values);
break; break;
} }
......
...@@ -479,8 +479,7 @@ Expression *pointerBitmap(TraitsExp *e) ...@@ -479,8 +479,7 @@ Expression *pointerBitmap(TraitsExp *e)
for (d_uns64 i = 0; i < cntdata; i++) for (d_uns64 i = 0; i < cntdata; i++)
exps->push(new IntegerExp(e->loc, data[(size_t)i], Type::tsize_t)); exps->push(new IntegerExp(e->loc, data[(size_t)i], Type::tsize_t));
ArrayLiteralExp* ale = new ArrayLiteralExp(e->loc, exps); ArrayLiteralExp* ale = new ArrayLiteralExp(e->loc, Type::tsize_t->sarrayOf(cntdata + 1), exps);
ale->type = Type::tsize_t->sarrayOf(cntdata + 1);
return ale; return ale;
} }
......
...@@ -351,3 +351,24 @@ void test15789() ...@@ -351,3 +351,24 @@ void test15789()
{ {
test15789a(0); test15789a(0);
} }
/**************************************/
// 7030
extern(C++)
{
struct T
{
void foo(int) const;
void bar(int);
static __gshared int boo;
}
}
version (Posix)
{
static assert(T.foo.mangleof == "_ZNK1T3fooEi");
static assert(T.bar.mangleof == "_ZN1T3barEi");
static assert(T.boo.mangleof == "_ZN1T3booE");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment