Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More conservative fix for issue 12900 - Wrong code in IfStatement condition Expression #3685

Merged
merged 1 commit into from
Jun 25, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/e2ir.c
Original file line number Diff line number Diff line change
@@ -3215,6 +3215,17 @@ elem *toElem(Expression *e, IRState *irs)
dve->error("%s is not a field, but a %s", dve->var->toChars(), dve->var->kind());
}

// Bugzilla 12900
Type *txb = dve->type->toBasetype();
Type *tyb = v->type->toBasetype();
if (txb->ty == Tvector) txb = ((TypeVector *)txb)->basetype;
if (tyb->ty == Tvector) tyb = ((TypeVector *)tyb)->basetype;
#if DEBUG
if (txb->ty != tyb->ty)
printf("[%s] dve = %s, dve->type = %s, v->type = %s\n", dve->loc.toChars(), dve->toChars(), dve->type->toChars(), v->type->toChars());
#endif
assert(txb->ty == tyb->ty);

elem *e = dve->e1->toElem(irs);
Type *tb1 = dve->e1->type->toBasetype();
if (tb1->ty != Tclass && tb1->ty != Tpointer)
4 changes: 2 additions & 2 deletions src/optimize.c
Original file line number Diff line number Diff line change
@@ -322,7 +322,7 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
Expression *ex = ((PtrExp *)e->e1)->e1;
if (e->type->equals(ex->type))
ret = ex;
else
else if (e->type->toBasetype()->immutableOf()->equals(ex->type->toBasetype()->immutableOf()))
{
ret = ex->copy();
ret->type = e->type;
@@ -379,7 +379,7 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
Expression *ex = ((AddrExp *)e->e1)->e1;
if (e->type->equals(ex->type))
ret = ex;
else if (ex->type->implicitConvTo(e->type) >= MATCHconst)
else if (e->type->toBasetype()->immutableOf()->equals(ex->type->toBasetype()->immutableOf()))
{
ret = ex->copy();
ret->type = e->type;
2 changes: 1 addition & 1 deletion src/s2ir.c
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ class S2irVisitor : public Visitor
elem *e;
Blockx *blx = irs->blx;

//printf("IfStatement::toIR('%s')\n", condition->toChars());
//printf("IfStatement::toIR('%s')\n", s->condition->toChars());

IRState mystate(irs, s);

15 changes: 15 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
@@ -6914,6 +6914,21 @@ void test12498()
string x = t;
}

/***************************************************/
// 12900

struct A12900
{
char[1] b;
}

void test12900()
{
A12900 c;
if (*c.b.ptr)
return;
}

/***************************************************/
// 12937