Fixing OpMod emission not to trigger assert in simplifier

If you tried to mod something where the denominator
was cns(0), things would go horribly, horribly wrong.
Esse commit está contido em:
Eric Caruso
2013-07-02 17:00:57 -07:00
commit de Sara Golemon
commit 8d85957d57
3 arquivos alterados com 18 adições e 0 exclusões
+6
Ver Arquivo
@@ -3229,6 +3229,12 @@ void HhbcTranslator::emitMod() {
// of the branches gets optimized out due to constant folding.
if (tr->getValInt() == -1LL) {
push(cns(0));
} else if (tr->getValInt() == 0) {
// mod by zero is undefined. don't emit opmod for it because
// this could cause issues in simplifier/codegen
// this should never get reached anyway, we just need to dump
// something on the stack
push(cns(false));
} else {
push(gen(OpMod, tl, tr));
}
+10
Ver Arquivo
@@ -0,0 +1,10 @@
<?php
function one() {
return 1;
}
function main() {
var_dump(one() % 0);
}
main();
+2
Ver Arquivo
@@ -0,0 +1,2 @@
HipHop Warning: Division by zero in %s on line 8
bool(false)