llvm: sync complete upstream LLVM 22 support - #5
Conversation
This matches TinyGo, where they are merged. It should make maintenance a little bit easier, and also makes it easier to add new OSes (like FreeBSD) without having to create a whole new set of files.
add ExecutionEngine.GetFunctionAddress()
We still haven't updated TinyGo, so this change is needed so we can use tinygo-org#73 in TinyGo.
* Add LLVM 22 build support Written entirely by Claude (Anthropic's Claude Code), at the request of and under the direction of dgryski, as part of a broader effort to get TinyGo building against upcoming LLVM releases. Adds the llvm22 build-tag config file (mirroring the existing llvm21 one) and a CI matrix entry for it. Also adds a regression test confirming that LLVM 21+'s 'captures' parameter attribute (which replaced the boolean 'nocapture' enum attribute) round-trips correctly through the existing generic enum-attribute API, with value 0 corresponding to captures(none) -- no binding/C++ shim changes were needed for this, since 'captures' is an IntAttr using the same wire format as e.g. 'align' or 'dereferenceable'. Verified by running the full test suite against real LLVM 22.1.8 headers and libraries (via Homebrew). * limit captures_test to llvm 21 and above. * Fix switch-instruction case-value access for LLVM 22 Written entirely by Claude (Anthropic's Claude Code), at the request of and under the direction of dgryski, on the dgryski/llvm23 branch (LLVM 22 support, in preparation for the eventual LLVM 23 release). LLVM 22 stopped exposing SwitchInst case values as regular instruction operands -- only the condition and destination-block operands remain as operands now. Case values must be read via the new LLVMGetSwitchCaseValue C API added in the same release. This was discovered while chasing a real-world regression in TinyGo's interp package (see the paired tinygo commit on the same branch), which manually walked switch operands assuming the old layout; verified independently here first via a minimal standalone .ll repro against real LLVM 20/21/22 headers and libraries, isolating the exact version cutoff (21 -> 22) before touching any tinygo code. Adds: - Value.SuccessorsCount()/Value.Successor(i) in ir.go, using the stable, version-independent LLVMGetNumSuccessors/LLVMGetSuccessor API to enumerate a switch's destination blocks (successor 0 is always the default destination; successors 1..N-1 are the cases). - Value.GetSwitchCaseValue(i), version-gated: switch_llvm22.go uses the new LLVMGetSwitchCaseValue API, switch_pre22.go falls back to the old operand-based read for LLVM <22. - switch_test.go, a regression test verifying case values and destinations round-trip correctly; passes against real LLVM 20/21/22.
# Conflicts: # .github/workflows/go.yml # llvm_config_llvm19.go # llvm_config_llvm20.go
update from upstream
# Conflicts: # .github/workflows/go.yml # llvm_config_llvm19.go
There was a problem hiding this comment.
Code Review
This pull request introduces support for LLVM 22's switch case value retrieval and LLVM 21's 'captures' attribute, along with helper methods to safely enumerate successors of terminator instructions. Feedback on the changes highlights a resource leak in captures_test.go where the LLVM context is not disposed, a potential file-locking issue in switch_test.go if writing to the temporary file fails before it is closed, and an inconsistent library search path (lib64 instead of lib) in the LLVM 20 configuration.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Summary
xgo-dev/llvm:xgo, including tinygo-org/go-llvm PR Add LLVM 22 build support tinygo-org/go-llvm#75 (ddd595b)Validation
go test -v -count=1 ./...with Homebrew LLVM 19.1.7go test -v -count=1 -tags=llvm22 ./...with Homebrew LLVM 22.1.8go vet ./...go vet -tags=llvm22 ./...Context
xgo-dev/llvm PR xgo-dev#43 was closed after approval because upstream PR tinygo-org#75 landed with the more complete LLVM 22 switch/captures fix. This PR absorbs that upstream implementation into the coroutine integration branch instead of reopening xgo-dev#43.