Skip to content

Commit 7849e72

Browse files
authored
Merge pull request #231 from UQ-PAC/yousif-fixMemoryInjection
Adding Memory Regions to IR
2 parents d4dc24a + ba13989 commit 7849e72

File tree

427 files changed

+5960
-10284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

427 files changed

+5960
-10284
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdio.h>
2+
3+
// Function declarations
4+
int addNumbers(int a, int b);
5+
6+
int callAddFromAnotherFunction(int x, int y) {
7+
return addNumbers(x, y);
8+
}
9+
10+
int callFromFun2(int x, int y) {
11+
return addNumbers(x, y);
12+
}
13+
14+
int addNumbers(int a, int b) {
15+
return a + b;
16+
}
17+
18+
int main() {
19+
int resultFromMain = addNumbers(10, 5);
20+
int resultFromOtherFunc = callAddFromAnotherFunction(20, 15);
21+
int resultFromFun2 = callFromFun2(30, 25);
22+
return 0;
23+
}

src/main/scala/Main.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ object Main {
4949
@arg(name = "threads", short = 't', doc = "Separates threads into multiple .bpl files with given output filename as prefix (requires --analyse flag)")
5050
threadSplit: Flag,
5151
@arg(name = "summarise-procedures", doc = "Generates summaries of procedures which are used in pre/post-conditions (requires --analyse flag)")
52-
summariseProcedures: Flag
52+
summariseProcedures: Flag,
53+
@arg(name = "memory-regions", doc = "Performs static analysis to separate memory into discrete regions in Boogie output (requires --analyse flag)")
54+
memoryRegions: Flag
5355
)
5456

