Author: coke
Date: Sun Mar 30 22:33:24 2008
New Revision: 26657
Modified:
trunk/compilers/imcc/optimizer.c
trunk/t/compilers/imcc/syn/regressions.t
trunk/t/op/integer.t
trunk/t/op/number.t
Log:
[IMCC]
'$I0 = 1/0' generated a compile time exception due to constant folding instead
of a
catchable runtime exception.
- if an exception occurs during this kind of constant folding, just abort the
optimization.
- fixup the todo test to have proper syntax (which was missed due to the
constant
folding)
- eliminate two invalid tests that used invalid opcodes which were missed due to
this issue.
Modified: trunk/compilers/imcc/optimizer.c
==============================================================================
--- trunk/compilers/imcc/optimizer.c (original)
+++ trunk/compilers/imcc/optimizer.c Sun Mar 30 22:33:24 2008
@@ -768,8 +768,8 @@
=item C<static int eval_ins>
Run one parrot instruction, registers are filled with the
-according constants. Thus the result is always ok as the function
-core evaluates the constants.
+according constants. If an exception occurs, return -1, aborting
+this optimization: this lets the runtime handle any exceptions.
=cut
@@ -829,10 +829,9 @@
/* eval the opcode */
new_internal_exception(interp);
- if (setjmp(interp->exceptions->destination)) {
- fprintf(stderr, "eval_ins: op '%s' failed\n", op);
- handle_exception(interp);
- }
+ if (setjmp(interp->exceptions->destination))
+ return -1;
+
pc = (interp->op_func_table[opnum]) (eval, interp);
free_internal_exception(interp);
/* the returned pc is either incremented by op_count or is eval,
@@ -977,6 +976,8 @@
* from the result
*/
branched = eval_ins(interp, op, found, r);
+ if (branched == -1)
+ return NULL;
/*
* for math ops result is in I0/N0
* if it was a branch with constant args, the result is
Modified: trunk/t/compilers/imcc/syn/regressions.t
==============================================================================
--- trunk/t/compilers/imcc/syn/regressions.t (original)
+++ trunk/t/compilers/imcc/syn/regressions.t Sun Mar 30 22:33:24 2008
@@ -16,11 +16,11 @@
/syntax error/
OUT
-pir_output_is( <<'CODE', <<'OUT', 'cannot constant fold div by 0', todo=> 'RT#
43048');
+pir_output_is( <<'CODE', <<'OUT', 'cannot constant fold div by 0');
.sub fold_by_zero
push_eh ok
$I1 = 1/0
- clear_eh
+ pop_eh
ok:
say "ok"
.end
Modified: trunk/t/op/integer.t
==============================================================================
--- trunk/t/op/integer.t (original)
+++ trunk/t/op/integer.t Sun Mar 30 22:33:24 2008
@@ -1,12 +1,12 @@
#!perl
-# Copyright (C) 2001-2007, The Perl Foundation.
+# Copyright (C) 2001-2008, The Perl Foundation.
# $Id$
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 57;
+use Parrot::Test tests => 56;
=head1 NAME
@@ -1274,13 +1274,6 @@
/.*Divide by zero.*/
OUTPUT
-pasm_error_output_like( <<'CODE', <<OUTPUT, "div_i_ic_ic by zero" );
- div I2, 0, 0
- end
-CODE
-/.*Divide by zero.*/
-OUTPUT
-
pasm_error_output_like( <<'CODE', <<OUTPUT, "fdiv_i_i by zero" );
set I0, 0
set I1, 10
Modified: trunk/t/op/number.t
==============================================================================
--- trunk/t/op/number.t (original)
+++ trunk/t/op/number.t Sun Mar 30 22:33:24 2008
@@ -1,12 +1,12 @@
#!perl
-# Copyright (C) 2001-2007, The Perl Foundation.
+# Copyright (C) 2001-2008, The Perl Foundation.
# $Id$
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 57;
+use Parrot::Test tests => 56;
=head1 NAME
@@ -1109,13 +1109,6 @@
/.*Divide by zero.*/
OUTPUT
-pasm_error_output_like( <<'CODE', <<OUTPUT, "div_n_nc_nc by zero" );
- div N1, 0, 0
- end
-CODE
-/.*Divide by zero.*/
-OUTPUT
-
pasm_error_output_like( <<'CODE', <<OUTPUT, "div_n_n_n by zero" );
set N0, 0
set N1, 10