Skip to content

Commit

Permalink
fix Issue 15144 - Bad operand size in asm { movdqa ... } produces bog…
Browse files Browse the repository at this point in the history
…us ubyte16 initializer error elsewhere
  • Loading branch information
WalterBright committed Apr 21, 2016
1 parent ffbe664 commit 2a74f6c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
29 changes: 24 additions & 5 deletions src/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extern (C++) Expression implicitCastTo(Expression e, Scope* sc, Type t)

override void visit(Expression e)
{
//printf("Expression::implicitCastTo(%s of type %s) => %s\n", e->toChars(), e->type->toChars(), t->toChars());
//printf("Expression.implicitCastTo(%s of type %s) => %s\n", e.toChars(), e.type.toChars(), t.toChars());
MATCH match = e.implicitConvTo(t);
if (match)
{
Expand Down Expand Up @@ -705,13 +705,22 @@ extern (C++) MATCH implicitConvTo(Expression e, Type t)
TypeVector tv = cast(TypeVector)tb;
TypeSArray tbase = cast(TypeSArray)tv.basetype;
assert(tbase.ty == Tsarray);
if (e.elements.dim != tbase.dim.toInteger())
const edim = e.elements.dim;
const tbasedim = tbase.dim.toInteger();
if (edim > tbasedim)
{
result = MATCHnomatch;
return;
}
Type telement = tv.elementType();
for (size_t i = 0; i < e.elements.dim; i++)
if (edim < tbasedim)
{
Expression el = typeb.nextOf.defaultInitLiteral(e.loc);
MATCH m = el.implicitConvTo(telement);
if (m < result)
result = m; // remember worst match
}
foreach (i; 0 .. edim)
{
Expression el = (*e.elements)[i];
MATCH m = el.implicitConvTo(telement);
Expand Down Expand Up @@ -2018,18 +2027,28 @@ extern (C++) Expression castTo(Expression e, Scope* sc, Type t)
TypeVector tv = cast(TypeVector)tb;
TypeSArray tbase = cast(TypeSArray)tv.basetype;
assert(tbase.ty == Tsarray);
if (e.elements.dim != tbase.dim.toInteger())
const edim = e.elements.dim;
const tbasedim = tbase.dim.toInteger();
if (edim > tbasedim)
goto L1;
ae = cast(ArrayLiteralExp)e.copy();
ae.type = tbase; // Bugzilla 12642
ae.elements = e.elements.copy();
Type telement = tv.elementType();
for (size_t i = 0; i < e.elements.dim; i++)
foreach (i; 0 .. edim)
{
Expression ex = (*e.elements)[i];
ex = ex.castTo(sc, telement);
(*ae.elements)[i] = ex;
}
// Fill in the rest with the default initializer
ae.elements.setDim(cast(size_t)tbasedim);
foreach (i; edim .. cast(size_t)tbasedim)
{
Expression ex = typeb.nextOf.defaultInitLiteral(e.loc);
ex = ex.castTo(sc, telement);
(*ae.elements)[i] = ex;
}
Expression ev = new VectorExp(e.loc, ae, tb);
ev = ev.semantic(sc);
result = ev;
Expand Down
2 changes: 1 addition & 1 deletion src/iasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ static void asm_merge_symbol(OPND *o1, Dsymbol *s)
goto L2;
}
if ((v->isConst() || v->isImmutable() || v->storage_class & STCmanifest) &&
!v->type->isfloating() && v->_init)
!v->type->isfloating() && v->type->ty != Tvector && v->_init)
{
ExpInitializer *ei = v->_init->isExpInitializer();
if (ei)
Expand Down
24 changes: 23 additions & 1 deletion test/runnable/testxmm.d
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ void foo13988(double[] arr)
{
static ulong repr(double d) { return *cast(ulong*)&d; }
foreach (x; arr)
assert(repr(arr[0]) == *cast(ulong*)&(arr[0]));
assert(repr(arr[0]) == *cast(ulong*)&(arr[0]));
}


Expand All @@ -1422,6 +1422,28 @@ void test15123()
}
}

/*****************************************/
// https://issues.dlang.org/show_bug.cgi?id=15144

void test15144()
{
enum ubyte16 csXMM1 = ['a','b','c',0,0,0,0,0];
__gshared ubyte16 csXMM2 = ['a','b','c',0,0,0,0,0];
immutable ubyte16 csXMM3 = ['a','b','c',0,0,0,0,0];
version (D_PIC)
{
}
else
{
asm @nogc nothrow
{
movdqa XMM0, [csXMM1];
movdqa XMM0, [csXMM2];
movdqa XMM0, [csXMM3];
}
}
}

/*****************************************/

int main()
Expand Down

0 comments on commit 2a74f6c

Please sign in to comment.