Skip to content

Commit 38cdf6d

Browse files
Avoid transforming sub pattern of cpblk stackalloc initializer
1 parent bd0fd8d commit 38cdf6d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ internal static bool TransformRuntimeHelpersCreateSpanInitialization(Call inst,
137137
return false;
138138
if (!field.HasFlag(System.Reflection.FieldAttributes.HasFieldRVA))
139139
return false;
140+
if (IsSubPatternOfCpblkInitializer(inst))
141+
return false;
140142
var initialValue = field.GetInitialValue(context.PEFile, context.TypeSystem);
141143
var elementTypeSize = elementType.GetSize();
142144
if (elementTypeSize <= 0 || initialValue.Length % elementTypeSize != 0)
@@ -146,6 +148,13 @@ internal static bool TransformRuntimeHelpersCreateSpanInitialization(Call inst,
146148
return replacement != null;
147149
}
148150

151+
private static bool IsSubPatternOfCpblkInitializer(Call inst)
152+
{
153+
if (inst.Parent is not AddressOf { Parent: Call { Parent: Cpblk cpblk } get_Item })
154+
return false;
155+
return MatchGetStaticFieldAddress(get_Item, out _);
156+
}
157+
149158
private static ILInstruction DecodeArrayInitializerOrUTF8StringLiteral(StatementTransformContext context, IType elementType, BlobReader initialValue, int size)
150159
{
151160
if (context.Settings.Utf8StringLiterals && elementType.IsKnownType(KnownTypeCode.Byte)
@@ -373,7 +382,7 @@ bool HandleCpblkInitializer(Block block, int pos, ILVariable v, long length, out
373382
return true;
374383
}
375384

376-
bool MatchGetStaticFieldAddress(ILInstruction input, out IField field)
385+
static bool MatchGetStaticFieldAddress(ILInstruction input, out IField field)
377386
{
378387
if (input.MatchLdsFlda(out field))
379388
return true;

0 commit comments

Comments
 (0)