From 8c2f26bfcb5a27fed68c4601b713f27ac7fee6b7 Mon Sep 17 00:00:00 2001 From: de4dot Date: Fri, 21 Oct 2011 18:53:36 +0200 Subject: [PATCH] Replace stloc + ldloc with dup + stloc only if it's a bool local --- blocks/cflow/StLdlocFixer.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/blocks/cflow/StLdlocFixer.cs b/blocks/cflow/StLdlocFixer.cs index b240a505..c8ce9c2e 100644 --- a/blocks/cflow/StLdlocFixer.cs +++ b/blocks/cflow/StLdlocFixer.cs @@ -46,7 +46,7 @@ namespace de4dot.blocks.cflow { for (int i = 0; i < instructions.Count; i++) { var instr = instructions[i]; switch (instr.OpCode.Code) { - // Xenocode generates stloc + ldloc. Replace it with dup + stloc. It will eventually + // Xenocode generates stloc + ldloc (bool). Replace it with dup + stloc. It will eventually // become dup + pop and be removed. case Code.Stloc: case Code.Stloc_S: @@ -58,7 +58,10 @@ namespace de4dot.blocks.cflow { break; if (!instructions[i + 1].isLdloc()) break; - if (Instr.getLocalVar(locals, instr) != Instr.getLocalVar(locals, instructions[i + 1])) + var local = Instr.getLocalVar(locals, instr); + if (local.VariableType.FullName != "System.Boolean") + continue; + if (local != Instr.getLocalVar(locals, instructions[i + 1])) break; instructions[i] = new Instr(Instruction.Create(OpCodes.Dup)); instructions[i + 1] = instr;