JuliaLang/julia

`llvmcall` segfaults if an argument has size 0

已關閉

#60,063 建立於 2025年11月6日

 (6 則留言) (0 個反應) (0 位負責人)Julia (5,773 個分叉)batch import
compiler:codegencompiler:llvmgood first issue

倉庫指標

星標
 (48,709 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

llvmcall catches incorrect argument types, but it doesn't catch arguments with empty bit representation (which are presumably not allowed in LLVM IR). I think it would be better if llvmcall threw an error in this case.

julia> f(x::T) where T = Base.llvmcall("ret i8 %0", Int8, Tuple{T}, x);

julia> f(1)
ERROR: Failed to parse LLVM assembly: 
<string>:2:8: error: '%0' defined with type 'i64' but expected 'i8'
ret i8 %0
       ^

julia> f(nothing)

[26746] signal 11 (1): Segmentation fault
in expression starting at REPL[3]:1
llvm_type_rewrite at /cache/build/tester-amdci4-14/julialang/julia-release-1-dot-12/src/ccall.cpp:407
emit_llvmcall at /cache/build/tester-amdci4-14/julialang/julia-release-1-dot-12/src/ccall.cpp:826
emit_intrinsic at /cache/build/tester-amdci4-14/julialang/julia-release-1-dot-12/src/intrinsics.cpp:1307
emit_call at /cache/build/tester-amdci4-14/julialang/julia-release-1-dot-12/src/codegen.cpp:5456
emit_expr at /cache/build/tester-amdci4-14/julialang/julia-release-1-dot-12/src/codegen.cpp:6383
emit_ssaval_assign at /cache/build/tester-amdci4-14/julialang/julia-release-1-dot-12/src/codegen.cpp:5870
emit_stmtpos at /cache/build/tester-amdci4-14/julialang/julia-release-1-dot-12/src/codegen.cpp:6172 [inlined]
emit_function at /cache/build/tester-amdci4-14/julialang/julia-release-1-dot-12/src/codegen.cpp:9347
[...]

Tested with Julia 1.12. Same with a few days old 1.13-nightly.

julia> versioninfo()
Julia Version 1.12.1
Commit ba1e628ee49 (2025-10-17 13:02 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-18.1.7 (ORCJIT, skylake)
  GC: Built with stock GC

貢獻者指南