Skip to content

Commit e303af8

Browse files
bors[bot]vchuravy
andauthored
Merge #228
228: overdub overflowerr_binaryop (#227) r=vchuravy a=vchuravy Co-authored-by: Valentin Churavy <[email protected]>
2 parents cb47e08 + 1d8e902 commit e303af8

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/compiler.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,14 @@ function generate_overdubs(mod, Ctx)
6262
end
6363

6464
@inline Cassette.overdub(::$Ctx, ::typeof(Base.literal_pow), f::F, x, p) where F = Base.literal_pow(f, x, p)
65+
66+
if VERSION >= v"1.5"
67+
@inline function Cassette.overdub(::$Ctx, ::typeof(Base.Checked.throw_overflowerr_binaryop), op, x, y)
68+
throw(OverflowError("checked arithmetic: cannot compute"))
69+
end
70+
@inline function Cassette.overdub(::$Ctx, ::typeof(Base.Checked.throw_overflowerr_negation), x)
71+
throw(OverflowError("checked arithmetic: cannot compute -x"))
72+
end
73+
end
6574
end
6675
end

test/compiler.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,26 @@ end
1212
A[1] = 2^11
1313
end
1414

15+
@kernel function checked(A, a, b)
16+
A[1] = Base.Checked.checked_add(a, b)
17+
end
18+
1519
function compiler_testsuite()
1620
kernel = index(CPU(), DynamicSize(), DynamicSize())
1721
iterspace = NDRange{1, StaticSize{(128,)}, StaticSize{(8,)}}();
1822
ctx = KernelAbstractions.mkcontext(kernel, 1, nothing, iterspace, Val(KernelAbstractions.NoDynamicCheck()))
1923

2024
@test KernelAbstractions.Cassette.overdub(ctx, KernelAbstractions.__index_Global_NTuple, CartesianIndex(1)) == (1,)
2125

22-
CI, rt = @ka_code_typed literal_pow(CPU())(zeros(Int,1), ndrange=1)
23-
# test that there is no invoke of overdub
24-
@test !any(stmt->(stmt isa Expr) && stmt.head == :invoke, CI.code)
25-
end
26+
let (CI, rt) = @ka_code_typed literal_pow(CPU())(zeros(Int,1), ndrange=1)
27+
# test that there is no invoke of overdub
28+
@test !any(stmt->(stmt isa Expr) && stmt.head == :invoke, CI.code)
29+
end
2630

31+
if VERSION >= v"1.5"
32+
let (CI, rt) = @ka_code_typed checked(CPU())(zeros(Int,1), 1, 2, ndrange=1)
33+
# test that there is no invoke of overdub
34+
@test !any(stmt->(stmt isa Expr) && stmt.head == :invoke, CI.code)
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)