Skip to content

Commit 8690dbe

Browse files
authored
[release/8.0-staging] JIT: Fix loop recognition bug in .NET 8 (#114457)
* JIT: Fix loop recognition bug in .NET 8 A loop preheader can't be a callfinally pair tail. Fixes #108811. * exclude new test from wasm
1 parent c8070f7 commit 8690dbe

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

src/coreclr/jit/optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ class LoopSearch
18011801
//
18021802
BasicBlock* FindEntry(BasicBlock* head, BasicBlock* top, BasicBlock* bottom)
18031803
{
1804-
if (head->bbJumpKind == BBJ_ALWAYS)
1804+
if ((head->bbJumpKind == BBJ_ALWAYS) && !head->isBBCallAlwaysPairTail())
18051805
{
18061806
if (head->bbJumpDest->bbNum <= bottom->bbNum && head->bbJumpDest->bbNum >= top->bbNum)
18071807
{
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Runtime.CompilerServices;
6+
using System.Security.Cryptography;
7+
using System.IO;
8+
using System.Text;
9+
using System.Threading;
10+
using Xunit;
11+
12+
public class Runtime_108811
13+
{
14+
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
15+
[Fact]
16+
public static int Test()
17+
{
18+
var hex = "3AE46205A50ED00E7612A91692552B7A";
19+
var key = "abcdef1234567890";
20+
var iv = "abcdef1234567890";
21+
var bytes = Convert.FromHexString(hex);
22+
int retval = 100;
23+
for (int i = 0; i < 200; i++)
24+
{
25+
var result = new Runtime_108811().Decrypt(bytes, key, iv, out _);
26+
Console.Write($"{result} ");
27+
if (result != 9)
28+
{
29+
retval = -1;
30+
break;
31+
}
32+
Thread.Sleep(10);
33+
}
34+
Console.WriteLine();
35+
return retval;
36+
}
37+
38+
public int Decrypt(byte[] buffer, string key, string iv, out byte[] decryptedData)
39+
{
40+
int decryptedByteCount = 0;
41+
decryptedData = new byte[buffer.Length];
42+
43+
using var aes = Aes.Create();
44+
aes.Mode = CipherMode.CBC;
45+
aes.KeySize = 128;
46+
aes.Padding = PaddingMode.Zeros;
47+
48+
var instPwdArray = Encoding.ASCII.GetBytes(key);
49+
var instSaltArray = Encoding.ASCII.GetBytes(iv);
50+
51+
using (var decryptor = aes.CreateDecryptor(instPwdArray, instSaltArray))
52+
{
53+
using (var memoryStream = new MemoryStream(buffer))
54+
{
55+
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
56+
{
57+
int read;
58+
do
59+
{
60+
read = cryptoStream.Read(
61+
decryptedData,
62+
decryptedByteCount,
63+
decryptedData.Length - decryptedByteCount);
64+
decryptedByteCount += read;
65+
} while (read != 0);
66+
}
67+
}
68+
}
69+
// Found the accurate length of decrypted data
70+
while (decryptedData[decryptedByteCount - 1] == 0 && decryptedByteCount > 0)
71+
decryptedByteCount--;
72+
return decryptedByteCount;
73+
}
74+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
</Project>

src/tests/issues.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,9 @@
32413241
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_90219/Runtime_90219/*">
32423242
<Issue>Loads an assembly from file</Issue>
32433243
</ExcludeList>
3244+
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_108811/Runtime_108811/*">
3245+
<Issue>Requires AES</Issue>
3246+
</ExcludeList>
32443247
</ItemGroup>
32453248

32463249
<ItemGroup Condition="'$(TargetArchitecture)' == 'wasm'">

0 commit comments

Comments
 (0)