Skip to content

Sanitize linkage names that aren't valid C identifiers - #28

Merged
maleadt merged 1 commit into
mainfrom
tb/sanitize-linkage-names
Oct 24, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/sanitize-linkage-names

Conversation

@maleadt

@maleadt maleadt commented Oct 23, 2026

Copy link
Copy Markdown
Member

LLVM's SPIR-V back-end lowers funnel shifts (llvm.fshl/llvm.fshr) into helper functions with exported linkage names like spirv.llvm_fshl_i64. Linkage names were used verbatim as C identifiers, so the translation contained ulong spirv.llvm_fshl_i64(...) and failed to compile. This breaks OpenCL.jl's OpenCL C source path for any kernel that rotates an integer (e.g. bitrotate, or the hashing in GPUArrays' findfirst and reductions), and is what fails OpenCL.jl's poclc tests on JuliaGPU/GPUCompiler.jl#1027.

A linkage name that isn't a valid identifier can't be kept, so it is now sanitized like an OpName (spirv_llvm_fshl_i64). That happens after all names that are kept verbatim have been reserved, so a sanitized name can't take one of them. Entry-point names are left alone, since kernels are looked up by them.

With this, the failing OpenCL.jl testsets (gpuarrays/reductions/sum prod, == isequal and indexing find on PoCL's source path) pass with GPUCompiler.jl#1027.

Linkage names were reserved verbatim, so an exported function named like
LLVM's SPIR-V back-end helpers ("spirv.llvm_fshl_i64", emitted for funnel
shifts) produced uncompilable OpenCL C. Such a name can't be kept anyway, so
sanitize it like an OpName, after all names that are kept verbatim have been
reserved so that it can't take one of them.
@maleadt
maleadt merged commit 3b2835e into main Oct 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant