Author: Ronan Lamy <ronan.l...@gmail.com> Branch: exc-later Changeset: r76511:1e06bd97b03a Date: 2015-03-23 12:30 +0000 http://bitbucket.org/pypy/pypy/changeset/1e06bd97b03a/
Log: Ensure (hackishly) that OverflowError is correctly propagated even when it's not caught explicitly diff --git a/rpython/translator/c/test/test_exception.py b/rpython/translator/c/test/test_exception.py --- a/rpython/translator/c/test/test_exception.py +++ b/rpython/translator/c/test/test_exception.py @@ -3,6 +3,7 @@ from rpython.translator.c.test import test_typed from rpython.translator.c.test import test_backendoptimized from rpython.rtyper.lltypesystem import lltype +from rpython.rlib.rarithmetic import ovfcheck getcompiled = test_typed.TestTypedTestCase().getcompiled getcompiledopt = test_backendoptimized.TestTypedOptimizedTestCase().getcompiled @@ -195,3 +196,19 @@ assert g() == -1 compiled = getcompiled(g, []) assert compiled() == -1 + +def test_ovf_propagation(): + def div(a, b): + try: + return ovfcheck(a//b) + except ZeroDivisionError: + raise + def f(): + div(4, 2) + try: + return div(-sys.maxint-1, -1) + except OverflowError: + return 0 + assert f() == 0 + compiled = getcompiled(f, []) + assert compiled() == 0 diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py --- a/rpython/translator/simplify.py +++ b/rpython/translator/simplify.py @@ -342,6 +342,16 @@ if not exits: block.exitswitch = None block.recloseblock(block.exits[0], *exits) + if OverflowError in op.canraise: + if not any(issubclass(OverflowError, exit.exitcase) + for exit in block.exits[1:]): + v_etype = const(OverflowError) + v_exc = Variable('last_exc_value') + exit = Link([v_etype, v_exc], graph.exceptblock, OverflowError) + exit.extravars(v_etype, v_exc) + exits = list(block.exits) + exits.append(exit) + block.recloseblock(*exits) if Exception in op.canraise: if block.exits[-1].exitcase is not Exception: v_etype = Variable('last_exception') _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit