2007-06-05 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / branch-opts.c
index b9656f57060e8e1e42d66bd3b120f9e275e42e57..5d01e03ad6800a9fd8284efb992124cb05e6d61a 100644 (file)
@@ -35,7 +35,7 @@ mono_branch_optimize_exception_target (MonoCompile *cfg, MonoBasicBlock *bb, con
        for (i = 0; i < header->num_clauses; ++i) {
                clause = &header->clauses [i];
                if (MONO_OFFSET_IN_CLAUSE (clause, bb->real_offset)) {
-                       if (clause->data.catch_class && mono_class_is_assignable_from (clause->data.catch_class, exclass)) {
+                       if (clause->flags == MONO_EXCEPTION_CLAUSE_NONE && clause->data.catch_class && mono_class_is_assignable_from (clause->data.catch_class, exclass)) {
                                MonoBasicBlock *tbb;
 
                                /* get the basic block for the handler and 
@@ -43,7 +43,7 @@ mono_branch_optimize_exception_target (MonoCompile *cfg, MonoBasicBlock *bb, con
                                 * Flag is set during method_to_ir due to 
                                 * pop-op is optmized away in codegen (burg).
                                 */
-                               tbb = g_hash_table_lookup (cfg->bb_hash, header->code + clause->handler_offset);
+                               tbb = cfg->cil_offset_to_bb [clause->handler_offset];
                                if (tbb && tbb->flags & BB_EXCEPTION_DEAD_OBJ && !(tbb->flags & BB_EXCEPTION_UNSAFE)) {
                                        MonoBasicBlock *targetbb = tbb;
                                        gboolean unsafe = FALSE;
@@ -68,7 +68,7 @@ mono_branch_optimize_exception_target (MonoCompile *cfg, MonoBasicBlock *bb, con
                                                /* Create dummy inst to allow easier integration in
                                                 * arch dependent code (opcode ignored)
                                                 */
-                                               MONO_INST_NEW (cfg, jump, CEE_BR);
+                                               MONO_INST_NEW (cfg, jump, OP_BR);
 
                                                /* Allocate memory for our branch target */
                                                jump->inst_i1 = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoInst));
@@ -82,6 +82,9 @@ mono_branch_optimize_exception_target (MonoCompile *cfg, MonoBasicBlock *bb, con
 
                                        return NULL;
                                }
+                       } else {
+                               /* Branching to an outer clause could skip inner clauses */
+                               return NULL;
                        }
                }
        }