Skip to content

Commit

Permalink
Fix use of old context-based constructor. (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Oct 25, 2023
1 parent 341890b commit ea9cee8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/interop/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Create an LLVM function, given its return type `rettyp` and a vector of argument
`argtyp`. The function is marked for inlining, to be embedded in the caller's body.
Returns both the newly created function, and its type.
"""
function create_function(rettyp::LLVMType=LLVM.VoidType(Context()),
function create_function(rettyp::LLVMType=LLVM.VoidType(),
argtyp::Vector{<:LLVMType}=LLVMType[],
name::String="entry")
mod = LLVM.Module("llvmcall")
Expand Down
43 changes: 39 additions & 4 deletions test/interop_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,43 @@ end

@testset "base" begin

@generated function add_one(i)
@generated function foo()
@dispose ctx=Context() begin
f, ft = create_function()

@dispose builder=IRBuilder() begin
entry = BasicBlock(f, "entry")
position!(builder, entry)

ret!(builder)
end

call_function(f, Nothing, Tuple{})
end
end
@test foo() === nothing

@generated function bar()
@dispose ctx=Context() begin
T_int = convert(LLVMType, Int)

f, ft = create_function(T_int)

@dispose builder=IRBuilder() begin
entry = BasicBlock(f, "entry")
position!(builder, entry)

val = ConstantInt(T_int, 42)

ret!(builder, val)
end

call_function(f, Int, Tuple{})
end
end
@test bar() == 42

@generated function baz(i)
@dispose ctx=Context() begin
T_int = convert(LLVMType, Int)

Expand All @@ -21,16 +57,15 @@ end
entry = BasicBlock(f, "entry")
position!(builder, entry)

val = add!(builder, parameters(f)[1], ConstantInt(T_int, 1))
val = add!(builder, parameters(f)[1], ConstantInt(T_int, 42))

ret!(builder, val)
end

call_function(f, Int, Tuple{Int}, :i)
end
end

@test add_one(1) == 2
@test baz(1) == 43

@eval struct GhostType end
@eval struct NonGhostType1
Expand Down

0 comments on commit ea9cee8

Please sign in to comment.