Skip to content

llvm: sync complete upstream LLVM 22 support - #5

Merged
cpunion merged 15 commits into
llvm-corofrom
coro/llvm22-upstream-sync
Jul 24, 2026
Merged

llvm: sync complete upstream LLVM 22 support#5
cpunion merged 15 commits into
llvm-corofrom
coro/llvm22-upstream-sync

Conversation

@cpunion

@cpunion cpunion commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • merge the latest xgo-dev/llvm:xgo, including tinygo-org/go-llvm PR Add LLVM 22 build support tinygo-org/go-llvm#75 (ddd595b)
  • add the LLVM 22 switch-case API split, successor accessors, captures regression test, and upstream LLVM 22 configuration/CI updates
  • retain the coroutine branch APIs and tests: token none, switched-resume/CoroSplit pipelines, target ABI options, section options, and memory-buffer emission
  • keep LLVM 19 as the default binding while validating LLVM 22 explicitly

Validation

  • go test -v -count=1 ./... with Homebrew LLVM 19.1.7
  • go test -v -count=1 -tags=llvm22 ./... with Homebrew LLVM 22.1.8
  • go 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.

aykevl and others added 13 commits September 16, 2025 12:14
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
# Conflicts:
#	.github/workflows/go.yml
#	llvm_config_llvm19.go

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread captures_test.go
Comment thread switch_test.go Outdated
Comment thread llvm_config_llvm20.go
@cpunion
cpunion merged commit 6dccb72 into llvm-coro Jul 24, 2026
4 checks passed
@cpunion
cpunion deleted the coro/llvm22-upstream-sync branch July 24, 2026 13:35
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.

5 participants