Skip to content

Commit

Permalink
Merge pull request #4217 from 9rnsr/fix12776
Browse files Browse the repository at this point in the history
Issue 12776 - Wrong type for __vector(int[4]).init
  • Loading branch information
WalterBright committed Dec 20, 2014
2 parents 626d642 + e1b3b2b commit e11f409
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/iasm.c
Expand Up @@ -4193,7 +4193,7 @@ static OPND *asm_una_exp()
// Check for offset keyword
if (asmtok->ident == Id::offset)
{
deprecation(asmstate.loc, "offset deprecated, use offsetof");
error(asmstate.loc, "use offsetof instead of offset");
goto Loffset;
}
if (asmtok->ident == Id::offsetof)
Expand Down
40 changes: 29 additions & 11 deletions src/mtype.c
Expand Up @@ -2063,7 +2063,8 @@ Type *Type::toHeadMutable()
* If flag == 1, don't report "not a property" error and just return NULL.
*/
Expression *Type::getProperty(Loc loc, Identifier *ident, int flag)
{ Expression *e;
{
Expression *e;

#if LOGDOTEXP
printf("Type::getProperty(type = '%s', ident = '%s')\n", toChars(), ident->toChars());
Expand Down Expand Up @@ -2104,7 +2105,8 @@ Expression *Type::getProperty(Loc loc, Identifier *ident, int flag)
}
}
else if (ident == Id::stringof)
{ char *s = toChars();
{
char *s = toChars();
e = new StringExp(loc, s, strlen(s), 'c');
Scope sc;
e = e->semantic(&sc);
Expand Down Expand Up @@ -2138,7 +2140,8 @@ Expression *Type::getProperty(Loc loc, Identifier *ident, int flag)
* If flag == 1, don't report "not a property" error and just return NULL.
*/
Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident, int flag)
{ VarDeclaration *v = NULL;
{
VarDeclaration *v = NULL;

#if LOGDOTEXP
printf("Type::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars());
Expand Down Expand Up @@ -2179,7 +2182,8 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident, int flag)
}
}
if (ident == Id::stringof)
{ /* Bugzilla 3796: this should demangle e->type->deco rather than
{
/* Bugzilla 3796: this should demangle e->type->deco rather than
* pretty-printing the type.
*/
char *s = e->toChars();
Expand Down Expand Up @@ -3476,7 +3480,8 @@ Type *TypeVector::semantic(Loc loc, Scope *sc)
return terror;
basetype = basetype->toBasetype()->mutableOf();
if (basetype->ty != Tsarray)
{ error(loc, "T in __vector(T) must be a static array, not %s", basetype->toChars());
{
error(loc, "T in __vector(T) must be a static array, not %s", basetype->toChars());
return terror;
}
TypeSArray *t = (TypeSArray *)basetype;
Expand Down Expand Up @@ -3531,7 +3536,7 @@ unsigned TypeVector::alignsize()

Expression *TypeVector::getProperty(Loc loc, Identifier *ident, int flag)
{
return basetype->getProperty(loc, ident, flag);
return Type::getProperty(loc, ident, flag);
}

Expression *TypeVector::dotExp(Scope *sc, Expression *e, Identifier *ident, int flag)
Expand All @@ -3547,23 +3552,36 @@ Expression *TypeVector::dotExp(Scope *sc, Expression *e, Identifier *ident, int
e->type = basetype;
return e;
}
if (ident == Id::offsetof || ident == Id::offset || ident == Id::stringof)
if (ident == Id::init || ident == Id::offsetof || ident == Id::stringof)
{
// offsetof does not work on a cast expression, so use the basetype directly
// init should return a new VectorExp (Bugzilla 12776)
// offsetof does not work on a cast expression, so use e directly
// stringof should not add a cast to the output
return basetype->dotExp(sc, e, ident, flag);
return Type::dotExp(sc, e, ident, flag);
}
return basetype->dotExp(sc, e->castTo(sc, basetype), ident, flag);
}

Expression *TypeVector::defaultInit(Loc loc)
{
return basetype->defaultInit(loc);
//printf("TypeVector::defaultInit()\n");
assert(basetype->ty == Tsarray);
Expression *e = basetype->defaultInit(loc);
VectorExp *ve = new VectorExp(loc, e, this);
ve->type = this;
ve->dim = (int)(basetype->size(loc) / elementType()->size(loc));
return ve;
}

Expression *TypeVector::defaultInitLiteral(Loc loc)
{
return basetype->defaultInitLiteral(loc);
//printf("TypeVector::defaultInitLiteral()\n");
assert(basetype->ty == Tsarray);
Expression *e = basetype->defaultInitLiteral(loc);
VectorExp *ve = new VectorExp(loc, e, this);
ve->type = this;
ve->dim = (int)(basetype->size(loc) / elementType()->size(loc));
return ve;
}

bool TypeVector::isZeroInit(Loc loc)
Expand Down
22 changes: 22 additions & 0 deletions test/runnable/testxmm.d
Expand Up @@ -1236,6 +1236,28 @@ void test13841()
}
}

/*****************************************/
// 12776

void test12776()
{
alias Vector16s = TypeTuple!(
void16, byte16, short8, int4, long2,
ubyte16, ushort8, uint4, ulong2, float4, double2);
foreach (V; Vector16s)
{
static assert(is(typeof( V .init) == V ));
static assert(is(typeof( const(V).init) == const(V)));
static assert(is(typeof( inout( V).init) == inout( V)));
static assert(is(typeof( inout(const V).init) == inout(const V)));
static assert(is(typeof(shared( V).init) == shared( V)));
static assert(is(typeof(shared( const V).init) == shared( const V)));
static assert(is(typeof(shared(inout V).init) == shared(inout V)));
static assert(is(typeof(shared(inout const V).init) == shared(inout const V)));
static assert(is(typeof( immutable(V).init) == immutable(V)));
}
}

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

int main()
Expand Down

0 comments on commit e11f409

Please sign in to comment.