Skip to content

Commit f7ca84a

Browse files
authored
[tools] Make the dead code removal optimizer correctly handle unconditional branches. (#23107)
When handling an unconditional branch, we need to mark all the instructions until the end of the method, not only until the end of block that is currently being processed. This fixes a problem where the dead code optimizer would optimize away code after an unconditonal branch, ending up with invalid IL because code that wasn't optimized away would have branches into the removed code.
1 parent 9a36e6b commit f7ca84a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/linker/CoreOptimizeGeneratedCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static bool MarkInstructions (MethodDefinition method, Mono.Collections.Generic.
330330
case FlowControl.Branch:
331331
// Unconditional branch, we continue marking from the instruction that we branch to.
332332
var br_target = (Instruction) ins.Operand;
333-
return MarkInstructions (method, instructions, reachable, instructions.IndexOf (br_target), end);
333+
return MarkInstructions (method, instructions, reachable, instructions.IndexOf (br_target), instructions.Count);
334334
case FlowControl.Cond_Branch:
335335
// Conditional instruction, we need to check if we can calculate a constant value for the condition
336336
var cond_target = ins.Operand as Instruction;

0 commit comments

Comments
 (0)