Skip to content

Commit 17c94e3

Browse files
heyitsanthonyAnthony Romanoivg
authored
prevents IR block contraction on unconditional edges (#1543)
* plugins/bil: don't contract if b1 is keep / not weak Contraction / normalize conditions changed in 2.5.0 which causes IR normalization to drop the "when RCX <> 0 ... goto ..." for the instruction "rep cmpsb" (\xf3\xa6). This patch adds an extra keep/weak check to can_contract that keeps the when-cnd-goto made when reifying the rep while loop. * prevents contraction on conditional edges Co-authored-by: Anthony Romano <[email protected]> Co-authored-by: ivg <[email protected]>
1 parent b8e12b3 commit 17c94e3

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

plugins/bil/bil_ir.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ let is_call jmp = Option.is_some (Jmp.alt jmp)
3131
let is_empty = function
3232
| {entry; blks=[]} -> is_null entry
3333
| _ -> false
34+
let is_unconditional jmp = match Jmp.cond jmp with
35+
| Int w when Word.(w = b1) -> true
36+
| _ -> false
3437

3538
module BIR = struct
3639
type t = blk term list
@@ -82,15 +85,13 @@ module BIR = struct
8285
let single_dst = function
8386
| [] | _ :: _ :: _ -> None
8487
| [x] -> match dst x with
85-
| Some tid when not (is_call x) -> Some tid
88+
| Some tid when not (is_call x) && is_unconditional x -> Some tid
8689
| _ -> None
8790

88-
89-
let is_sub {weak; keep} = keep && weak
90-
9191
let can_contract refs b1 b2 =
9292
not (Tid.equal b1.name b2.name) &&
93-
(not b2.keep || b2.weak) && match single_dst b1.jmps with
93+
(not b2.keep || b2.weak) &&
94+
match single_dst b1.jmps with
9495
| None -> false
9596
| Some dst ->
9697
Tid.equal dst b2.name &&
@@ -408,10 +409,6 @@ module IR = struct
408409
blks = [blk entry ++ Jmp.reify ~tid ~dst:(Jmp.indirect dst) ()]
409410
}
410411

411-
let is_unconditional jmp = match Jmp.cond jmp with
412-
| Int w when Word.(w = b1) -> true
413-
| _ -> false
414-
415412
let fall ~tid x dst = match x.jmps with
416413
| [jmp] when is_call jmp ->
417414
let jmp' = Jmp.with_dst jmp @@ Some (Jmp.resolved dst) in

0 commit comments

Comments
 (0)