It protects agains invalid register allocation for temporary.
It fixes the bug in convert_array_load() where the high register
was always set to NULL.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/jit/expression.h      |    2 +-
 jit/expression.c              |   14 ++++++++++----
 jit/object-bc.c               |    4 +---
 jit/ostack-bc.c               |   10 +---------
 test/jit/arithmetic-bc-test.c |   20 +++++---------------
 test/jit/branch-bc-test.c     |   11 +++--------
 test/jit/invoke-bc-test.c     |    4 +---
 test/jit/load-store-bc-test.c |    4 +---
 test/jit/object-bc-test.c     |    4 +---
 test/jit/tree-printer-test.c  |    9 ++++++++-
 test/jit/typeconv-bc-test.c   |    4 +---
 11 files changed, 33 insertions(+), 53 deletions(-)

diff --git a/include/jit/expression.h b/include/jit/expression.h
index 08f773c..fcb3379 100644
--- a/include/jit/expression.h
+++ b/include/jit/expression.h
@@ -328,7 +328,7 @@ void expr_put(struct expression *);
 struct expression *value_expr(enum vm_type, unsigned long long);
 struct expression *fvalue_expr(enum vm_type, double);
 struct expression *local_expr(enum vm_type, unsigned long);
-struct expression *temporary_expr(enum vm_type, struct var_info *, struct 
var_info *);
+struct expression *temporary_expr(enum vm_type, struct compilation_unit *);
 struct expression *mimic_stack_expr(enum vm_type, int, int);
 struct expression *array_deref_expr(enum vm_type, struct expression *, struct 
expression *);
 struct expression *binop_expr(enum vm_type, enum binary_operator, struct 
expression *, struct expression *);
diff --git a/jit/expression.c b/jit/expression.c
index 7f04fa9..428b94a 100644
--- a/jit/expression.c
+++ b/jit/expression.c
@@ -246,7 +246,7 @@ struct expression *local_expr(enum vm_type vm_type, 
unsigned long local_index)
        return expr;
 }
 
