Shader tests: LLVM's verifier over every module the tests emit #68

Open
github-bot wants to merge 2 commits from github-bot/gh-68 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:34 UTC · original
lcg007xd-c:feat/llvm-verify-test-modules → main · +140 −1 · 4 files · 2 commits · open

What

The DXIL we emit is LLVM bitcode, so LLVM's own verifier can check it on any platform. Today a broken module is caught only by dxil.dll, and only on Windows. That covers the class of bug the README mentions: a phi or value that does not dominate its uses.

This adds a test-only hook where Shader::finish writes the bitcode, right next to the census hook. When VICTORY_LLVM_OPT names an opt binary, every module any test emits goes through opt -passes=verify. A rejected module fails the test that made it, with LLVM's message, and the module is saved to the temp directory for llvm-dis. When the variable is unset, nothing happens. The Windows job is unchanged.

Details:

  • Data layout override. The module's own data layout predates current LLVM's rule that i8 is 8-bit aligned. Plain opt/llvm-dis refuse it ("i8 must be 8-bit aligned"), so the check passes DXIL's layout as -data-layout.
  • Only real verifier failures fail a test. That means LLVM's "input module is broken". An opt that can't read the module at all (too old, or something else named opt) is reported once and then not asked again.
  • CI. The portable job sets VICTORY_LLVM_OPT to the newest opt on the runner image, if there is one, and prints its version.

Tests

  • the_verifier_rejects_a_use_its_definition_does_not_dominate builds a two-armed diamond with the bitcode writer. It checks that the phi version verifies and that the version reading the arm's value directly is rejected ("Instruction does not dominate all uses!"). So the hook is shown to really run, not just to be silent.
  • Locally (LLVM 23.1 opt), VICTORY_LLVM_OPT=opt cargo test on the portable crates passes. opt ran on 99 modules from the victory-shader tests and added about 2 s.
  • Without the variable, the suites run as before. The portable clippy and Windows-target clippy (--target x86_64-pc-windows-msvc) are clean.

Not tested: which LLVM the ubuntu-latest image has, and whether that version reads DXIL. I only had LLVM 23 here. This PR's CI log will show it on the "VICTORY_LLVM_OPT=" line. If it can't read the modules, the tests still pass, and the step only says so once.

Note: the Windows check job fails on current main for an unrelated reason (5668b8b, missing Layout::bytes_from), which #64 fixes.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:34 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/68) `lcg007xd-c:feat/llvm-verify-test-modules` → `main` · +140 −1 · 4 files · 2 commits · open ## What The DXIL we emit is LLVM bitcode, so LLVM's own verifier can check it on any platform. Today a broken module is caught only by `dxil.dll`, and only on Windows. That covers the class of bug the README mentions: a phi or value that does not dominate its uses. This adds a test-only hook where `Shader::finish` writes the bitcode, right next to the `census` hook. When `VICTORY_LLVM_OPT` names an `opt` binary, every module any test emits goes through `opt -passes=verify`. A rejected module fails the test that made it, with LLVM's message, and the module is saved to the temp directory for `llvm-dis`. When the variable is unset, nothing happens. The Windows job is unchanged. Details: - **Data layout override.** The module's own data layout predates current LLVM's rule that `i8` is 8-bit aligned. Plain `opt`/`llvm-dis` refuse it ("i8 must be 8-bit aligned"), so the check passes DXIL's layout as `-data-layout`. - **Only real verifier failures fail a test.** That means LLVM's "input module is broken". An `opt` that can't read the module at all (too old, or something else named `opt`) is reported once and then not asked again. - **CI.** The `portable` job sets `VICTORY_LLVM_OPT` to the newest `opt` on the runner image, if there is one, and prints its version. ## Tests - `the_verifier_rejects_a_use_its_definition_does_not_dominate` builds a two-armed diamond with the bitcode writer. It checks that the phi version verifies and that the version reading the arm's value directly is rejected ("Instruction does not dominate all uses!"). So the hook is shown to really run, not just to be silent. - Locally (LLVM 23.1 `opt`), `VICTORY_LLVM_OPT=opt cargo test` on the portable crates passes. `opt` ran on 99 modules from the `victory-shader` tests and added about 2 s. - Without the variable, the suites run as before. The portable clippy and Windows-target clippy (`--target x86_64-pc-windows-msvc`) are clean. Not tested: which LLVM the `ubuntu-latest` image has, and whether that version reads DXIL. I only had LLVM 23 here. This PR's CI log will show it on the "VICTORY_LLVM_OPT=" line. If it can't read the modules, the tests still pass, and the step only says so once. Note: the Windows `check` job fails on current main for an unrelated reason (5668b8b, missing `Layout::bytes_from`), which #64 fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DXIL is LLVM bitcode, so `opt -passes=verify` finds a broken module
(an instruction that does not dominate its uses, a mistyped operand) on
any platform, without dxil.dll. With VICTORY_LLVM_OPT naming an `opt`,
every module a test emits goes through it as it is written, and a
rejected module fails that test and is kept for llvm-dis. The module's
own data layout predates current LLVM's rule that i8 is 8-bit aligned,
so the check passes DXIL's layout in today's spelling. An opt that
cannot read the module at all is reported once and not asked again.

The portable CI job sets it to the newest opt on the runner image.
A synthetic module with a use its definition does not dominate checks
that the verifier really runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:59 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/68/head:github-bot/gh-68'
git switch 'github-bot/gh-68'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-68'
git switch 'github-bot/gh-68'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-68'
git switch 'github-bot/gh-68'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-68'
git switch 'main'
git merge --squash 'github-bot/gh-68'
git switch 'main'
git merge --ff-only 'github-bot/gh-68'
git switch 'main'
git merge 'github-bot/gh-68'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.