Skip to content

go-llvm: add LLVM 23 support and make it default - #2

Merged
zhouguangyuan0718 merged 8 commits into
masterfrom
codex/llvm23-integration
Jul 26, 2026
Merged

go-llvm: add LLVM 23 support and make it default#2
zhouguangyuan0718 merged 8 commits into
masterfrom
codex/llvm23-integration

Conversation

@zhouguangyuan0718

Copy link
Copy Markdown

Summary

  • synchronize the fork with upstream LLVM 22 context API changes
  • add LLVM 23 build constraints and configuration
  • make LLVM 23 the default dynamic configuration
  • keep in-tree static linking behind the explicit staticllvm tag
  • extend CI through LLVM 23

Validation

  • go test -count=1 -tags="byollvm llvm23" ./... against the local LLVM 23.1 shared library
  • go test -count=1 ./... against the same library
  • build-tag matrix checked for default, explicit LLVM 20, static LLVM 23, static LLVM 20, and BYO LLVM 23

aykevl and others added 5 commits July 27, 2026 00:54
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.
…VM 22

LLVM 22 deprecated 8 global-context C API functions in favor of their
context-aware counterparts. Instead of suppressing the warnings, call
the non-deprecated InContext APIs directly.

The non-context Go functions (MDKindID, StructType, ConstString,
ConstStruct, AddBasicBlock, InsertBasicBlock) now delegate to
GlobalContext().<method>(), which already calls the InContext C APIs.
IntPtrType calls LLVMIntPtrTypeInContext directly.

Only LLVMGetGlobalContext still needs a warning-suppression wrapper
in deprecated.c since it has no non-deprecated replacement.

The context-aware C APIs have been available since well before LLVM 14,
so this works across all supported LLVM versions.

Signed-off-by: deadprogram <ron@hybridgroup.com>
@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/llvm23-integration branch from 81f6292 to 1b722f8 Compare July 26, 2026 16:54
@zhouguangyuan0718
zhouguangyuan0718 merged commit 7467f94 into master Jul 26, 2026
44 checks passed
@zhouguangyuan0718
zhouguangyuan0718 deleted the codex/llvm23-integration branch July 26, 2026 17:12
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.

4 participants