Skip to content

Support LLVM 22 and fix diagnostics lifetime#1645

Draft
shi-eric wants to merge 1 commit into
NVIDIA:mainfrom
shi-eric:ershi/llvm-build-fixes
Draft

Support LLVM 22 and fix diagnostics lifetime#1645
shi-eric wants to merge 1 commit into
NVIDIA:mainfrom
shi-eric:ershi/llvm-build-fixes

Conversation

@shi-eric

@shi-eric shi-eric commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

Make warp-clang compatible with externally supplied LLVM 22 installations while keeping Warp's source-build default at LLVM 21.1.0. This also fixes a latent diagnostic-consumer use-after-free in the shared LLVM 21+ path.

LLVM 22 removed the ORC debug-object APIs Warp used, and LLVM 19 changed the host CPU feature query to return its map by value. On LLVM 21+, the diagnostics setup also deleted its owned TextDiagnosticPrinter before retaining the same pointer as a non-owned client. LLVM 22 on Windows made that dangling pointer reliably visible as a crash during CPU kernel compilation.

Changes

  • Select the compatible host CPU feature API for LLVM 19+ and ORC debug plugin for LLVM 22+.
  • Transfer diagnostic-consumer ownership with takeClient() and bind its options to the compiler invocation for the required lifetime.
  • Filter Windows LLVM link-directory contents to .lib files so package metadata such as Conan's components.json is not passed to link.exe.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.
  • CHANGELOG.md is updated for any user-facing changes under the Unreleased section.

Validation summary

  • Verified a focused Windows-link-input test fails before the change because components.json reaches the linker inputs, then passes after the .lib filter is applied.
  • Rebuilt warp.so and warp-clang.so from clean native sources with the bundled LLVM 18.1.3 toolchain and CUDA 13.0.
  • Ran a CPU JIT smoke kernel through the rebuilt library and verified its output.
  • Ran test_modules_lite (6 tests) and the full autodetected Warp suite (14,769 tests, 21 skipped); both passed.
  • Ran all configured pre-commit hooks on the changed files.
  • The originating private patch was also validated on Windows x86-64 with LLVM 22.1.8 and LLVM 21.1.8, including warp-clang compilation, linking, and a CPU JIT smoke kernel.

Bug fix

With warp-clang built against externally supplied LLVM 22 libraries, a CPU kernel compile exercised the dangling diagnostic consumer and crashed before this change. The equivalent smoke kernel now compiles and runs:

import warp as wp


@wp.kernel
def increment(values: wp.array(dtype=wp.int32)):
    i = wp.tid()
    values[i] += 1


values = wp.array([1, 2, 3], dtype=wp.int32, device="cpu")
wp.launch(increment, dim=values.size, inputs=[values], device="cpu")
assert values.numpy().tolist() == [2, 3, 4]

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows builds by excluding non-library files from the linking process.
    • Updated compatibility for newer LLVM versions, improving compiler integration and reducing build failures.
    • Improved diagnostic handling to provide more reliable compiler error and warning reporting.
    • Enhanced debug information support for JIT-compiled code on recent LLVM releases.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: bf1234e9-98bf-49c7-96ce-258ad381bce7

📥 Commits

Reviewing files that changed from the base of the PR and between 5498fff and d4974dc.

📒 Files selected for processing (2)
  • build_llvm.py
  • warp/native/clang/clang.cpp
✅ Files skipped from review due to trivial changes (1)
  • build_llvm.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • warp/native/clang/clang.cpp

📝 Walkthrough

Walkthrough

The change filters Windows linker inputs to .lib files and updates clang’s LLVM-version-specific CPU, diagnostics, and JIT debug-object integration for newer LLVM APIs.

Changes

LLVM compatibility and linking

Layer / File(s) Summary
Windows library input filtering
build_llvm.py
The Windows clang build path retains only .lib entries from collected linker inputs.
LLVM compiler and diagnostics API compatibility
warp/native/clang/clang.cpp
CPU feature discovery, diagnostic option lifetime, and diagnostic consumer ownership are adjusted for LLVM version-specific APIs.
JIT debug-object plugin integration
warp/native/clang/clang.cpp
LLVM 22 and newer use ELFDebugObjectPlugin, with conditional error handling and version-specific debug headers; older versions retain the legacy path.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main changes: LLVM 22 support and the diagnostics lifetime fix.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@shi-eric shi-eric self-assigned this Jul 10, 2026
@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR updates Warp's LLVM integration for newer external LLVM installs. The main changes are:

  • LLVM 22 ORC debug plugin support for JITLink.
  • LLVM 19+ host CPU feature API compatibility.
  • Safer diagnostic consumer ownership for LLVM 21+.
  • Windows LLVM link input filtering for .lib files.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
build_llvm.py Filters Windows LLVM link inputs to case-insensitive .lib files before adding required system libraries.
warp/native/clang/clang.cpp Adds LLVM-version-specific handling for CPU features, diagnostics ownership, and LLVM 22 debug plugin setup.

Reviews (2): Last reviewed commit: "Support LLVM 22 and fix diagnostics life..." | Re-trigger Greptile

Comment thread build_llvm.py Outdated
Warp-clang could not compile against LLVM 19 through 22 because upstream
API changes were either guarded at the wrong version or not handled.
LLVM 21 also exposed a latent diagnostics bug: changing an owned
consumer to a non-owning pointer deleted the consumer and retained a
dangling pointer.

Select the appropriate host-feature and ORC debug APIs by LLVM version.
Transfer the diagnostic consumer out of its temporary engine and bind
its options to the compiler invocation so both objects outlive
compilation.
Filter external Windows LLVM directories to .lib files so package
metadata does not reach the linker.

This keeps the source-build default at LLVM 21.1.0 while allowing
externally supplied LLVM 22 installations.

Signed-off-by: Eric Shi <ershi@nvidia.com>
@shi-eric shi-eric force-pushed the ershi/llvm-build-fixes branch from 5498fff to d4974dc Compare July 11, 2026 00:00
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