julia icon indicating copy to clipboard operation
julia copied to clipboard

regression in 1.13.0-alpha2: `ccall` errors if the function name is a `const` string

Open matthias314 opened this issue 3 weeks ago • 4 comments

This works in Julia 1.12.2 (provided that you have an x86 processor with BMI extension, of course):

julia> const llvm_pext = "llvm.x86.bmi.pext.64";

julia> pext(x::UInt64, y::UInt64) = ccall(llvm_pext, llvmcall, UInt64, (UInt64, UInt64), x, y);

julia> pext(UInt64(1), UInt64(1))
0x0000000000000001

Julia 1.13.0-alpha2 seems to require a literal string:

julia> pext(UInt64(1), UInt64(1))
ERROR: TypeError: in ccall: first argument not a pointer or valid constant expression, expected Ptr, got a value of type String

julia> pext2(x::UInt64, y::UInt64) = ccall("llvm.x86.bmi.pext.64", llvmcall, UInt64, (UInt64, UInt64), x, y);

julia> pext2(UInt64(1), UInt64(1))
0x0000000000000001
Julia Version 1.13.0-alpha2
Commit 7f76b76527d (2025-11-30 19:52 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × Intel(R) Core(TM) i3-10110U CPU @ 2.10GHz
  WORD_SIZE: 64
  LLVM: libLLVM-20.1.8 (ORCJIT, skylake)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 4 virtual cores)

matthias314 avatar Dec 03 '25 01:12 matthias314

I imagine this was changed by https://github.com/JuliaLang/julia/pull/59165, and since it's tagged minor change it also seems the difference in behavior is intentional. I did not really follow neither the motivation for the PR nor its implementation though so I can't say much more of use.

adienes avatar Dec 03 '25 03:12 adienes

Could you add a suitable label to this issue? Maybe that catches the attention of someone who can say more about this.

matthias314 avatar Dec 06 '25 16:12 matthias314

Ping @vtjnash

lgoettgens avatar Dec 06 '25 16:12 lgoettgens

I'm not sure what more you want. Putting something else there has always been ill-defined behavior. We now document exactly which forms are supported and how they are defined. Now that const-redefinition is formally defined, we felt it was time to put a formal standard around what is actually allowed there and what is not (and is a mandatory step towards having an accurate and functioning JuliaInterpreter / Revise implementation)

The simplest fix though is simply to write ccall((name,), llvmcall, UInt64, (UInt64, UInt64), x, y) now instead, since the extra (,) there have always instructed it to treat name as a name instead of a pointer.

vtjnash avatar Dec 06 '25 19:12 vtjnash