-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in compiling llvmcall
with tuple argument for declarations and IR.
#26297
Comments
I came across this for MWE: module Test1
const libpython = "/usr/lib/libpython3.6m"
struct OpaqueStruct end
macro pyglobalobj1(name)
:(cglobal(($(esc(name)), libpython), OpaqueStruct))
end
macro pyglobalobj2(name)
:(cglobal(($(esc(name)), $libpython), OpaqueStruct))
end
f1() = @pyglobalobj1(:PyRange_Type)
f2() = @pyglobalobj2(:PyRange_Type)
end
@code_typed Test1.f1()
@code_typed Test1.f2()
Test1.f1()
Test1.f2() On master: julia> @code_typed Test1.f1()
CodeInfo(:(begin
Core.SSAValue(0) = (Core.tuple)(:PyRange_Type, Main.Test1.libpython)::Tuple{Symbol,String}
Core.SSAValue(1) = (Main.Test1.cglobal)(Core.SSAValue(0), Main.Test1.OpaqueStruct)::Ptr{Main.Test1.OpaqueStruct}
return Core.SSAValue(1)
end)) => Ptr{Main.Test1.OpaqueStruct}
julia> @code_typed Test1.f2()
CodeInfo(:(begin
Core.SSAValue(0) = (Core.tuple)(:PyRange_Type, "/usr/lib/libpython3.6m")::Tuple{Symbol,String}
Core.SSAValue(1) = (Main.Test1.cglobal)(Core.SSAValue(0), Main.Test1.OpaqueStruct)::Ptr{Main.Test1.OpaqueStruct}
return Core.SSAValue(1)
end)) => Ptr{Main.Test1.OpaqueStruct}
julia> Test1.f1()
ERROR: TypeError: in f1, in cglobal: first argument not a pointer or valid constant expression, expected Ptr, got Tuple{Symbol,String}
Stacktrace:
[1] f1() at ./REPL[43]:14
[2] top-level scope
julia> Test1.f2()
ERROR: TypeError: in f2, in cglobal: first argument not a pointer or valid constant expression, expected Ptr, got Tuple{Symbol,String}
Stacktrace:
[1] f2() at ./REPL[43]:15
[2] top-level scope On v0.6.2: julia> @code_typed Test1.f1()
CodeInfo(:(begin
return (Test1.cglobal)((Core.tuple)(:PyRange_Type, Test1.libpython)::Tuple{Symbol,String}, Test1.OpaqueStruct)::Ptr{Test1.OpaqueStruct}
end))=>Ptr{Test1.OpaqueStruct}
julia> @code_typed Test1.f2()
CodeInfo(:(begin
return (Test1.cglobal)((Core.tuple)(:PyRange_Type, "/usr/lib/libpython3.6m")::Tuple{Symbol,String}, Test1.OpaqueStruct)::Ptr{Test1.OpaqueStruct}
end))=>Ptr{Test1.OpaqueStruct}
julia> Test1.f1()
Ptr{Test1.OpaqueStruct} @0x00007f1fb13a0460
julia> Test1.f2()
Ptr{Test1.OpaqueStruct} @0x00007f1fb13a0460 |
FWIW, the following works around the bug:
|
Mostly straightforward, but note that (probably due to JuliaLang/julia#26297), llvmcall has to be imported from Base in order to avoid the error 'error compiling assume: error statically evaluating llvm IR argument'. Also note that cfunction calls have been replaced with ccalls to jl_function_ptr, while they should probably be replaced with cfunction macro calls. The problem is however that the cfunction macro expects a literal tuple for the argument types.
I also ran into this issue with FunctionWrappers. @chethega's workaround worked there as well (unfortunately I didn't find this issue initially and trial-and-errored my way to the same solution). Here's the error message from FunctionWrappers for better searchability: ERROR: error compiling assume: error statically evaluating llvm IR argument |
#28172 fixed the FunctionWrappers error, as well as the example in the issue description. Close? |
Probably related to linear IR and #25041, but since we actually have tests for it
julia/test/llvmcall.jl
Lines 127 to 134 in df489f0
I was surprised recently by triggering this in the REPL and when loading code with
-L
.This can be worked around by using a
@generated
functioncc: @quinnj
The text was updated successfully, but these errors were encountered: