File tree Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Original file line number Diff line number Diff line change
1
+ package ir .transforms
2
+
3
+ import ir .*
4
+ import ir .cilvisitor .*
5
+
6
+ import analysis .{LatticeSet }
7
+
8
+ import collection .immutable
9
+
10
+ /**
11
+ * Find blocks which are mentioned syntactically within a given procedure.
12
+ *
13
+ * Includes the entry block, and overapproximates in the presence of indirect calls.
14
+ */
15
+ class FindGotoTargets extends CILVisitor {
16
+
17
+ var keep : LatticeSet [Block ] = LatticeSet .Bottom ()
18
+
19
+ override def vproc (p : Procedure ) = {
20
+ keep = keep ++ p.entryBlock
21
+ DoChildren ()
22
+ }
23
+
24
+ override def vstmt (s : Statement ) = {
25
+ s match {
26
+ case IndirectCall (_, _) => keep = LatticeSet .Top ()
27
+ case _ => ()
28
+ }
29
+ SkipChildren ()
30
+ }
31
+
32
+ override def vjump (s : Jump ) = {
33
+ s match {
34
+ case GoTo (targs, _) => keep = keep ++ targs
35
+ case _ => ()
36
+ }
37
+ SkipChildren ()
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Very coarse transform pass to remove obviously unreachable blocks.
43
+ *
44
+ * This only removes in the most simple cases.
45
+ * Does NOT remove:
46
+ * - mutually-recursive unreachable blocks,
47
+ * - blocks only reachable from unreachable blocks.
48
+ * - any blocks in the presence of indirect calls.
49
+ */
50
+ object RemoveUnreachableBlocks {
51
+ def apply (p : Procedure ) = {
52
+ val vis = FindGotoTargets ()
53
+ visit_proc(vis, p)
54
+ val keepBlocks = vis.keep
55
+ p.blocks.toList.filterNot(keepBlocks.contains).foreach(p.removeBlocks)
56
+ }
57
+ }
Original file line number Diff line number Diff line change @@ -894,7 +894,8 @@ object RunUtils {
894
894
895
895
if (! q.loading.keepPC) {
896
896
visit_prog(transforms.RemovePCStatements (), ctx.program)
897
- Logger .info(s " [!] Removed PC-related statements " )
897
+ ctx.program.procedures.foreach(transforms.RemoveUnreachableBlocks .apply)
898
+ Logger .info(s " [!] Removed PC-related statements and unreachable blocks " )
898
899
}
899
900
900
901
if (q.loading.parameterForm && ! q.simplify) {
You can’t perform that action at this time.
0 commit comments