Skip to content

Commit bbfc15c

Browse files
[release/6.0] Fix Crossgen2 bug dotnet#61104 and add regression test (dotnet#64027)
* Fix issue dotnet#61104 and add regression test The issue tracks the runtime regression failure where Crossgen2-compiled app is unable to locate a type with non-ASCII characters in its name. The failure was caused by the fact that Crossgen2 was incorrectly zero-extended the individual characters when calculating the hash whereas runtime is sign-extending them. Thanks Tomas * Simplify the regression test per Anton's PR feedback Co-authored-by: Tomas <trylek@microsoft.com>
1 parent 6de5c5b commit bbfc15c

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunHashCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public static int NameHashCode(string name)
3434
byte[] src = Encoding.UTF8.GetBytes(name);
3535
for (int i = 0; i < src.Length; i += 2)
3636
{
37-
hash1 = unchecked(hash1 + RotateLeft(hash1, 5)) ^ src[i];
37+
hash1 = unchecked(hash1 + RotateLeft(hash1, 5)) ^ (int)unchecked((sbyte)src[i]);
3838
if (i + 1 < src.Length)
3939
{
40-
hash2 = unchecked(hash2 + RotateLeft(hash2, 5)) ^ src[i + 1];
40+
hash2 = unchecked(hash2 + RotateLeft(hash2, 5)) ^ (int)unchecked((sbyte)src[i + 1]);
4141
}
4242
else
4343
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
var type = Type.GetType("_测试数据记录仪_Iiİı_åäö_Controller_DataLogger1_log_all_", false);
5+
var obj = Activator.CreateInstance(type!);
6+
Console.WriteLine(obj?.GetType().Name);
7+
8+
return 100;
9+
10+
public class _测试数据记录仪_Iiİı_åäö_Controller_DataLogger1_log_all_
11+
{
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<CLRTestPriority>1</CLRTestPriority>
8+
9+
<!-- This is an explicit crossgen test -->
10+
<AlwaysUseCrossGen2>true</AlwaysUseCrossGen2>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<Compile Include="test61104.cs" />
15+
</ItemGroup>
16+
17+
</Project>

0 commit comments

Comments
 (0)