Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@ void Lowering::ContainBlockStoreAddress(GenTreeBlk* blkNode, unsigned size, GenT
return;
}
#else // !TARGET_ARM
if ((ClrSafeInt<int>(offset) + ClrSafeInt<int>(size)).IsOverflow())
// Keep offset + size strictly below INT32_MAX, as required by unrolled block codegen.
ClrSafeInt<int> endOffset = ClrSafeInt<int>(offset) + ClrSafeInt<int>(size);
if (endOffset.IsOverflow() || (endOffset.Value() == INT32_MAX))
{
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ void Lowering::ContainBlockStoreAddress(GenTreeBlk* blkNode, unsigned size, GenT
// up to 16 bytes lower than offset + size. But offsets large enough to hit this case are likely
// to be extremely rare for this to ever be a CQ issue.
// On x86 this shouldn't be needed but then again, offsets large enough to hit this are rare.
if (addrMode->Offset() > (INT32_MAX - static_cast<int>(size)))
// Keep offset + size strictly below INT32_MAX, as required by unrolled block codegen.
if (addrMode->Offset() >= (INT32_MAX - static_cast<int>(size)))
{
return;
}
Expand Down
37 changes: 37 additions & 0 deletions src/tests/JIT/Regression_ro_2/Runtime_133785.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_133785
{
// On x64, the element offset is 16 + Index * 3 == int.MaxValue - 3.
private const int Index = 715827876;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting this to 715827875 instead still hits an assert in codegenarmarch due to some overflowing signed int math in UnrollInitBlock. Bug existed before your change though so up to you if its easy enough to fix while youre in here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, interesting, I'll check


private struct S3
{
public byte A, B, C;
}

[Fact]
public static void TestEntryPoint()
{
S3[] array = new S3[1];
S3 value = new S3 { A = 1, B = 2, C = 3 };

Assert.Throws<IndexOutOfRangeException>(() => StoreInit(array));
Assert.Throws<IndexOutOfRangeException>(() => StoreCopy(array, value));
Assert.Throws<IndexOutOfRangeException>(() => LoadCopy(array, ref value));
}

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static void StoreInit(S3[] array) => array[Index] = default;

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static void StoreCopy(S3[] array, S3 value) => array[Index] = value;

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static void LoadCopy(S3[] array, ref S3 value) => value = array[Index];
}
Loading