From 023787d121f6dc8eade412fab55f62f26d8c3163 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 22 Apr 2013 21:25:15 -0600 Subject: [PATCH] fix special case of exception handler table translation scalac may generate bytecode such that an exception is thrown within the bounds of a handler for that exception such that the throw is the last instruction in the method, which we weren't handling properly. --- src/compile.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 8741fcddbd..d218048f40 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -6459,11 +6459,11 @@ resolveIpBackwards(Context* context, int start, int end) if (start >= static_cast (codeLength(t, methodCode(t, context->method)))) { - start = codeLength(t, methodCode(t, context->method)) - 1; - } - - while (start >= end and context->visitTable[start] == 0) { - -- start; + start = codeLength(t, methodCode(t, context->method)); + } else { + while (start >= end and context->visitTable[start] == 0) { + -- start; + } } if (start < end) { @@ -6523,7 +6523,8 @@ truncateLineNumberTable(Thread* t, object table, unsigned length) } object -translateExceptionHandlerTable(MyThread* t, Context* context, intptr_t start) +translateExceptionHandlerTable(MyThread* t, Context* context, intptr_t start, + intptr_t end) { avian::codegen::Compiler* c = context->compiler; @@ -6559,14 +6560,16 @@ translateExceptionHandlerTable(MyThread* t, Context* context, intptr_t start) exceptionHandlerStart(oldHandler)); assert(t, handlerEnd >= 0); - assert(t, handlerEnd < static_cast + assert(t, handlerEnd <= static_cast (codeLength(t, methodCode(t, context->method)))); intArrayBody(t, newIndex, ni * 3) = c->machineIp(handlerStart)->value() - start; intArrayBody(t, newIndex, (ni * 3) + 1) - = c->machineIp(handlerEnd)->value() - start; + = (handlerEnd == static_cast + (codeLength(t, methodCode(t, context->method))) + ? end : c->machineIp(handlerEnd)->value()) - start; intArrayBody(t, newIndex, (ni * 3) + 2) = c->machineIp(exceptionHandlerIp(oldHandler))->value() - start; @@ -7339,7 +7342,8 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) } { object newExceptionHandlerTable = translateExceptionHandlerTable - (t, context, reinterpret_cast(start)); + (t, context, reinterpret_cast(start), + reinterpret_cast(start) + codeSize); PROTECT(t, newExceptionHandlerTable);