Skip to content

Commit 9fade46

Browse files
committed
Fix PushExecutionFlow not terminating basic block
1 parent c496033 commit 9fade46

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

SummaryGenerator.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public enum ReferenceType
108108
JumpTrue,
109109
JumpFalse,
110110
Push,
111+
Pop,
111112
Latent,
112113
Function,
113114
}
@@ -560,10 +561,11 @@ static List<BasicBlock> BuildBasicBlocks(List<Instruction> instructions, HashSet
560561
var lastInstr = block.Instructions[^1];
561562
foreach (var reference in lastInstr.ReferencedAddresses)
562563
{
563-
// Skip types already added above
564+
// Skip types already added above, and skip Pop (indirect jump with no known target)
564565
if (reference.Type != ReferenceType.Function &&
565566
reference.Type != ReferenceType.Latent &&
566-
reference.Type != ReferenceType.Push)
567+
reference.Type != ReferenceType.Push &&
568+
reference.Type != ReferenceType.Pop)
567569
{
568570
block.Successors.Add(new BlockEdge(
569571
reference.Address,
@@ -581,11 +583,13 @@ static bool IsBlockTerminator(Instruction instr)
581583
// Block terminates when control flow branches or has special flow
582584
// - JumpTrue/JumpFalse = conditional branch
583585
// - Push/Latent = special flow (latent actions, push execution flow)
586+
// - Pop = indirect jump to previously pushed address
584587
// - No Normal reference = no fall-through (terminal instructions)
585588
return instr.ReferencedAddresses.Any(r =>
586589
r.Type == ReferenceType.JumpTrue ||
587590
r.Type == ReferenceType.JumpFalse ||
588591
r.Type == ReferenceType.Push ||
592+
r.Type == ReferenceType.Pop ||
589593
r.Type == ReferenceType.Latent) ||
590594
!instr.ReferencedAddresses.Any(r => r.Type == ReferenceType.Normal);
591595
}
@@ -797,13 +801,15 @@ Lines Stringify(KismetExpression exp, ref uint index, List<Reference> referenced
797801
case EX_PopExecutionFlow e:
798802
{
799803
lines = new Lines(addr).Expr(e);
804+
referencedAddresses.Add(new Reference(uint.MaxValue, ReferenceType.Pop));
800805
break;
801806
}
802807
case EX_PopExecutionFlowIfNot e:
803808
{
804809
lines = new Lines(addr).Expr(e);
805810
lines.Add(Stringify(e.BooleanExpression, ref index, referencedAddresses));
806-
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.Normal));
811+
if (top) referencedAddresses.Add(new Reference(uint.MaxValue, ReferenceType.Pop));
812+
if (top) referencedAddresses.Add(new Reference(index, ReferenceType.JumpTrue));
807813
break;
808814
}
809815
case EX_CallMath e:

0 commit comments

Comments
 (0)