Skip to content

Commit

Permalink
imcc: error on exceptions in constant folding
Browse files Browse the repository at this point in the history
When an op with only constants args throws an exception like div by zero,
eval just returns the address of the handler, not the handler.  So we only
know that something is wrong, not what.

The exception message should be improved later.  For now just error with
eval_ins: unhandled exception for op '%s'

Fixes #1236
  • Loading branch information
rurban committed Jun 5, 2017
1 parent 5609285 commit 63e810d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
14 changes: 10 additions & 4 deletions compilers/imcc/optimizer.c
Expand Up @@ -927,7 +927,7 @@ eval_ins(ARGMOD(imc_info_t *imcc), ARGIN(const char *op), size_t ops,
break;
default:
IMCC_fatal(imcc, 1, "eval_ins"
"invalid arg #%d for op '%s' not found\n",
": invalid arg #%d for op '%s' not found\n",
i, op);
}
}
Expand All @@ -940,10 +940,16 @@ eval_ins(ARGMOD(imc_info_t *imcc), ARGIN(const char *op), size_t ops,
pc = (OP_INFO_OPFUNC(op_info)) (eval, imcc->interp);
Parrot_runloop_free_jump_point(imcc->interp);
/* the returned pc is either incremented by op_count or is eval,
* as the branch offset is 0 - return true if it branched
* as the branch offset is 0 - return true if it branched.
* or if the op threw an exception (e.g. DIV_BY_ZERO), the pc of the handler.
*/
PARROT_ASSERT(pc == eval + op_info->op_count || pc == eval);
return pc == eval;
if (pc == eval)
return -1;
else if (pc == eval + op_info->op_count)
return 0;
else /* Todo: just follow the exception address */
IMCC_fatal(imcc, 1, "eval_ins"
": fatal exception in op '%s'\n", op);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/string/namealias.c
@@ -1,5 +1,5 @@
/* ANSI-C code produced by gperf version 3.0.4 */
/* Command-line: gperf --output-file=tmp_namealias.c src/string/namealias_c.in */
/* ANSI-C code produced by gperf version 3.1 */
/* Command-line: gperf --output-file=tmp_namealias.c src/string/namealias_c.in */
/* Computed positions: -k'1,14,$' */

#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
Expand Down
13 changes: 11 additions & 2 deletions t/compilers/imcc/syn/const.t
@@ -1,5 +1,5 @@
#!perl
# Copyright (C) 2001-2014, Parrot Foundation.
# Copyright (C) 2001-2017, Parrot Foundation.

use strict;
use warnings;
Expand All @@ -8,7 +8,7 @@ use vars qw($TODO);

use Test::More;
use Parrot::Config;
use Parrot::Test tests => 40;
use Parrot::Test tests => 41;

pir_output_is( <<'CODE', <<'OUT', "globalconst 1" );
.sub 'main' :main
Expand Down Expand Up @@ -668,6 +668,15 @@ OUT
#/Method 'new' not found for non-object/
#OUT
# TODO: This really should just exit with Divide by zero, as parrot_old did
pir_error_output_like( <<'CODE', <<'OUT', 'Exceptions in the constant folder [GH #1236]')
.sub a
$N0=0//0
.end
CODE
/ exception in op 'fdiv_n_n_n'/
OUT
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit 63e810d

Please sign in to comment.