From 04cce56512f671522b4fac1fa83437f3fc3f7719 Mon Sep 17 00:00:00 2001 From: Blake Johnson Date: Wed, 23 Dec 2015 21:35:20 -0500 Subject: [PATCH] Add tests for bounds check elimination. --- test/boundscheck.jl | 55 +++++++++++++++++++++++++++++++++++++++++++++ test/choosetests.jl | 3 ++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/boundscheck.jl diff --git a/test/boundscheck.jl b/test/boundscheck.jl new file mode 100644 index 0000000000000..9633be9e97629 --- /dev/null +++ b/test/boundscheck.jl @@ -0,0 +1,55 @@ + +module TestBoundsCheck + +using Base.Test + +# test for boundscheck block elision at same level +function A1_inbounds() + r = 0 + @inbounds begin + @boundscheck r += 1 + end + return r +end + +function A1() + r = 0 + @boundscheck r += 1 + return r +end + +@test A1() == 1 +@test A1_inbounds() == 0 + +# test for boundscheck block elision one layer deep +function A2_inbounds() + @inbounds r = A1()+1 + return r +end + +function A2() + r = A1()+1 + return r +end + +@test A2() == 2 +@test A2_inbounds() == 1 + +# test boundscheck NOT elided two layers deep +# C() = (y=0; @boundscheck y += A1()+1; return y) +B() = A1() + 1 + +function A3_inbounds() + @inbounds r = B()+1 + return r +end + +function A3() + r = B()+1 + return r +end + +@test A3() == 3 +@test A3_inbounds() == 3 + +end \ No newline at end of file diff --git a/test/choosetests.jl b/test/choosetests.jl index f485972243497..b9346a96758ee 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -32,7 +32,8 @@ function choosetests(choices = []) "nullable", "meta", "profile", "libgit2", "docs", "markdown", "base64", "serialize", "functors", "misc", "threads", "enums", "cmdlineargs", "i18n", "workspace", "libdl", "int", - "checked", "intset", "floatfuncs", "compile", "parallel", "inline" + "checked", "intset", "floatfuncs", "compile", "parallel", "inline", + "boundscheck" ] if Base.USE_GPL_LIBS