Skip to content

Commit 2dbbd02

Browse files
committed
Box arguments to funs if types don't match
1 parent f2052fb commit 2dbbd02

2 files changed

Lines changed: 10 additions & 22 deletions

File tree

src/codegens.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function codegen!(cg::CodeCtx)
9393
if !has_terminator(entry)
9494
LLVM.unreachable!(cg.builder)
9595
end
96-
# LLVM.verify(cg.func)
96+
LLVM.verify(cg.func)
9797
LLVM.dispose(cg.builder)
9898
return cg.mod
9999
end
@@ -255,8 +255,12 @@ function codegen!(cg::CodeCtx, ::Val{:invoke}, args, typ)
255255
end
256256
llvmargs = LLVM.Value[]
257257
startpos = isa(args[1], Core.MethodInstance) ? 3 : 2
258-
for v in args[startpos:end]
259-
push!(llvmargs, codegen!(cg, v))
258+
for (i,v) in enumerate(args[startpos:end])
259+
a = codegen!(cg, v)
260+
if llvmtype(argtypes.parameters[i]) != LLVM.llvmtype(a) # kludgey?
261+
a = emit_box!(cg, v)
262+
end
263+
push!(llvmargs, a)
260264
end
261265
return LLVM.call!(cg.builder, func, llvmargs)
262266
end

test/broken.jl

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,10 @@ using MicroLogging
88
configure_logging(min_level=:info)
99
configure_logging(min_level=:debug)
1010

11-
m = codegen(Base.throw_inexacterror,Tuple{Symbol,Type{Int32},Int32})
12-
verify(m)
13-
14-
# basedump(Base.throw_inexacterror,Tuple{Symbol,Type{Int32},Int32})
15-
16-
# function test_arrays(x)
17-
# y = fill(2pi, 5)
18-
# push!(y, 3x)
19-
# z = reverse(y)
20-
# zz = y .+ z.^2
21-
# return maximum(zz)
22-
# end
23-
# m = codegen(test_arrays, Tuple{Int})
24-
# verify(m)
2511

26-
27-
28-
# f(x) = string("a", x)
29-
# m = codegen(f, Tuple{Int})
30-
# verify(m)
12+
f(x) = string("a", x)
13+
m = codegen(f, Tuple{Int})
14+
verify(m)
3115

3216

3317

0 commit comments

Comments
 (0)