Mercurial > projects > ldc
diff dmd/optimize.c @ 35:3cfcb944304e trunk
[svn r39] * Updated to DMD 1.022 with the exception of:
Bugzilla 278: dmd.conf search path doesn't work
This fix was causing crashes for me :/ So for it's the old behaviour
author | lindquist |
---|---|
date | Tue, 09 Oct 2007 06:21:30 +0200 |
parents | c53b6e3fe49a |
children | 70d6113eeb8c |
line wrap: on
line diff
--- a/dmd/optimize.c Tue Oct 09 02:50:00 2007 +0200 +++ b/dmd/optimize.c Tue Oct 09 06:21:30 2007 +0200 @@ -371,6 +371,18 @@ //printf("BinExp::optimize(result = %d) %s\n", result, toChars()); e1 = e1->optimize(result); e2 = e2->optimize(result); + if (op == TOKshlass || op == TOKshrass || op == TOKushrass) + { + if (e2->isConst() == 1) + { + integer_t i2 = e2->toInteger(); + d_uns64 sz = e1->type->size() * 8; + if (i2 < 0 || i2 > sz) + { error("shift assign by %jd is outside the range 0..%zu", i2, sz); + e2 = new IntegerExp(0); + } + } + } return this; } @@ -451,55 +463,41 @@ return e; } -Expression *ShlExp::optimize(int result) -{ Expression *e; +Expression *shift_optimize(int result, BinExp *e, Expression *(*shift)(Type *, Expression *, Expression *)) +{ Expression *ex = e; - //printf("ShlExp::optimize(result = %d) %s\n", result, toChars()); - e1 = e1->optimize(result); - e2 = e2->optimize(result); - e = this; - if (e2->isConst() == 1) + e->e1 = e->e1->optimize(result); + e->e2 = e->e2->optimize(result); + if (e->e2->isConst() == 1) { - integer_t i2 = e2->toInteger(); - if (i2 < 0 || i2 > e1->type->size() * 8) - { error("shift left by %jd exceeds %zu", i2, e2->type->size() * 8); - e2 = new IntegerExp(0); + integer_t i2 = e->e2->toInteger(); + d_uns64 sz = e->e1->type->size() * 8; + if (i2 < 0 || i2 > sz) + { error("shift by %jd is outside the range 0..%zu", i2, sz); + e->e2 = new IntegerExp(0); } - if (e1->isConst() == 1) - e = new IntegerExp(loc, e1->toInteger() << e2->toInteger(), type); + if (e->e1->isConst() == 1) + ex = (*shift)(e->type, e->e1, e->e2); } - return e; + return ex; +} + +Expression *ShlExp::optimize(int result) +{ + //printf("ShlExp::optimize(result = %d) %s\n", result, toChars()); + return shift_optimize(result, this, Shl); } Expression *ShrExp::optimize(int result) -{ Expression *e; - - e1 = e1->optimize(result); - e2 = e2->optimize(result); - - if (e1->isConst() == 1 && e2->isConst() == 1) - { - e = Shr(type, e1, e2); - } - else - e = this; - return e; +{ + //printf("ShrExp::optimize(result = %d) %s\n", result, toChars()); + return shift_optimize(result, this, Shr); } Expression *UshrExp::optimize(int result) -{ Expression *e; - - //printf("UshrExp::optimize() %s\n", toChars()); - e1 = e1->optimize(result); - e2 = e2->optimize(result); - - if (e1->isConst() == 1 && e2->isConst() == 1) - { - e = Ushr(type, e1, e2); - } - else - e = this; - return e; +{ + //printf("UshrExp::optimize(result = %d) %s\n", result, toChars()); + return shift_optimize(result, this, Ushr); } Expression *AndExp::optimize(int result)