Skip to content

Commit 7f0cdd7

Browse files
committed
adds more testcases
1 parent de9a710 commit 7f0cdd7

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: veir-interpret %s | filecheck %s
2+
3+
// The interpreter starts with an empty entropy source, so `io.rand` is UB.
4+
5+
"builtin.module"() ({
6+
"func.func"() <{sym_name = "main", function_type = () -> i64}> ({
7+
%len = "llvm.mlir.constant"() <{value = 4 : i64}> : () -> i64
8+
%buf = "llvm.alloca"(%len) <{elem_type = i8}> : (i64) -> !llvm.ptr
9+
%n = "io.rand"(%buf, %len) : (!llvm.ptr, i64) -> i64
10+
// CHECK: Undefined behavior
11+
"func.return"(%n) : (i64) -> ()
12+
}) : () -> ()
13+
}) : () -> ()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: veir-interpret %s | filecheck %s
2+
3+
// Receiving with nothing in flight reports `Io.Error.exhausted` (-2); the
4+
// sender result is unspecified and the interpreter returns address 0.
5+
6+
"builtin.module"() ({
7+
"func.func"() <{sym_name = "main", function_type = () -> (i64, !io.address)}> ({
8+
%len = "llvm.mlir.constant"() <{value = 4 : i64}> : () -> i64
9+
%buf = "llvm.alloca"(%len) <{elem_type = i8}> : (i64) -> !llvm.ptr
10+
%n, %from = "io.recv"(%buf, %len) : (!llvm.ptr, i64) -> (i64, !io.address)
11+
"func.return"(%n, %from) : (i64, !io.address) -> ()
12+
}) : () -> ()
13+
}) : () -> ()
14+
15+
// CHECK: Program output: #[0xfffffffffffffffe#64, ioAddr(0)]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: veir-interpret %s | filecheck %s
2+
3+
// A 4-byte message received into a 2-byte window reports
4+
// `Io.Error.messageTooLong` (-3), leaves the buffer untouched, and stays in
5+
// flight, so a retry with the full length succeeds with 4 bytes.
6+
7+
"builtin.module"() ({
8+
"func.func"() <{sym_name = "main", function_type = () -> (i64, i32, i64, i32)}> ({
9+
%self = "io.self"() : () -> !io.address
10+
%len = "llvm.mlir.constant"() <{value = 4 : i64}> : () -> i64
11+
%short = "llvm.mlir.constant"() <{value = 2 : i64}> : () -> i64
12+
%buf = "llvm.alloca"(%len) <{elem_type = i8}> : (i64) -> !llvm.ptr
13+
%abcd = "llvm.mlir.constant"() <{value = 1684234849 : i32}> : () -> i32
14+
"llvm.store"(%abcd, %buf) : (i32, !llvm.ptr) -> ()
15+
%sent = "io.send"(%self, %buf, %len) : (!io.address, !llvm.ptr, i64) -> i64
16+
%zero = "llvm.mlir.constant"() <{value = 0 : i32}> : () -> i32
17+
"llvm.store"(%zero, %buf) : (i32, !llvm.ptr) -> ()
18+
%n1, %from1 = "io.recv"(%buf, %short) : (!llvm.ptr, i64) -> (i64, !io.address)
19+
%w1 = "llvm.load"(%buf) : (!llvm.ptr) -> i32
20+
%n2, %from2 = "io.recv"(%buf, %len) : (!llvm.ptr, i64) -> (i64, !io.address)
21+
%w2 = "llvm.load"(%buf) : (!llvm.ptr) -> i32
22+
"func.return"(%n1, %w1, %n2, %w2) : (i64, i32, i64, i32) -> ()
23+
}) : () -> ()
24+
}) : () -> ()
25+
26+
// CHECK: Program output: #[0xfffffffffffffffd#64, 0x00000000#32, 0x0000000000000004#64, 0x64636261#32]

0 commit comments

Comments
 (0)