Skip to content

Commit 04cce56

Browse files
committed
Add tests for bounds check elimination.
1 parent a6f6519 commit 04cce56

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

test/boundscheck.jl

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
module TestBoundsCheck
3+
4+
using Base.Test
5+
6+
# test for boundscheck block elision at same level
7+
function A1_inbounds()
8+
r = 0
9+
@inbounds begin
10+
@boundscheck r += 1
11+
end
12+
return r
13+
end
14+
15+
function A1()
16+
r = 0
17+
@boundscheck r += 1
18+
return r
19+
end
20+
21+
@test A1() == 1
22+
@test A1_inbounds() == 0
23+
24+
# test for boundscheck block elision one layer deep
25+
function A2_inbounds()
26+
@inbounds r = A1()+1
27+
return r
28+
end
29+
30+
function A2()
31+
r = A1()+1
32+
return r
33+
end
34+
35+
@test A2() == 2
36+
@test A2_inbounds() == 1
37+
38+
# test boundscheck NOT elided two layers deep
39+
# C() = (y=0; @boundscheck y += A1()+1; return y)
40+
B() = A1() + 1
41+
42+
function A3_inbounds()
43+
@inbounds r = B()+1
44+
return r
45+
end
46+
47+
function A3()
48+
r = B()+1
49+
return r
50+
end
51+
52+
@test A3() == 3
53+
@test A3_inbounds() == 3
54+
55+
end

test/choosetests.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ function choosetests(choices = [])
3232
"nullable", "meta", "profile", "libgit2", "docs", "markdown",
3333
"base64", "serialize", "functors", "misc", "threads",
3434
"enums", "cmdlineargs", "i18n", "workspace", "libdl", "int",
35-
"checked", "intset", "floatfuncs", "compile", "parallel", "inline"
35+
"checked", "intset", "floatfuncs", "compile", "parallel", "inline",
36+
"boundscheck"
3637
]
3738

3839
if Base.USE_GPL_LIBS

0 commit comments

Comments
 (0)