From f249d39a1dfb34534f044fb95646e9139b996f44 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Fri, 16 Dec 2016 14:58:57 -0500 Subject: [PATCH] [simd] Fix the exception thrown by Vector.CopyTo () on a failed bounds check. --- mono/mini/basic-vectors.cs | 2 +- mono/mini/simd-intrinsics.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mono/mini/basic-vectors.cs b/mono/mini/basic-vectors.cs index 1830fd9a8bc..3b8c50c181a 100644 --- a/mono/mini/basic-vectors.cs +++ b/mono/mini/basic-vectors.cs @@ -1410,7 +1410,7 @@ public class VectorTests { try { vector_copyto (v1, arr, 241); return 1; - } catch (IndexOutOfRangeException) { + } catch (ArgumentException) { } return 0; } diff --git a/mono/mini/simd-intrinsics.c b/mono/mini/simd-intrinsics.c index b237968189c..9b31c3fa69b 100644 --- a/mono/mini/simd-intrinsics.c +++ b/mono/mini/simd-intrinsics.c @@ -2224,7 +2224,11 @@ emit_vector_t_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSigna /* Emit index check for the end (index + len - 1 < array length) */ end_index_reg = alloc_ireg (cfg); EMIT_NEW_BIALU_IMM (cfg, ins, OP_IADD_IMM, end_index_reg, index_ins->dreg, len - 1); - MONO_EMIT_BOUNDS_CHECK (cfg, array_ins->dreg, MonoArray, max_length, end_index_reg); + + int length_reg = alloc_ireg (cfg); + MONO_EMIT_NEW_LOAD_MEMBASE_OP_FAULT (cfg, OP_LOADI4_MEMBASE, length_reg, array_ins->dreg, MONO_STRUCT_OFFSET (MonoArray, max_length)); + MONO_EMIT_NEW_BIALU (cfg, OP_COMPARE, -1, length_reg, end_index_reg); + MONO_EMIT_NEW_COND_EXC (cfg, LE_UN, "ArgumentException"); /* Load the simd reg into the array slice */ ldelema_ins = mini_emit_ldelema_1_ins (cfg, mono_class_from_mono_type (etype), array_ins, index_ins, TRUE); -- 2.25.1