[jit] Don't crash in mono_op_imm_to_op if opcode is not handled
authorVlad Brezae <brezaevlad@gmail.com>
Tue, 5 Jan 2016 20:32:50 +0000 (22:32 +0200)
committerVlad Brezae <brezaevlad@gmail.com>
Thu, 14 Jan 2016 17:34:46 +0000 (19:34 +0200)
Mimic the behaviour of its counterpart, mono_op_to_op_imm, since crashing limits the usage of the function and it is the responsability of the upper layer.

mono/mini/mini-arm.c
mono/mini/mini-ia64.c
mono/mini/mini-mips.c
mono/mini/mini-ppc.c
mono/mini/mini.c

index 211c91e4eb252854c9cb4dc27b7e21f44528c3fe..a491184277a8cb5e82498d15674b5dcc06e691d4 100644 (file)
@@ -3463,11 +3463,14 @@ loop_start:
                case OP_IOR_IMM:
                case OP_IXOR_IMM:
                        if ((imm8 = mono_arm_is_rotated_imm8 (ins->inst_imm, &rot_amount)) < 0) {
+                               int opcode2 = mono_op_imm_to_op (ins->opcode);
                                ADD_NEW_INS (cfg, temp, OP_ICONST);
                                temp->inst_c0 = ins->inst_imm;
                                temp->dreg = mono_alloc_ireg (cfg);
                                ins->sreg2 = temp->dreg;
-                               ins->opcode = mono_op_imm_to_op (ins->opcode);
+                               if (opcode2 == -1)
+                                       g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
+                               ins->opcode = opcode2;
                        }
                        if (ins->opcode == OP_SBB || ins->opcode == OP_ISBB || ins->opcode == OP_SUBCC)
                                goto loop_start;
@@ -3507,13 +3510,17 @@ loop_start:
                case OP_IDIV_IMM:
                case OP_IDIV_UN_IMM:
                case OP_IREM_IMM:
-               case OP_IREM_UN_IMM:
+               case OP_IREM_UN_IMM: {
+                       int opcode2 = mono_op_imm_to_op (ins->opcode);
                        ADD_NEW_INS (cfg, temp, OP_ICONST);
                        temp->inst_c0 = ins->inst_imm;
                        temp->dreg = mono_alloc_ireg (cfg);
                        ins->sreg2 = temp->dreg;
-                       ins->opcode = mono_op_imm_to_op (ins->opcode);
+                       if (opcode2 == -1)
+                               g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
+                       ins->opcode = opcode2;
                        break;
+               }
                case OP_LOCALLOC_IMM:
                        ADD_NEW_INS (cfg, temp, OP_ICONST);
                        temp->inst_c0 = ins->inst_imm;
index 0e8838ae1223cea4ff0b043ee10d77de394a83e8..09bee82ed5f27b5b5eaf24d124bdb1f204ee7839 100644 (file)
@@ -1586,6 +1586,8 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
                                break;
                        }
 
+                       if (mono_op_imm_to_op (ins->opcode) == -1)
+                               g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
                        ins->opcode = mono_op_imm_to_op (ins->opcode);
 
                        if (ins->inst_imm == 0)
index 0e6953bd2328551132cb270295d77b078ae7ac54..fd0e074ecbbe6839ce2b1d72f3af2a8ef6ffa8d6 100644 (file)
@@ -2616,6 +2616,8 @@ map_to_reg_reg_op (int op)
        case OP_STOREI8_MEMBASE_IMM:
                return OP_STOREI8_MEMBASE_REG;
        }
+       if (mono_op_imm_to_op (op) == -1)
+               g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (op));
        return mono_op_imm_to_op (op);
 }
 
index 65ba8c35a988c855059019716a74b4bb0b37007b..6060e0a0782244354d369301801ad110fd8883d8 100644 (file)
@@ -2568,6 +2568,8 @@ map_to_reg_reg_op (int op)
        case OP_STOREI8_MEMBASE_IMM:
                return OP_STOREI8_MEMBASE_REG;
        }
+       if (mono_op_imm_to_op (op) == -1)
+               g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (op));
        return mono_op_imm_to_op (op);
 }
 
index 27202ebac2bd8491b5b125ea0f9adfd8d1fd7db5..35dd472d63baa155f232a6635036fc1c2de36891 100644 (file)
@@ -748,11 +748,9 @@ mono_op_imm_to_op (int opcode)
                return OP_ICOMPARE;
        case OP_LOCALLOC_IMM:
                return OP_LOCALLOC;
-       default:
-               printf ("%s\n", mono_inst_name (opcode));
-               g_assert_not_reached ();
-               return -1;
        }
+
+       return -1;
 }
 
 /*
@@ -763,13 +761,18 @@ mono_op_imm_to_op (int opcode)
 void
 mono_decompose_op_imm (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins)
 {
+       int opcode2 = mono_op_imm_to_op (ins->opcode);
        MonoInst *temp;
 
        MONO_INST_NEW (cfg, temp, OP_ICONST);
        temp->inst_c0 = ins->inst_imm;
        temp->dreg = mono_alloc_ireg (cfg);
        mono_bblock_insert_before_ins (bb, ins, temp);
-       ins->opcode = mono_op_imm_to_op (ins->opcode);
+
+       if (opcode2 == -1)
+                g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
+       ins->opcode = opcode2;
+
        if (ins->opcode == OP_LOCALLOC)
                ins->sreg1 = temp->dreg;
        else