5557
def main(args: Array[String]): Unit = {
@@ -82,7 +84,7 @@ object Main {
8284
val q = BASILConfig(
8385
loading = ILLoadingConfig(conf.inputFileName, conf.relfFileName, conf.specFileName, conf.dumpIL, conf.mainProcedureName, conf.procedureDepth),
8486
runInterpret = conf.interpret.value,
85-
staticAnalysis = if conf.analyse.value then Some(StaticAnalysisConfig(conf.dumpIL, conf.analysisResults, conf.analysisResultsDot, conf.threadSplit.value, conf.summariseProcedures.value)) else None,
87+
staticAnalysis = if conf.analyse.value then Some(StaticAnalysisConfig(conf.dumpIL, conf.analysisResults, conf.analysisResultsDot, conf.threadSplit.value, conf.summariseProcedures.value, conf.memoryRegions.value)) else None,
8688
boogieTranslation = BoogieGeneratorConfig(if conf.lambdaStores.value then BoogieMemoryAccessMode.LambdaStoreSelect else BoogieMemoryAccessMode.SuccessiveStoreSelect,
8789
true, rely, conf.threadSplit.value),
8890
outputPrefix = conf.outFileName,

src/main/scala/analysis/Analysis.scala

+36-37
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ trait ConstantPropagation(val program: Program) {
3232

3333
/** Default implementation of eval.
3434
*/
35-
def eval(exp: Expr, env: Map[Variable, FlatElement[BitVecLiteral]]): FlatElement[BitVecLiteral] =
35+
def eval(exp: Expr, env: Map[Variable, FlatElement[BitVecLiteral]]): FlatElement[BitVecLiteral] = {
3636
import valuelattice._
37-
exp match
37+
exp match {
3838
case id: Variable => env(id)
3939
case n: BitVecLiteral => bv(n)
4040
case ze: ZeroExtend => zero_extend(ze.extension, eval(ze.body, env))
@@ -43,7 +43,7 @@ trait ConstantPropagation(val program: Program) {
4343
case bin: BinaryExpr =>
4444
val left = eval(bin.arg1, env)
4545
val right = eval(bin.arg2, env)
46-
bin.op match
46+
bin.op match {
4747
case BVADD => bvadd(left, right)
4848
case BVSUB => bvsub(left, right)
4949
case BVMUL => bvmul(left, right)
@@ -63,28 +63,29 @@ trait ConstantPropagation(val program: Program) {
6363
case BVASHR => bvashr(left, right)
6464
case BVCOMP => bvcomp(left, right)
6565
case BVCONCAT => concat(left, right)
66-
66+
}
6767
case un: UnaryExpr =>
6868
val arg = eval(un.arg, env)
69-
70-
un.op match
69+
un.op match {
7170
case BVNOT => bvnot(arg)
7271
case BVNEG => bvneg(arg)
73-
72+
}
7473
case _ => valuelattice.top
74+
}
75+
}
76+
7577

7678
/** Transfer function for state lattice elements.
7779
*/
78-
def localTransfer(n: CFGPosition, s: Map[Variable, FlatElement[BitVecLiteral]]): Map[Variable, FlatElement[BitVecLiteral]] =
79-
n match
80-
case r: Command =>
81-
r match
82-
// assignments
83-
case la: Assign =>
84-
s + (la.lhs -> eval(la.rhs, s))
85-
// all others: like no-ops
86-
case _ => s
80+
def localTransfer(n: CFGPosition, s: Map[Variable, FlatElement[BitVecLiteral]]): Map[Variable, FlatElement[BitVecLiteral]] = {
81+
n match {
82+
// assignments
83+
case la: Assign =>
84+
s + (la.lhs -> eval(la.rhs, s))
85+
// all others: like no-ops
8786
case _ => s
87+
}
88+
}
8889

8990
/** The analysis lattice.
9091
*/
@@ -99,9 +100,10 @@ trait ConstantPropagation(val program: Program) {
99100

100101
class ConstantPropagationSolver(program: Program) extends ConstantPropagation(program)
101102
with SimplePushDownWorklistFixpointSolver[CFGPosition, Map[Variable, FlatElement[BitVecLiteral]], MapLattice[Variable, FlatElement[BitVecLiteral], ConstantPropagationLattice]]
102-
with IRIntraproceduralForwardDependencies
103+
with IRInterproceduralForwardDependencies
103104
with Analysis[Map[CFGPosition, Map[Variable, FlatElement[BitVecLiteral]]]]
104105

106+
105107
/** Base class for value analysis with simple (non-lifted) lattice.
106108
*/
107109
trait ConstantPropagationWithSSA(val program: Program, val reachingDefs: Map[CFGPosition, (Map[Variable, Set[Assign]], Map[Variable, Set[Assign]])]) {
@@ -114,9 +116,9 @@ trait ConstantPropagationWithSSA(val program: Program, val reachingDefs: Map[CFG
114116

115117
/** Default implementation of eval.
116118
*/
117-
def eval(exp: Expr, env: Map[RegisterWrapperEqualSets, Set[BitVecLiteral]], n: CFGPosition): Set[BitVecLiteral] =
119+
def eval(exp: Expr, env: Map[RegisterWrapperEqualSets, Set[BitVecLiteral]], n: CFGPosition): Set[BitVecLiteral] = {
118120
import valuelattice._
119-
exp match
121+
exp match {
120122
case id: Variable => env(RegisterWrapperEqualSets(id, getUse(id, n, reachingDefs)))
121123
case n: BitVecLiteral => bv(n)
122124
case ze: ZeroExtend => zero_extend(ze.extension, eval(ze.body, env, n))
@@ -125,7 +127,7 @@ trait ConstantPropagationWithSSA(val program: Program, val reachingDefs: Map[CFG
125127
case bin: BinaryExpr =>
126128
val left = eval(bin.arg1, env, n)
127129
val right = eval(bin.arg2, env, n)
128-
bin.op match
130+
bin.op match {
129131
case BVADD => bvadd(left, right)
130132
case BVSUB => bvsub(left, right)
131133
case BVMUL => bvmul(left, right)
@@ -145,34 +147,31 @@ trait ConstantPropagationWithSSA(val program: Program, val reachingDefs: Map[CFG
145147
case BVASHR => bvashr(left, right)
146148
case BVCOMP => bvcomp(left, right)
147149
case BVCONCAT => concat(left, right)
150+
}
148151

149152
case un: UnaryExpr =>
150153
val arg = eval(un.arg, env, n)
151-
152-
un.op match
154+
un.op match {
153155
case BVNOT => bvnot(arg)
154156
case BVNEG => bvneg(arg)
157+
}
155158

156159
case _ => Set.empty
160+
}
161+
}
157162

158163
/** Transfer function for state lattice elements.
159164
*/
160165
def localTransfer(n: CFGPosition, s: Map[RegisterWrapperEqualSets, Set[BitVecLiteral]]): Map[RegisterWrapperEqualSets, Set[BitVecLiteral]] =
161166
n match {
162-
case r: Command =>
163-
r match {
164-
// assignments
165-
case a: Assign =>
166-
val lhsWrappers = s.collect {
167-
case (k, v) if RegisterVariableWrapper(k.variable, k.assigns) == RegisterVariableWrapper(a.lhs, getDefinition(a.lhs, r, reachingDefs)) => (k, v)
168-
}
169-
if (lhsWrappers.nonEmpty) {
170-
s ++ lhsWrappers.map((k, v) => (k, v.union(eval(a.rhs, s, r))))
171-
} else {
172-
s + (RegisterWrapperEqualSets(a.lhs, getDefinition(a.lhs, r, reachingDefs)) -> eval(a.rhs, s, n))
173-
}
174-
// all others: like no-ops
175-
case _ => s
167+
case a: Assign =>
168+
val lhsWrappers = s.collect {
169+
case (k, v) if RegisterVariableWrapper(k.variable, k.assigns) == RegisterVariableWrapper(a.lhs, getDefinition(a.lhs, a, reachingDefs)) => (k, v)
170+
}
171+
if (lhsWrappers.nonEmpty) {
172+
s ++ lhsWrappers.map((k, v) => (k, v.union(eval(a.rhs, s, a))))
173+
} else {
174+
s + (RegisterWrapperEqualSets(a.lhs, getDefinition(a.lhs, a, reachingDefs)) -> eval(a.rhs, s, n))
176175
}
177176
case _ => s
178177
}
@@ -190,5 +189,5 @@ trait ConstantPropagationWithSSA(val program: Program, val reachingDefs: Map[CFG
190189

191190
class ConstantPropagationSolverWithSSA(program: Program, reachingDefs: Map[CFGPosition, (Map[Variable, Set[Assign]], Map[Variable, Set[Assign]])]) extends ConstantPropagationWithSSA(program, reachingDefs)
192191
with SimplePushDownWorklistFixpointSolver[CFGPosition, Map[RegisterWrapperEqualSets, Set[BitVecLiteral]], MapLattice[RegisterWrapperEqualSets, Set[BitVecLiteral], ConstantPropagationLatticeWithSSA]]
193-
with IRIntraproceduralForwardDependencies
192+
with IRInterproceduralForwardDependencies
194193
with Analysis[Map[CFGPosition, Map[RegisterWrapperEqualSets, Set[BitVecLiteral]]]]

src/main/scala/analysis/BitVectorEval.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package analysis
2-
import ir._
2+
import ir.*
33
import analysis.BitVectorEval.*
44

5+
import scala.annotation.tailrec
56
import scala.math.pow
67

78
object BitVectorEval {
@@ -337,5 +338,4 @@ object BitVectorEval {
337338
smt_zero_extend(i, s)
338339
}
339340
}
340-
341341
}

0 commit comments

Comments
 (0)