未验证 提交 195a0a90 编写于 作者: S SingleAccretion 提交者: GitHub

Tighten checks in `areArgumentsContiguous` (#70829)

* Tighten checks in "areArgumentsContiguous"

* Add a test
上级 401722be
......@@ -1685,7 +1685,15 @@ bool Compiler::areArrayElementsContiguous(GenTree* op1, GenTree* op2)
//
bool Compiler::areArgumentsContiguous(GenTree* op1, GenTree* op2)
{
if (op1->OperIs(GT_IND) && op2->OperIs(GT_IND))
if (op1->TypeGet() != op2->TypeGet())
{
return false;
}
assert(!op1->TypeIs(TYP_STRUCT));
if (op1->OperIs(GT_IND) && op1->AsIndir()->Addr()->OperIs(GT_INDEX_ADDR) && op2->OperIs(GT_IND) &&
op2->AsIndir()->Addr()->OperIs(GT_INDEX_ADDR))
{
return areArrayElementsContiguous(op1, op2);
}
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Numerics;
using System.Runtime.CompilerServices;
public unsafe class Runtime_70824
{
public static int Main()
{
long lng = 2;
float flt = 3;
Vector2 vtor = new Vector2(4, 5);
float[] arr = new float[] { 6, 7 };
if (ProblemWithTypes(&lng, &flt, vtor))
{
return 101;
}
if (ProblemWithAddrs(&flt, arr, vtor))
{
return 102;
}
return 100;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool ProblemWithTypes(long* p1, float* pF, Vector2 vtor)
{
*pF = vtor.X;
*p1 = (long)*pF;
return *p1 != (long)*pF;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool ProblemWithAddrs(float* pF, float[] arr, Vector2 vtor)
{
*pF = vtor.X;
arr[0] = vtor.Y;
arr[1] = vtor.X;
*pF = vtor.Y;
return arr[0] != vtor.Y || *pF != vtor.Y;
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册