Skip to content

Commit 16a9e36

Browse files
committed
Added setting to prevent Ldvirtftn argument remove for better DCE optimisation.
1 parent ff62e15 commit 16a9e36

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

ICSharpCode.Decompiler/DecompilerSettings.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,21 @@ public CSharpFormattingOptions CSharpFormattingOptions {
333333
}
334334
}
335335
}
336+
337+
bool skipLdvirtftnArgumentRemove = false;
338+
339+
public bool SkipLdvirtftnArgumentRemove
340+
{
341+
get { return skipLdvirtftnArgumentRemove; }
342+
set
343+
{
344+
if (skipLdvirtftnArgumentRemove != value)
345+
{
346+
skipLdvirtftnArgumentRemove = value;
347+
OnPropertyChanged("SkipLdvirtftnArgumentRemove");
348+
}
349+
}
350+
}
336351

337352
public event PropertyChangedEventHandler PropertyChanged;
338353

ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ void IntroducePropertyAccessInstructions(ILExpression expr, ILExpression parentE
445445
if (expr.Arguments[0].Match(ILCode.Ldloc, out target)
446446
&& expr.Arguments[1].Code == ILCode.Ldvirtftn
447447
&& expr.Arguments[1].Arguments.Count == 1
448-
&& expr.Arguments[1].Arguments[0].MatchLdloc(target))
448+
&& expr.Arguments[1].Arguments[0].MatchLdloc(target)
449+
&& context.Settings.SkipLdvirtftnArgumentRemove)
449450
{
450451
// Remove the 'target' argument from the ldvirtftn instruction.
451452
// It's not needed in the translation to C#, and needs to be eliminated so that the target expression

0 commit comments

Comments
 (0)