@@ -2553,6 +2553,9 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
2553
2553
if (index < 0 || index >= elems ) {
2554
2554
MONO_EMIT_NEW_BIALU_IMM (cfg , OP_COMPARE_IMM , -1 , args [1 ]-> dreg , elems );
2555
2555
MONO_EMIT_NEW_COND_EXC (cfg , GE_UN , "ArgumentOutOfRangeException" );
2556
+
2557
+ // Fixup the index to be in range so codegen is still valid
2558
+ index %= elems ;
2556
2559
}
2557
2560
2558
2561
// Bounds check is elided if we know the index is safe.
@@ -3220,8 +3223,11 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
3220
3223
// If the index is provably a constant, we can generate vastly better code.
3221
3224
int index = GTMREG_TO_INT (args [1 ]-> inst_c0 );
3222
3225
if (index < 0 || index >= elems ) {
3223
- MONO_EMIT_NEW_BIALU_IMM (cfg , OP_COMPARE_IMM , -1 , args [1 ]-> dreg , elems );
3224
- MONO_EMIT_NEW_COND_EXC (cfg , GE_UN , "ArgumentOutOfRangeException" );
3226
+ MONO_EMIT_NEW_BIALU_IMM (cfg , OP_COMPARE_IMM , -1 , args [1 ]-> dreg , elems );
3227
+ MONO_EMIT_NEW_COND_EXC (cfg , GE_UN , "ArgumentOutOfRangeException" );
3228
+
3229
+ // Fixup the index to be in range so codegen is still valid
3230
+ index %= elems ;
3225
3231
}
3226
3232
3227
3233
return emit_vector_insert_element (cfg , klass , args [0 ], arg0_type , args [2 ], index , FALSE);
@@ -3766,6 +3772,9 @@ emit_vector_2_3_4 (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f
3766
3772
if (index < 0 || index >= len ) {
3767
3773
MONO_EMIT_NEW_BIALU_IMM (cfg , OP_COMPARE_IMM , -1 , args [1 ]-> dreg , len );
3768
3774
MONO_EMIT_NEW_COND_EXC (cfg , GE_UN , "ArgumentOutOfRangeException" );
3775
+
3776
+ // Fixup the index to be in range so codegen is still valid
3777
+ index %= len ;
3769
3778
}
3770
3779
3771
3780
int opcode = type_to_extract_op (ty );
@@ -3852,6 +3861,9 @@ emit_vector_2_3_4 (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f
3852
3861
if (index < 0 || index >= len ) {
3853
3862
MONO_EMIT_NEW_BIALU_IMM (cfg , OP_COMPARE_IMM , -1 , args [1 ]-> dreg , len );
3854
3863
MONO_EMIT_NEW_COND_EXC (cfg , GE_UN , "ArgumentOutOfRangeException" );
3864
+
3865
+ // Fixup the index to be in range so codegen is still valid
3866
+ index %= len ;
3855
3867
}
3856
3868
3857
3869
if (args [0 ]-> dreg == dreg ) {
0 commit comments