Skip to content

Commit

Permalink
Merge remote branch 'd/master' into type-checked-arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
michelf committed Jul 16, 2011
2 parents b1b884b + 64835f6 commit 531845b
Show file tree
Hide file tree
Showing 16 changed files with 571 additions and 178 deletions.
3 changes: 3 additions & 0 deletions docs/man/man1/dmd.1
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ List all variables poing into thread local storage
.IP -w
Enable warnings

.IP -wi
Enable informational warnings

.SH LINKING
Linking is done directly by the
.B dmd
Expand Down
71 changes: 55 additions & 16 deletions src/backend/cod3.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ int cod3_EA(code *c)
unsigned op1 = c->Iop & 0xFF;
if (op1 == ESCAPE)
ins = 0;
else if ((c->Iop & 0xFFFD00) == 0x0F3800)
ins = inssize2[(c->Iop >> 8) & 0xFF];
else if ((c->Iop & 0xFF00) == 0x0F00)
ins = inssize2[op1];
else
Expand Down Expand Up @@ -2772,7 +2774,9 @@ void assignaddrc(code *c)
if (code_next(c) && code_next(code_next(c)) == c)
assert(0);
#endif
if ((c->Iop & 0xFF00) == 0x0F00)
if ((c->Iop & 0xFFFD00) == 0x0F3800)
ins = inssize2[(c->Iop >> 8) & 0xFF];
else if ((c->Iop & 0xFF00) == 0x0F00)
ins = inssize2[c->Iop & 0xFF];
else if ((c->Iop & 0xFF) == ESCAPE)
{
Expand Down Expand Up @@ -3151,7 +3155,9 @@ void pinholeopt(code *c,block *b)
{
L1:
op = c->Iop;
if ((op & 0xFF00) == 0x0F00)
if ((op & 0xFFFD00) == 0x0F3800)
ins = inssize2[(op >> 8) & 0xFF];
else if ((op & 0xFF00) == 0x0F00)
ins = inssize2[op & 0xFF];
else
ins = inssize[op & 0xFF];
Expand Down Expand Up @@ -3776,17 +3782,27 @@ unsigned calccodsize(code *c)
#endif
iflags = c->Iflags;
op = c->Iop;
if ((op & 0xFF00) == 0x0F00)
if ((op & 0xFF00) == 0x0F00 || (op & 0xFFFD00) == 0x0F3800)
op = 0x0F;
else
op &= 0xFF;
switch (op)
{
case 0x0F:
ins = inssize2[c->Iop & 0xFF];
size = ins & 7;
if (c->Iop & 0xFF0000 || (c->Iop & 0xFFFFFF) == 0x000F38) // Opcode 0F_38_00 PSHUFB ( ssse3 )
size++;
if ((c->Iop & 0xFFFD00) == 0x0F3800)
{ // 3 byte op ( 0F38-- or 0F3A-- )
ins = inssize2[(c->Iop >> 8) & 0xFF];
size = ins & 7;
if (c->Iop & 0xFF000000)
size++;
}
else
{ // 2 byte op ( 0F-- )
ins = inssize2[c->Iop & 0xFF];
size = ins & 7;
if (c->Iop & 0xFF0000)
size++;
}
break;

case NOP:
Expand Down Expand Up @@ -3972,7 +3988,11 @@ int code_match(code *c1,code *c2)
goto nomatch;

ins = inssize[cs1.Iop & 0xFF];
if ((cs1.Iop & 0xFF00) == 0x0F00)
if ((cs1.Iop & 0xFFFD00) == 0x0F3800)
{
ins = inssize2[(cs1.Iop >> 8) & 0xFF];
}
else if ((cs1.Iop & 0xFF00) == 0x0F00)
{
ins = inssize2[cs1.Iop & 0xFF];
}
Expand Down Expand Up @@ -4198,16 +4218,29 @@ unsigned codout(code *c)

if (op > 0xFF)
{
if ((op & 0xFF00) == 0x0F00)
if ((op & 0xFFFD00) == 0x0F3800)
ins = inssize2[(op >> 8) & 0xFF];
else if ((op & 0xFF00) == 0x0F00)
ins = inssize2[op & 0xFF];

if (op & 0xFF000000)
{
if (c->Irex)
GEN(c->Irex | REX);
GEN(op >> 24);
unsigned char op1 = op >> 24;
if (op1 == 0xF2 || op1 == 0xF3 || op1 == 0x66)
{
GEN(op1);
if (c->Irex)
GEN(c->Irex | REX);
}
else
{
if (c->Irex)
GEN(c->Irex | REX);
GEN(op1);
}
GEN((op >> 16) & 0xFF);
GEN((op >> 8) & 0xFF);
GEN(op & 0xFF);
GEN((op >> 16) & 0xFF); // yes, this is out of order. For 0x660F3A41 & 40
}
else if (op & 0xFF0000)
{
Expand Down Expand Up @@ -4963,7 +4996,9 @@ void code_hydrate(code **pc)
while (*pc)
{
c = (code *) ph_hydrate(pc);
if ((c->Iop & 0xFF00) == 0x0F00)
if ((c->Iop & 0xFFFD00) == 0x0F3800)
ins = inssize2[(c->Iop >> 8) & 0xFF];
else if ((c->Iop & 0xFF00) == 0x0F00)
ins = inssize2[c->Iop & 0xFF];
else
ins = inssize[c->Iop & 0xFF];
Expand Down Expand Up @@ -5129,7 +5164,9 @@ void code_dehydrate(code **pc)
{
ph_dehydrate(pc);

if ((c->Iop & 0xFF00) == 0x0F00)
if ((c->Iop & 0xFFFD00) == 0x0F3800)
ins = inssize2[(c->Iop >> 8) & 0xFF];
else if ((c->Iop & 0xFF00) == 0x0F00)
ins = inssize2[c->Iop & 0xFF];
else
ins = inssize[c->Iop & 0xFF];
Expand Down Expand Up @@ -5301,7 +5338,9 @@ void code::print()
}

unsigned op = c->Iop;
if ((c->Iop & 0xFF00) == 0x0F00)
if ((c->Iop & 0xFFFD00) == 0x0F3800)
ins = inssize2[(op >> 8) & 0xFF];
else if ((c->Iop & 0xFF00) == 0x0F00)
ins = inssize2[op & 0xFF];
else
ins = inssize[op & 0xFF];
Expand Down
30 changes: 30 additions & 0 deletions src/e2ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3501,6 +3501,32 @@ elem *DotTypeExp::toElem(IRState *irs)
return e;
}

// check ce is nrvo_var.__dtor()
int isNrvoDtorCall(CallExp *ce)
{
if (ce->e1->op == TOKdotvar)
{ DotVarExp *dve = (DotVarExp *)ce->e1;
if (dve->e1->op == TOKvar)
{ Declaration *var = ((VarExp *)dve->e1)->var;
FuncDeclaration *fd = var->toParent2()->isFuncDeclaration();
if (fd && fd->nrvo_can && fd->nrvo_var)
{ if (var == fd->nrvo_var)
{ // NRVO var exists
Type *tret = fd->type->nextOf()->toBasetype();
if (tret->ty == Tstruct)
{ Declaration *dtor = ((TypeStruct *)tret)->sym->dtor;
if (dtor && dve->var == dtor)
{ // dtor call of nevo_var
return 1;
}
}
}
}
}
}
return 0;
}

elem *CallExp::toElem(IRState *irs)
{
//printf("CallExp::toElem('%s')\n", toChars());
Expand All @@ -3517,6 +3543,10 @@ elem *CallExp::toElem(IRState *irs)

directcall = 0;
fd = NULL;

if (isNrvoDtorCall(this))
return IntegerExp(0).toElem(irs);

if (e1->op == TOKdotvar && t1->ty != Tdelegate)
{ DotVarExp *dve = (DotVarExp *)e1;

Expand Down
16 changes: 16 additions & 0 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -8306,6 +8306,22 @@ Expression *CastExp::semantic(Scope *sc)
if (!tob->hasPointers())
goto Lsafe;

if (tob->ty == Tclass && t1b->ty == Tclass)
{
ClassDeclaration *cdfrom = t1b->isClassHandle();
ClassDeclaration *cdto = tob->isClassHandle();

int offset;
if (!cdfrom->isBaseOf(cdto, &offset))
goto Lunsafe;

if (cdfrom->isCPPinterface() ||
cdto->isCPPinterface())
goto Lunsafe;

goto Lsafe;
}

if (tob->ty == Tarray && t1b->ty == Tarray)
{
Type* tobn = tob->nextOf()->toBasetype();
Expand Down
4 changes: 1 addition & 3 deletions src/iasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1406,10 +1406,8 @@ STATIC code *asm_emit(Loc loc,
unsigned usOpcode = ptb.pptb0->usOpcode;

pc->Iop = usOpcode;
if ((usOpcode & 0xFFFFFF00) == 0x660F3A00 || // SSE4
(usOpcode & 0xFFFFFF00) == 0x660F3800) // SSE4
if ((usOpcode & 0xFFFD00) == 0x0F3800) // SSSE3, SSE4
{
pc->Iop = 0x66000F00 | ((usOpcode >> 8) & 0xFF) | ((usOpcode & 0xFF) << 16);
goto L3;
}
switch (usOpcode & 0xFF0000)
Expand Down
14 changes: 9 additions & 5 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)
if (ad->ctor)
error(loc, "%s %s has constructors, cannot use { initializers }, use %s( initializers ) instead",
ad->kind(), ad->toChars(), ad->toChars());
int nfields = ad->fields.dim;
if (((StructDeclaration *)ad)->isnested) nfields--;
for (size_t i = 0; i < field.dim; i++)
{
Identifier *id = field.tdata()[i];
Expand All @@ -166,7 +168,7 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)

if (id == NULL)
{
if (fieldi >= ad->fields.dim)
if (fieldi >= nfields)
{ error(loc, "too many initializers for %s", ad->toChars());
errors = 1;
field.remove(i);
Expand All @@ -192,7 +194,7 @@ Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)
// Find out which field index it is
for (fieldi = 0; 1; fieldi++)
{
if (fieldi >= ad->fields.dim)
if (fieldi >= nfields)
{
error(loc, "%s.%s is not a per-instance initializable field",
t->toChars(), s->toChars());
Expand Down Expand Up @@ -260,7 +262,9 @@ Expression *StructInitializer::toExpression()
if (!sd)
return NULL;
Expressions *elements = new Expressions();
elements->setDim(ad->fields.dim);
int nfields = ad->fields.dim;
if (sd->isnested) nfields--;
elements->setDim(nfields);
for (int i = 0; i < elements->dim; i++)
{
elements->tdata()[i] = NULL;
Expand All @@ -281,7 +285,7 @@ Expression *StructInitializer::toExpression()
// Find out which field index it is
for (fieldi = 0; 1; fieldi++)
{
if (fieldi >= ad->fields.dim)
if (fieldi >= nfields)
{
s->error("is not a per-instance initializable field");
goto Lno;
Expand All @@ -290,7 +294,7 @@ Expression *StructInitializer::toExpression()
break;
}
}
else if (fieldi >= ad->fields.dim)
else if (fieldi >= nfields)
{ error(loc, "too many initializers for '%s'", ad->toChars());
goto Lno;
}
Expand Down
22 changes: 22 additions & 0 deletions src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const char Pline[] = "line";
const char Ptype[] = "type";
const char Pcomment[] = "comment";
const char Pmembers[] = "members";
const char Pprotection[] = "protection";
const char* Pprotectionnames[] = {NULL, "none", "private", "package", "protected", "public", "export"};

void JsonRemoveComma(OutBuffer *buf);

Expand Down Expand Up @@ -259,6 +261,10 @@ void Declaration::toJsonBuffer(OutBuffer *buf)

JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());

if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);

if (type)
JsonProperty(buf, Ptype, type->toChars());

Expand All @@ -285,8 +291,13 @@ void AggregateDeclaration::toJsonBuffer(OutBuffer *buf)

JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());

if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);

if (comment)
JsonProperty(buf, Pcomment, (const char *)comment);

if (loc.linnum)
JsonProperty(buf, Pline, loc.linnum);

Expand Down Expand Up @@ -344,6 +355,10 @@ void TemplateDeclaration::toJsonBuffer(OutBuffer *buf)

JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());

if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);

if (comment)
JsonProperty(buf, Pcomment, (const char *)comment);

Expand Down Expand Up @@ -389,6 +404,10 @@ void EnumDeclaration::toJsonBuffer(OutBuffer *buf)

JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());

if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);

if (comment)
JsonProperty(buf, Pcomment, (const char *)comment);

Expand Down Expand Up @@ -427,6 +446,9 @@ void EnumMember::toJsonBuffer(OutBuffer *buf)
JsonProperty(buf, Pname, toChars());
JsonProperty(buf, Pkind, kind());

if (prot())
JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);

if (comment)
JsonProperty(buf, Pcomment, (const char *)comment);

Expand Down
Loading

0 comments on commit 531845b

Please sign in to comment.