Skip to content

Commit d664dae

Browse files
committed
Merge pull request #3685 from 9rnsr/fix12900
More conservative fix for issue 12900 - Wrong code in IfStatement condition Expression
2 parents 548e71c + 6dd50d5 commit d664dae

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

src/e2ir.c

+11
Original file line numberDiff line numberDiff line change
@@ -3215,6 +3215,17 @@ elem *toElem(Expression *e, IRState *irs)
32153215
dve->error("%s is not a field, but a %s", dve->var->toChars(), dve->var->kind());
32163216
}
32173217

3218+
// Bugzilla 12900
3219+
Type *txb = dve->type->toBasetype();
3220+
Type *tyb = v->type->toBasetype();
3221+
if (txb->ty == Tvector) txb = ((TypeVector *)txb)->basetype;
3222+
if (tyb->ty == Tvector) tyb = ((TypeVector *)tyb)->basetype;
3223+
#if DEBUG
3224+
if (txb->ty != tyb->ty)
3225+
printf("[%s] dve = %s, dve->type = %s, v->type = %s\n", dve->loc.toChars(), dve->toChars(), dve->type->toChars(), v->type->toChars());
3226+
#endif
3227+
assert(txb->ty == tyb->ty);
3228+
32183229
elem *e = dve->e1->toElem(irs);
32193230
Type *tb1 = dve->e1->type->toBasetype();
32203231
if (tb1->ty != Tclass && tb1->ty != Tpointer)

src/optimize.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
322322
Expression *ex = ((PtrExp *)e->e1)->e1;
323323
if (e->type->equals(ex->type))
324324
ret = ex;
325-
else
325+
else if (e->type->toBasetype()->immutableOf()->equals(ex->type->toBasetype()->immutableOf()))
326326
{
327327
ret = ex->copy();
328328
ret->type = e->type;
@@ -379,7 +379,7 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
379379
Expression *ex = ((AddrExp *)e->e1)->e1;
380380
if (e->type->equals(ex->type))
381381
ret = ex;
382-
else if (ex->type->implicitConvTo(e->type) >= MATCHconst)
382+
else if (e->type->toBasetype()->immutableOf()->equals(ex->type->toBasetype()->immutableOf()))
383383
{
384384
ret = ex->copy();
385385
ret->type = e->type;

src/s2ir.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class S2irVisitor : public Visitor
157157
elem *e;
158158
Blockx *blx = irs->blx;
159159

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

162162
IRState mystate(irs, s);
163163

test/runnable/xtest46.d

+15
Original file line numberDiff line numberDiff line change
@@ -6914,6 +6914,21 @@ void test12498()
69146914
string x = t;
69156915
}
69166916

6917+
/***************************************************/
6918+
// 12900
6919+
6920+
struct A12900
6921+
{
6922+
char[1] b;
6923+
}
6924+
6925+
void test12900()
6926+
{
6927+
A12900 c;
6928+
if (*c.b.ptr)
6929+
return;
6930+
}
6931+
69176932
/***************************************************/
69186933
// 12937
69196934

0 commit comments

Comments
 (0)