From ea9cee8873e1af24e04636fe40e36a9c98ab5890 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 25 Oct 2023 10:50:31 +0200 Subject: [PATCH] Fix use of old context-based constructor. (#372) --- src/interop/base.jl | 2 +- test/interop_tests.jl | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/interop/base.jl b/src/interop/base.jl index 3f5445d6..1fbb345d 100644 --- a/src/interop/base.jl +++ b/src/interop/base.jl @@ -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") diff --git a/test/interop_tests.jl b/test/interop_tests.jl index 102d22a4..107a8906 100644 --- a/test/interop_tests.jl +++ b/test/interop_tests.jl @@ -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) @@ -21,7 +57,7 @@ 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 @@ -29,8 +65,7 @@ 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