From c22977e1be7f4cf4447aa349c5398f013bd64c2b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 4 Jun 2021 19:53:09 +0200 Subject: [PATCH] Fix #2390: Extend variable splitting to treat stobj as immediate address use. --- .../TestCases/Pretty/InitializerTests.cs | 15 +++++++++++++++ .../TestCases/Pretty/ValueTypes.cs | 2 +- .../IL/Transforms/SplitVariables.cs | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs index 8e0c9bd8f..93044e83e 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -233,6 +233,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests } #endregion + private S s1; + private S s2; + #region Field initializer tests private static V3f[] Issue1336_rg0 = new V3f[3] { new V3f(1f, 1f, 1f), @@ -905,6 +908,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests }); } + public void InliningOfStFldTarget() + { + s1 = new S { + A = 24, + B = 42 + }; + s2 = new S { + A = 42, + B = 24 + }; + } + public static void NotAStructInitializer_ExplicitConstructor() { StructData structData = new StructData(0); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ValueTypes.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ValueTypes.cs index b57b90d07..c40e55f4c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ValueTypes.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ValueTypes.cs @@ -282,7 +282,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty return ulong.MaxValue.ToString(); } - public static void M4() + public static void InliningDefaultValue() { Test(default(DateTime).GetType()); Test(default(DateTime).ToString()); diff --git a/ICSharpCode.Decompiler/IL/Transforms/SplitVariables.cs b/ICSharpCode.Decompiler/IL/Transforms/SplitVariables.cs index 18216219c..621450a17 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SplitVariables.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SplitVariables.cs @@ -103,7 +103,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms { switch (addressLoadingInstruction.Parent) { - case LdObj ldobj: + case LdObj _: + case StObj stobj when stobj.Target == addressLoadingInstruction: return AddressUse.Immediate; case LdFlda ldflda: return DetermineAddressUse(ldflda, targetVar);