Skip to content

Commit ce2dc37

Browse files
committed
Handle unreachable blocks in IR printing
Unreachable basic blocks are now assigned a large distance to ensure they are sorted last. Additionally, blocks without an order are labeled as 'Block (unordered)' to improve clarity in IR output. Changes are attempt to fix instances of `(no string representation)` in output
1 parent c19dc30 commit ce2dc37

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

binary/ql/lib/semmle/code/binary/ast/ir/PrintIR.ql

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,17 @@ private int getBlockOrderingInFunction(Function f, BasicBlock bb) {
103103
bb =
104104
rank[result + 1](BasicBlock bb2, string s, int d |
105105
bb2.getEnclosingFunction() = f and
106-
d = distanceFromEntry(f.getEntryBlock(), bb2) and
106+
(
107+
d = distanceFromEntry(f.getEntryBlock(), bb2)
108+
or
109+
// Unreachable blocks get a large distance so they sort last
110+
not exists(distanceFromEntry(f.getEntryBlock(), bb2)) and d = 999999
111+
) and
107112
s =
108-
strictconcat(int i, string instr |
113+
concat(int i, string instr |
109114
instr = bb2.getNode(i).asInstruction().toString()
110115
|
111-
instr order by i
116+
instr, "" order by i
112117
)
113118
|
114119
bb2 order by d, s
@@ -134,7 +139,12 @@ private class PrintableIRBlock extends PrintableNode, TPrintableBasicBlock {
134139

135140
override Location getLocation() { result = block.getLocation() }
136141

137-
override string getLabel() { result = "Block " + this.getOrder() }
142+
override string getLabel() {
143+
result = "Block " + this.getOrder()
144+
or
145+
not exists(this.getOrder()) and
146+
result = "Block (unordered)"
147+
}
138148

139149
override int getOrder() { result = getBlockIndex(block) }
140150

0 commit comments

Comments
 (0)