Browse Source

Fix #211 InvalidCastException in ILAstOptimizer.TransformArrayInitializers

pull/252/head
Daniel Grunwald 15 years ago
parent
commit
17a75ded4e
  1. 21
      ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs

21
ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs

@ -124,19 +124,24 @@ namespace ICSharpCode.Decompiler.ILAst
MethodReference methodRef; MethodReference methodRef;
ILExpression methodArg1; ILExpression methodArg1;
ILExpression methodArg2; ILExpression methodArg2;
FieldDefinition field; FieldReference fieldRef;
if (body.ElementAtOrDefault(pos).Match(ILCode.Call, out methodRef, out methodArg1, out methodArg2) && if (body.ElementAtOrDefault(pos).Match(ILCode.Call, out methodRef, out methodArg1, out methodArg2) &&
methodRef.DeclaringType.FullName == "System.Runtime.CompilerServices.RuntimeHelpers" && methodRef.DeclaringType.FullName == "System.Runtime.CompilerServices.RuntimeHelpers" &&
methodRef.Name == "InitializeArray" && methodRef.Name == "InitializeArray" &&
methodArg1.Match(ILCode.Ldloc, out v2) && methodArg1.Match(ILCode.Ldloc, out v2) &&
array == v2 && array == v2 &&
methodArg2.Match(ILCode.Ldtoken, out field) && methodArg2.Match(ILCode.Ldtoken, out fieldRef))
field != null && field.InitialValue != null) { {
ILExpression[] newArr = new ILExpression[arrayLength]; FieldDefinition fieldDef = fieldRef.ResolveWithinSameModule();
if (DecodeArrayInitializer(TypeAnalysis.GetTypeCode(arrayType.GetElementType()), field.InitialValue, newArr)) { if (fieldDef != null && fieldDef.InitialValue != null) {
values = newArr; ILExpression[] newArr = new ILExpression[arrayLength];
foundPos = pos; if (DecodeArrayInitializer(TypeAnalysis.GetTypeCode(arrayType.GetElementType()),
return true; fieldDef.InitialValue, newArr))
{
values = newArr;
foundPos = pos;
return true;
}
} }
} }
values = null; values = null;

Loading…
Cancel
Save