From c74680df33884acd21880e513c89d5f3738ac86e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 30 Aug 2020 16:15:43 +0200 Subject: [PATCH] Fix #1781: TDCU: Support methods without .locals init --- .../IL/Transforms/TransformDisplayClassUsage.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs index 1b9e370cf..ba2038dd0 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs @@ -79,7 +79,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (declaredVariable != null) return declaredVariable; declaredVariable = container.Variable.Function.RegisterVariable(VariableKind.Local, field.Type, field.Name); - declaredVariable.HasInitialValue = true; + declaredVariable.HasInitialValue = container.Type.IsReferenceType != false || container.Variable.HasInitialValue; declaredVariable.CaptureScope = container.CaptureScope; return declaredVariable; } @@ -288,9 +288,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms HandleInitBlock(stloc.Parent as Block, stloc.ChildIndex + 1, result, result.Variable); break; case TypeKind.Struct: - if (!v.HasInitialValue) - return null; - if (v.StoreCount != 1) + if (v.StoreCount != (v.HasInitialValue ? 1 : 0)) return null; Debug.Assert(v.StoreInstructions.Count == 0); result = new DisplayClass(v, definition) { CaptureScope = v.CaptureScope };