Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unsigned index extension in muldi-dimensional array stubs #22376

Merged
merged 1 commit into from Feb 3, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -781,7 +781,6 @@ class ArrayOpLinker : public ILStubLinker
BOOL fHasLowerBounds = pMT->GetInternalCorElementType() == ELEMENT_TYPE_ARRAY;

DWORD dwTotalLocalNum = NewLocal(ELEMENT_TYPE_I4);
DWORD dwFactorLocalNum = NewLocal(ELEMENT_TYPE_I4);
DWORD dwLengthLocalNum = NewLocal(ELEMENT_TYPE_I4);

mdToken tokRawData = GetToken(MscorlibBinder::GetField(FIELD__RAW_DATA__DATA));
@@ -793,16 +792,13 @@ class ArrayOpLinker : public ILStubLinker
ILCodeLabel * pTypeMismatchExceptionLabel = NULL;

UINT rank = pMT->GetRank();
UINT idx = rank;
UINT firstIdx = 0;
UINT hiddenArgIdx = rank;
_ASSERTE(rank>0);


#ifndef _TARGET_X86_
if(m_pMD->GetArrayFuncIndex() == ArrayMethodDesc::ARRAY_FUNC_ADDRESS)
{
idx++;
firstIdx = 1;
hiddenArgIdx = 0;
}
@@ -903,30 +899,30 @@ class ArrayOpLinker : public ILStubLinker
m_pCode->EmitLDFLDA(tokRawData);
m_pCode->EmitLDC(ArrayBase::GetBoundsOffset(pMT) - Object::GetOffsetOfFirstField());
m_pCode->EmitADD();
m_pCode->EmitLDARG(firstIdx);
m_pCode->EmitLDARG(firstIdx);

This comment has been minimized.

Copy link
@mikedn

mikedn Feb 3, 2019

Contributor

I guess the SZArray case doesn't use ldelem for simplicity/consistency?

This comment has been minimized.

Copy link
@jkotas

jkotas Feb 3, 2019

Author Member

I think so. Also, it would make the native stub code a bit bigger.

m_pCode->EmitBR(pCheckDone);
m_pCode->EmitLabel(pNotSZArray);
}

while(idx-- > firstIdx)
for (UINT i = 0; i < rank; i++)
{
// Cache length
m_pCode->EmitLoadThis();
m_pCode->EmitLDFLDA(tokRawData);
m_pCode->EmitLDC((ArrayBase::GetBoundsOffset(pMT) - Object::GetOffsetOfFirstField()) + (idx-firstIdx)*sizeof(DWORD));
m_pCode->EmitLDC((ArrayBase::GetBoundsOffset(pMT) - Object::GetOffsetOfFirstField()) + i*sizeof(DWORD));
m_pCode->EmitADD();
m_pCode->EmitLDIND_I4();
m_pCode->EmitSTLOC(dwLengthLocalNum);

// Fetch index
m_pCode->EmitLDARG(idx);
m_pCode->EmitLDARG(firstIdx + i);

if (fHasLowerBounds)
{
// Load lower bound
m_pCode->EmitLoadThis();
m_pCode->EmitLDFLDA(tokRawData);
m_pCode->EmitLDC((ArrayBase::GetLowerBoundsOffset(pMT) - Object::GetOffsetOfFirstField()) + (idx-firstIdx)*sizeof(DWORD));
m_pCode->EmitLDC((ArrayBase::GetLowerBoundsOffset(pMT) - Object::GetOffsetOfFirstField()) + i*sizeof(DWORD));
m_pCode->EmitADD();
m_pCode->EmitLDIND_I4();

@@ -940,26 +936,14 @@ class ArrayOpLinker : public ILStubLinker
m_pCode->EmitBGE_UN(pRangeExceptionLabel1);

// Add to the running total if we have one already
if ((idx-firstIdx) != (rank - 1))
if (i > 0)
{
m_pCode->EmitLDLOC(dwFactorLocalNum);
m_pCode->EmitMUL();
m_pCode->EmitLDLOC(dwTotalLocalNum);
m_pCode->EmitLDLOC(dwLengthLocalNum);
m_pCode->EmitMUL();
m_pCode->EmitADD();
}
m_pCode->EmitSTLOC(dwTotalLocalNum);

// Update factor if this is not the last iteration
if ((idx-firstIdx) != 0)
{
m_pCode->EmitLDLOC(dwLengthLocalNum);
if ((idx-firstIdx) != (rank - 1))
{
m_pCode->EmitLDLOC(dwFactorLocalNum);
m_pCode->EmitMUL();
}
m_pCode->EmitSTLOC(dwFactorLocalNum);
}
}

// Compute element address
@@ -968,9 +952,11 @@ class ArrayOpLinker : public ILStubLinker
m_pCode->EmitLDC(ArrayBase::GetDataPtrOffset(pMT) - Object::GetOffsetOfFirstField());
m_pCode->EmitADD();
m_pCode->EmitLDLOC(dwTotalLocalNum);

m_pCode->EmitLabel(pCheckDone);


m_pCode->EmitCONV_U();

SIZE_T elemSize = pMT->GetComponentSize();
if (elemSize != 1)
{
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E55A6F8B-B9E3-45CE-88F4-22AE70F606CB}</ProjectGuid>
<OutputType>Exe</OutputType>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLRTestKind>BuildAndRun</CLRTestKind>
<CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<!-- Add Compile Object Here -->
<Compile Include="test22348.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
</PropertyGroup>
</Project>
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;

public class Test22348
{
public static int Main()
{
try
{
byte[,] tooBig = new byte[267784, 15351];
tooBig[139893, 12] = 100;
return (byte)tooBig.GetValue(139893, 12);
}
catch (OutOfMemoryException e)
{
Console.WriteLine(e);
}

return 100;
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.