Skip to content

Commit

Permalink
Fix bug 10252 CTFE: Generate error for shr/ushr/shl out of range
Browse files Browse the repository at this point in the history
Use same behaviour as for const-folding.
  • Loading branch information
don-clugston-sociomantic committed Sep 13, 2013
1 parent 76982cb commit 670253c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/interpret.c
Expand Up @@ -2340,6 +2340,15 @@ Expression *BinExp::interpretCommon(InterState *istate, CtfeGoal goal, fp_t fp)
if (e2->isConst() != 1)
goto Lcant;

if (op == TOKshr || op == TOKshl || op == TOKushr)
{
sinteger_t i2 = e2->toInteger();
d_uns64 sz = e1->type->size() * 8;
if (i2 < 0 || i2 >= sz)
{ error("shift by %lld is outside the range 0..%llu", i2, (ulonglong)sz - 1);
return EXP_CANT_INTERPRET;
}
}
e = (*fp)(type, e1, e2);
if (e == EXP_CANT_INTERPRET)
error("%s cannot be interpreted at compile time", toChars());
Expand Down

0 comments on commit 670253c

Please sign in to comment.