Skip to content

Commit 8f45912

Browse files
branch in brtable
1 parent 319cfd6 commit 8f45912

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(module $brtable
2+
(global (;0;) (mut i32) (i32.const 1048576))
3+
(type (;0;) (func (param i32)))
4+
(func (;0;) (type 1) (result i32)
5+
i32.const 2
6+
(block
7+
(block
8+
(block
9+
i32.const 0
10+
i32.symbolic
11+
br_table 0 1 2 0 ;; br_table will consume an element from the stack
12+
)
13+
i32.const 1
14+
call 1
15+
br 1
16+
)
17+
i32.const 0
18+
call 1
19+
)
20+
)
21+
(import "console" "assert" (func (type 0)))
22+
(start 0))

headers/wasm/smt_solver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Solver {
4646
if (id >= result.size()) {
4747
result.resize(id + 1);
4848
}
49-
result[id] = Num(value.get_numeral_int());
49+
result[id] = Num(value.get_numeral_int64());
5050
} else {
5151
std::cout << "Find a variable that is not created by GenSym: " << name
5252
<< std::endl;

src/main/scala/wasm/StagedConcolicMiniWasm.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import gensym.wasm.symbolic.{SymVal}
1717
import gensym.lmsx.{SAIDriver, StringOps, SAIOps, SAICodeGenBase, CppSAIDriver, CppSAICodeGenBase}
1818
import gensym.wasm.symbolic.Concrete
1919
import gensym.wasm.symbolic.ExploreTree
20+
import gensym.structure.freer.Explore
2021

2122
@virtualize
2223
trait StagedWasmEvaluator extends SAIOps {
@@ -270,12 +271,20 @@ trait StagedWasmEvaluator extends SAIOps {
270271
}
271272
()
272273
case BrTable(labels, default) =>
273-
val (cond, newCtx) = Stack.pop()
274+
val (label, newCtx) = Stack.pop()
274275
def aux(choices: List[Int], idx: Int): Rep[Unit] = {
275276
if (choices.isEmpty) trail(default)(newCtx)(mkont)
276277
else {
277-
if (cond.toInt == idx) trail(choices.head)(newCtx)(mkont)
278-
else aux(choices.tail, idx + 1)
278+
val cond = (label - toStagedNum(I32V(idx))).isZero()
279+
ExploreTree.fillWithIfElse(cond.s)
280+
if (cond.toInt != 0) {
281+
ExploreTree.moveCursor(true)
282+
trail(choices.head)(newCtx)(mkont)
283+
}
284+
else {
285+
ExploreTree.moveCursor(false)
286+
aux(choices.tail, idx + 1)
287+
}
279288
}
280289
}
281290
aux(labels, 0)
@@ -959,6 +968,8 @@ trait StagedWasmCppGen extends CGenBase with CppSAICodeGenBase {
959968
shallow(lhs); emit(" >= "); shallow(rhs)
960969
case Node(_, "sym-binary-add", List(lhs, rhs), _) =>
961970
shallow(lhs); emit(".add("); shallow(rhs); emit(")")
971+
case Node(_, "sym-binary-sub", List(lhs, rhs), _) =>
972+
shallow(lhs); emit(".minus("); shallow(rhs); emit(")")
962973
case Node(_, "sym-binary-mul", List(lhs, rhs), _) =>
963974
shallow(lhs); emit(".mul("); shallow(rhs); emit(")")
964975
case Node(_, "sym-binary-div", List(lhs, rhs), _) =>

src/test/scala/genwasym/TestStagedConcolicEval.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ class TestStagedConcolicEval extends FunSuite {
3535
test("bug-finding") {
3636
testFileToCpp("./benchmarks/wasm/branch-strip-buggy.wat", Some("real_main"))
3737
}
38+
39+
test("brtable-bug-finding") {
40+
testFileToCpp("./benchmarks/wasm/staged/brtable_concolic.wat")
41+
}
3842
}

0 commit comments

Comments
 (0)