-struct expression *temporary_expr(enum vm_type vm_type, struct var_info 
*tmp_high, struct var_info *tmp_low)
+struct expression *temporary_expr(enum vm_type vm_type, struct 
compilation_unit *cu)
 {
        struct expression *expr;
 
@@ -255,9 +255,15 @@ struct expression *temporary_expr(enum vm_type vm_type, 
struct var_info *tmp_hig
        else
                expr = alloc_expression(EXPR_TEMPORARY, vm_type);
 
-       if (expr) {
-               expr->tmp_high = tmp_high;
-               expr->tmp_low = tmp_low;
+       if (!expr)
+               return NULL;
+
+       if (expr->vm_type == J_LONG) {
+               expr->tmp_low = get_var(cu, J_INT);
+               expr->tmp_high = get_var(cu, J_INT);
+       } else {
+               expr->tmp_low = get_var(cu, expr->vm_type);
+               expr->tmp_high = NULL;
        }
 
        return expr;
diff --git a/jit/object-bc.c b/jit/object-bc.c
index 2a48fb1..0604e7c 100644
--- a/jit/object-bc.c
+++ b/jit/object-bc.c
@@ -173,7 +173,6 @@ static int convert_array_load(struct parse_context *ctx, 
enum vm_type type)
        struct expression *index, *arrayref;
        struct expression *src_expr, *dest_expr;
        struct statement *store_stmt, *arraycheck;
-       struct var_info *temporary;
        struct expression *arrayref_pure;
        struct expression *index_pure;
 
@@ -196,8 +195,7 @@ static int convert_array_load(struct parse_context *ctx, 
enum vm_type type)
        index_pure = get_pure_expr(ctx, index);
        src_expr = array_deref_expr(type, arrayref_pure, index_pure);
 
-       temporary = get_var(ctx->cu, type);
-       dest_expr = temporary_expr(type, NULL, temporary);
+       dest_expr = temporary_expr(type, ctx->cu);
 
        store_stmt->store_src = &src_expr->node;
        store_stmt->store_dest = &dest_expr->node;
diff --git a/jit/ostack-bc.c b/jit/ostack-bc.c
index ec957cf..9cad316 100644
--- a/jit/ostack-bc.c
+++ b/jit/ostack-bc.c
@@ -41,16 +41,8 @@ dup_expr(struct parse_context *ctx, struct expression *expr)
 {
        struct expression *dest;
        struct statement *stmt;
-       struct var_info *tmp_low, *tmp_high = NULL;
 
-       if (expr->vm_type == J_LONG) {
-               tmp_low = get_var(ctx->cu, J_INT);
-               tmp_high = get_var(ctx->cu, J_INT);
-       } else {
-               tmp_low = get_var(ctx->cu, expr->vm_type);
-       }
-
-       dest = temporary_expr(expr->vm_type, tmp_high, tmp_low);
+       dest = temporary_expr(expr->vm_type, ctx->cu);
 
        expr_get(dest);
        stmt = alloc_statement(STMT_STORE);
diff --git a/test/jit/arithmetic-bc-test.c b/test/jit/arithmetic-bc-test.c
index b698c02..6e594c8 100644
--- a/test/jit/arithmetic-bc-test.c
+++ b/test/jit/arithmetic-bc-test.c
@@ -36,16 +36,12 @@ static void assert_convert_binop(enum vm_type vm_type,
                .code_attribute.code = code,
                .code_attribute.code_length = ARRAY_SIZE(code)
        };
-       struct var_info *temporary;
        struct basic_block *bb;
 
        bb = __alloc_simple_bb(&method);
 
-       temporary = get_var(bb->b_parent, vm_type);
-       left = temporary_expr(vm_type, NULL, temporary);
-
-       temporary = get_var(bb->b_parent, vm_type);
-       right = temporary_expr(vm_type, NULL, temporary);
+       left = temporary_expr(vm_type, bb->b_parent);
+       right = temporary_expr(vm_type, bb->b_parent);
 
        stack_push(bb->mimic_stack, left);
        stack_push(bb->mimic_stack, right);
@@ -110,13 +106,11 @@ static void assert_convert_unop(enum vm_type vm_type,
                .code_attribute.code = code,
                .code_attribute.code_length = ARRAY_SIZE(code)
        };
-       struct var_info *temporary;
        struct basic_block *bb;
 
        bb = __alloc_simple_bb(&method);
 
-       temporary = get_var(bb->b_parent, J_INT);
-       expression = temporary_expr(vm_type, NULL, temporary);
+       expression = temporary_expr(vm_type, bb->b_parent);
        stack_push(bb->mimic_stack, expression);
 
        convert_to_ir(bb->b_parent);
@@ -218,16 +212,12 @@ static void assert_convert_cmp(unsigned char opc, enum 
binary_operator op,
                .code_attribute.code = code,
                .code_attribute.code_length = ARRAY_SIZE(code),
        };
-       struct var_info *temporary;
        struct basic_block *bb;
 
        bb = __alloc_simple_bb(&method);
 
-       temporary = get_var(bb->b_parent, J_INT);
-       left = temporary_expr(type, NULL, temporary);
-
-       temporary = get_var(bb->b_parent, J_INT);
-       right = temporary_expr(type, NULL, temporary);
+       left = temporary_expr(type, bb->b_parent);
+       right = temporary_expr(type, bb->b_parent);
 
        stack_push(bb->mimic_stack, left);
        stack_push(bb->mimic_stack, right);
diff --git a/test/jit/branch-bc-test.c b/test/jit/branch-bc-test.c
index b393bd0..e9583d5 100644
--- a/test/jit/branch-bc-test.c
+++ b/test/jit/branch-bc-test.c
@@ -40,7 +40,6 @@ static void assert_convert_if(enum binary_operator 
expected_operator,
                .code_attribute.code = code,
                .code_attribute.code_length = ARRAY_SIZE(code),
        };
-       struct var_info *temporary;
 
        cu = compilation_unit_alloc(&method);
 
@@ -58,8 +57,7 @@ static void assert_convert_if(enum binary_operator 
expected_operator,
        list_add_tail(&bb->bb_list_node, &cu->bb_list);
        list_add_tail(&target_bb->bb_list_node, &cu->bb_list);
 
-       temporary = get_var(cu, J_INT);
-       if_value = temporary_expr(J_INT, NULL, temporary);
+       if_value = temporary_expr(J_INT, cu);
        stack_push(branch_bb->mimic_stack, if_value);
 
        convert_to_ir(cu);
@@ -97,7 +95,6 @@ static void assert_convert_if_cmp(enum binary_operator 
expected_operator,
                .code_attribute.code = code,
                .code_attribute.code_length = ARRAY_SIZE(code),
        };
-       struct var_info *temporary;
 
        cu = compilation_unit_alloc(&method);
        stmt_bb = alloc_basic_block(cu, 0, 1);
@@ -108,12 +105,10 @@ static void assert_convert_if_cmp(enum binary_operator 
expected_operator,
        list_add_tail(&stmt_bb->bb_list_node, &cu->bb_list);
        list_add_tail(&true_bb->bb_list_node, &cu->bb_list);
 
-       temporary = get_var(cu, J_INT);
-       if_value1 = temporary_expr(vm_type, NULL, temporary);
+       if_value1 = temporary_expr(vm_type, cu);
        stack_push(stmt_bb->mimic_stack, if_value1);
 
-       temporary = get_var(cu, J_INT);
-       if_value2 = temporary_expr(vm_type, NULL, temporary);
+       if_value2 = temporary_expr(vm_type, cu);
        stack_push(stmt_bb->mimic_stack, if_value2);
 
        convert_to_ir(cu);
diff --git a/test/jit/invoke-bc-test.c b/test/jit/invoke-bc-test.c
index c6d0634..01a7ff7 100644
--- a/test/jit/invoke-bc-test.c
+++ b/test/jit/invoke-bc-test.c
@@ -22,12 +22,10 @@ static void assert_convert_return(enum vm_type vm_type, 
unsigned char opc)
                .code_attribute.code_length = ARRAY_SIZE(code),
        };
        struct statement *ret_stmt;
-       struct var_info *temporary;
        struct basic_block *bb;
 
        bb = __alloc_simple_bb(&method);
-       temporary = get_var(bb->b_parent, J_INT);
-       return_value = temporary_expr(vm_type, NULL, temporary);
+       return_value = temporary_expr(vm_type, bb->b_parent);
        stack_push(bb->mimic_stack, return_value);
        convert_to_ir(bb->b_parent);
 
diff --git a/test/jit/load-store-bc-test.c b/test/jit/load-store-bc-test.c
index ff0576d..9d82e85 100644
--- a/test/jit/load-store-bc-test.c
+++ b/test/jit/load-store-bc-test.c
@@ -506,13 +506,11 @@ static void __assert_convert_store(unsigned char *code,
                                   unsigned char expected_index)
 {
        struct statement *stmt;
-       struct var_info *temporary;
        struct basic_block *bb;
 
        bb = alloc_simple_bb(code, code_size);
 
-       temporary = get_var(bb->b_parent, expected_type);
-       stack_push(bb->mimic_stack, temporary_expr(expected_type, NULL, 
temporary));
+       stack_push(bb->mimic_stack, temporary_expr(expected_type, 
bb->b_parent));
 
        convert_to_ir(bb->b_parent);
        stmt = stmt_entry(bb->stmt_list.next);
diff --git a/test/jit/object-bc-test.c b/test/jit/object-bc-test.c
index 0180e5e..13f3501 100644
--- a/test/jit/object-bc-test.c
+++ b/test/jit/object-bc-test.c
@@ -337,14 +337,12 @@ static void assert_convert_array_store(enum vm_type 
expected_type,
                .code_attribute.code = code,
                .code_attribute.code_length = ARRAY_SIZE(code),
        };
-       struct var_info *temporary;
 
        bb = __alloc_simple_bb(&method);
 
        arrayref_expr = value_expr(J_REFERENCE, arrayref);
        index_expr = value_expr(J_INT, index);
-       temporary = get_var(bb->b_parent, J_INT);
-       expr = temporary_expr(expected_type, NULL, temporary);
+       expr = temporary_expr(expected_type, bb->b_parent);
 
        stack_push(bb->mimic_stack, arrayref_expr);
        stack_push(bb->mimic_stack, index_expr);
diff --git a/test/jit/tree-printer-test.c b/test/jit/tree-printer-test.c
index ca096e7..3cdf044 100644
--- a/test/jit/tree-printer-test.c
+++ b/test/jit/tree-printer-test.c
@@ -267,7 +267,14 @@ void assert_printed_temporary_expr(struct string 
*expected, enum vm_type type, s
 {
        struct expression *expr;
 
-       expr = temporary_expr(type, var, var2);
+       if (vm_type_is_float(type))
+               expr = alloc_expression(EXPR_FLOAT_TEMPORARY, type);
+       else
+               expr = alloc_expression(EXPR_TEMPORARY, type);
+
+       expr->tmp_low = var2;
+       expr->tmp_high = var;
+
        assert_print_expr(expected, expr);
 }
 
diff --git a/test/jit/typeconv-bc-test.c b/test/jit/typeconv-bc-test.c
index 77bac3a..2e8cb37 100644
--- a/test/jit/typeconv-bc-test.c
+++ b/test/jit/typeconv-bc-test.c
@@ -21,12 +21,10 @@ static void assert_conversion_mimic_stack(unsigned char opc,
        };
        struct expression *conversion_expression;
        struct expression *expression;
-       struct var_info *temporary;
        struct basic_block *bb;
 
        bb = __alloc_simple_bb(&method);
-       temporary = get_var(bb->b_parent, J_INT);
-       expression = temporary_expr(from_type, NULL, temporary);
+       expression = temporary_expr(from_type, bb->b_parent);
        stack_push(bb->mimic_stack, expression);
        convert_to_ir(bb->b_parent);
 
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to