Skip to content

Commit

Permalink
Include lower bounds when making array type signatures (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 authored Dec 13, 2024
1 parent d297c56 commit 3c1e235
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Cpp2IL.Core/Utils/AsmResolver/AsmResolverUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static TypeSignature GetTypeSignatureFromIl2CppType(ModuleDefinition modu
break;
case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
ret = GetTypeSignatureFromIl2CppType(module, il2CppType.GetArrayElementType())
.MakeArrayType(il2CppType.GetArrayRank());
.MakeArrayTypeWithLowerBounds(il2CppType.GetArrayRank());
break;
case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
ret = GetTypeSignatureFromIl2CppType(module, il2CppType.GetEncapsulatedType())
Expand Down Expand Up @@ -340,4 +340,13 @@ public static ITypeDefOrRef ImportTypeIfNeeded(this ReferenceImporter importer,
public static bool IsManagedMethodWithBody(this MethodDefinition managedMethod) =>
managedMethod.Managed && !managedMethod.IsAbstract && !managedMethod.IsPInvokeImpl
&& !managedMethod.IsInternalCall && !managedMethod.IsNative && !managedMethod.IsRuntime;

internal static ArrayTypeSignature MakeArrayTypeWithLowerBounds(this TypeSignature elementType, int rank)
{
var result = new ArrayTypeSignature(elementType, rank);
for (var i = 0; i < rank; i++)
result.Dimensions[i] = new ArrayDimension(null, 0);

return result;
}
}
2 changes: 1 addition & 1 deletion Cpp2IL.Core/Utils/AsmResolver/ContextToTypeSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static TypeSignature ToTypeSignature(this ByRefTypeAnalysisContext contex

public static TypeSignature ToTypeSignature(this ArrayTypeAnalysisContext context, ModuleDefinition parentModule)
{
return context.ElementType.ToTypeSignature(parentModule).MakeArrayType(context.Rank);
return context.ElementType.ToTypeSignature(parentModule).MakeArrayTypeWithLowerBounds(context.Rank);
}

public static TypeSignature ToTypeSignature(this ParameterAnalysisContext context, ModuleDefinition parentModule)
Expand Down

0 comments on commit 3c1e235

Please sign in to comment.