Skip to content

chore: upgrade LLVM to 22.1.4#477

Open
16bit-ykiko wants to merge 2 commits into
mainfrom
chore/upgrade-llvm-22-v2
Open

chore: upgrade LLVM to 22.1.4#477
16bit-ykiko wants to merge 2 commits into
mainfrom
chore/upgrade-llvm-22-v2

Conversation

@16bit-ykiko

@16bit-ykiko 16bit-ykiko commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Upgrade LLVM dependency from 21.1.8 to 22.1.4. Single commit, pure API adaptation — no infrastructure changes (those landed in #476).

LLVM 22 Breaking Changes Adapted

All changes documented in docs/en/changelog/llvm-changelog.md with upstream commit references.

Type system (5 of 7 from the same mega-commit #147835):

  • ElaboratedType removed — keyword/qualifier merged into TagType
  • InjectedClassNameType now inherits TagType
  • DependentTemplateSpecializationType merged into TemplateSpecializationType
  • TagDecl::getTypeForDecl() deleted → ASTContext::getCanonicalTagType()
  • UsingType::getFoundDecl()getDecl()
  • PredefinedSugarType (__size_t) — desugar in hover
  • Implicit var template specs no longer retain written args

NNS: pointer → value type; Kind::Identifier/NamespaceAlias removed; NamespaceBaseDecl introduced

Driver/Frontend: Options.inc path changed; OPTION macro 15th param; GetResourcesPath moved; createDiagnostics VFS param removed

Other: fs::make_absolutepath::make_absolute; ClangTidyModuleRegistry.h deprecated

Notable behavior changes

  • Hover no longer adds struct/class/enum prefix (removed tag-keyword hack — LLVM 22 TypePrinter handles elaboration natively)
  • PredefinedSugarType desugared in hover to avoid __size_t display

Test plan

  • Unit tests: 716 passed locally
  • Integration tests: 177 passed locally
  • Smoke tests: 3/3 passed locally
  • CI: all platforms

Summary by CodeRabbit

  • New Features

    • Upgraded to a newer LLVM/Clang release, bringing updated language and tooling support.
  • Bug Fixes

    • Improved hover/type rendering with cleaner type names and more accurate record layout sizing.
    • Enhanced indexing/USR and semantic selection for injected class names and qualified/nested-name constructs.
    • Improved Clang resource path, option parsing, and VFS/diagnostics setup for more reliable analysis.
  • Documentation

    • Added LLVM upgrade breaking-change notes (LLVM 21 → 22).
  • Tests

    • Updated hover snapshots and unit expectations to match the new rendering/selection behavior.

Adapt codebase to LLVM 22 API changes:
- ElaboratedType removed: delete all getAs<ElaboratedType>() calls
- NestedNameSpecifier: pointer → value type, Kind::Identifier/NamespaceAlias removed
- DependentTemplateSpecializationType merged into TemplateSpecializationType
- TagDecl::getTypeForDecl() deleted → use ASTContext::getCanonicalTagType()
- UsingType::getFoundDecl() → getDecl()
- PredefinedSugarType (__size_t): desugar in hover to avoid internal names
- InjectedClassNameType inherits TagType: USR encoding verified consistent
- CompilerInstance::createDiagnostics VFS param removed
- Options.inc moved to clang/Options/, OPTION macro gained 15th param
- Driver::GetResourcesPath → clang::GetResourcesPath
- fs::make_absolute → path::make_absolute
- ClangTidyModuleRegistry.h → ClangTidyModule.h
- Remove hover tag-keyword hack (LLVM 22 handles it natively)
- Add clangOptions and clangTidyCustomModule to link deps
@coderabbitai

coderabbitai Bot commented Jul 1, 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.yaml

Review profile: CHILL

Plan: Pro

Run ID: bf390bdc-e1a1-4da4-ab9f-51281a642eb1

📥 Commits

Reviewing files that changed from the base of the PR and between 39f8019 and 9008031.

📒 Files selected for processing (3)
  • src/semantic/resolver.cpp
  • src/semantic/semantic_visitor.h
  • tests/unit/index/usr_tests.cpp
💤 Files with no reviewable changes (1)
  • tests/unit/index/usr_tests.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/semantic/semantic_visitor.h
  • src/semantic/resolver.cpp

📝 Walkthrough

Walkthrough

This PR upgrades LLVM to 22.1.4, updates Clang library and option-table wiring, migrates several Clang API usages to LLVM 22 forms, rewrites dependent type and nested-name-specifier handling, and updates docs plus snapshots/tests to match the new behavior.

Changes

LLVM 22 API Migration

Layer / File(s) Summary
Build configuration and LLVM version bump
cmake/llvm.cmake, cmake/package.cmake, docs/en/changelog/llvm-changelog.md
LLVM is pinned to 22.1.4, additional Clang libraries are linked, and the changelog records the LLVM 21→22 breaking changes.
Argument parser and resource path migration
src/command/argument_parser.cpp, src/command/argument_parser.h
Clang option-table generation moves to clang/Options/Options.inc, OPTION expansion is adjusted, and resource path lookup uses clang::GetResourcesPath.
Compilation and scan diagnostics/VFS setup
src/compile/compilation.cpp, src/syntax/scan.cpp, src/compile/implement.h, src/compile/tidy.cpp, src/command/search_config.cpp
Clang diagnostics, VFS, and file-manager setup are reordered, ClangTidyModule.h replaces ClangTidyModuleRegistry.h, and absolute-path normalization uses llvm::sys::path::make_absolute.
Type system and NestedNameSpecifier value-type migration
src/semantic/ast_utility.cpp, src/semantic/filtered_ast_visitor.h, src/semantic/find_target.cpp, src/semantic/selection.cpp, src/semantic/semantic_visitor.h, src/index/usr_generation.cpp, src/feature/hover.cpp
Nested-name-specifier handling moves to value semantics across visitors and helpers, and type/name printing updates to the new Clang 22 type forms.
Template resolver dependent-type resolution rewrite
src/semantic/resolver.cpp, src/semantic/resolver.h
Dependent template and nested-name lookup logic is rewritten around value-based nested-name specifiers and canonical tag types.
Tests and snapshot updates
tests/snapshots/hover/snapshot/*, tests/unit/feature/inlay_hint_tests.cpp, tests/unit/index/usr_tests.cpp, tests/unit/semantic/selection_tests.cpp
Hover, inlay-hint, USR, and selection expectations are updated to match the new printing and traversal behavior.

Estimated code review effort: 4 (Complex) | ~75 minutes

Possibly related PRs

  • clice-io/clice#346: Both PRs modify CompilationUnitRef::Self::run_clang diagnostics/VFS/file-manager wiring.
  • clice-io/clice#371: Both PRs modify argument parsing code, particularly resource-dir resolution and option-table/OPTION macro handling.
  • clice-io/clice#388: Both PRs heavily refactor src/semantic/resolver.cpp/.h, including TemplateResolver::lookup and NestedNameSpecifier handling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.65% 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 clearly and concisely summarizes the main change: upgrading LLVM to 22.1.4.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/upgrade-llvm-22-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/semantic/find_target.cpp (1)

456-501: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Restore dependent template-specialization resolution. TemplateSpecializationType with a DependentTemplateName now falls through this visitor, so names like T::template rebind<U> can lose hover/go-to targets. Add a dependent-template-name branch before the alias/non-dependent handling and route it through the existing resolver path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/semantic/find_target.cpp` around lines 456 - 501, Restore handling for
dependent template specializations in VisitTemplateSpecializationType so
dependent names do not fall through and lose targets. Add an explicit branch for
type->getTemplateName().isDependent() before the alias/non-dependent logic, and
route it through the existing resolver path used for dependent template names.
Keep the current alias, template template parameter, CXXRecordDecl, and fallback
cases unchanged for non-dependent specializations.
🧹 Nitpick comments (1)
tests/unit/index/usr_tests.cpp (1)

351-375: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove debug llvm::errs() calls.

These prints will run on every test execution and add noise; the ASSERT_EQ already validates the invariant.

♻️ Proposed cleanup
     t2.run();
 
-    llvm::errs() << "injected S:    " << t1.lookup("f") << "\n";
-    llvm::errs() << "explicit S<T>: " << t2.lookup("f") << "\n";
-
     ASSERT_EQ(t1.lookup("f"), t2.lookup("f"));
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/index/usr_tests.cpp` around lines 351 - 375, The InjectedClassName
test in the USR tester currently emits debug output via llvm::errs() before the
ASSERT_EQ, which adds noise to every test run. Remove the temporary stderr
prints from the InjectedClassName case and keep only the assertion comparing
t1.lookup("f") and t2.lookup("f"); use the test names and USRTester calls to
locate the cleanup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/semantic/find_target.cpp`:
- Around line 456-501: Restore handling for dependent template specializations
in VisitTemplateSpecializationType so dependent names do not fall through and
lose targets. Add an explicit branch for type->getTemplateName().isDependent()
before the alias/non-dependent logic, and route it through the existing resolver
path used for dependent template names. Keep the current alias, template
template parameter, CXXRecordDecl, and fallback cases unchanged for
non-dependent specializations.

---

Nitpick comments:
In `@tests/unit/index/usr_tests.cpp`:
- Around line 351-375: The InjectedClassName test in the USR tester currently
emits debug output via llvm::errs() before the ASSERT_EQ, which adds noise to
every test run. Remove the temporary stderr prints from the InjectedClassName
case and keep only the assertion comparing t1.lookup("f") and t2.lookup("f");
use the test names and USRTester calls to locate the cleanup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 29d41ac9-6751-4ae6-ba79-c9bd6556de52

📥 Commits

Reviewing files that changed from the base of the PR and between 9ff3f6f and 39f8019.

📒 Files selected for processing (28)
  • cmake/llvm.cmake
  • cmake/package.cmake
  • docs/en/changelog/llvm-changelog.md
  • src/command/argument_parser.cpp
  • src/command/argument_parser.h
  • src/command/search_config.cpp
  • src/compile/compilation.cpp
  • src/compile/implement.h
  • src/compile/tidy.cpp
  • src/feature/hover.cpp
  • src/index/usr_generation.cpp
  • src/semantic/ast_utility.cpp
  • src/semantic/filtered_ast_visitor.h
  • src/semantic/find_target.cpp
  • src/semantic/resolver.cpp
  • src/semantic/resolver.h
  • src/semantic/selection.cpp
  • src/semantic/semantic_visitor.h
  • src/syntax/scan.cpp
  • tests/snapshots/hover/snapshot/auto.cpp.snap.yml
  • tests/snapshots/hover/snapshot/docs.cpp.snap.yml
  • tests/snapshots/hover/snapshot/lambdas.cpp.snap.yml
  • tests/snapshots/hover/snapshot/tag_decls.cpp.snap.yml
  • tests/snapshots/hover/snapshot/this_expr.cpp.snap.yml
  • tests/snapshots/hover/snapshot/values.cpp.snap.yml
  • tests/unit/feature/inlay_hint_tests.cpp
  • tests/unit/index/usr_tests.cpp
  • tests/unit/semantic/selection_tests.cpp

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

if(auto* template_decl = type->getTemplateName().getAsTemplateDecl()) {
outer.add(template_decl->getTemplatedDecl(), flags | Rel::TemplatePattern);
}

P2 Badge Restore dependent template specialization resolution

When the selected type is a dependent template specialization such as typename Traits<T>::template rebind<U>, getTemplateName().getAsTemplateDecl() is null; before this upgrade the dedicated dependent-template visitor queried HeuristicResolver::resolveTemplateSpecializationType. With LLVM 22 these nodes now arrive here as TemplateSpecializationType, but this fallback only handles non-dependent template decls, so go-to-definition/hover/reference targeting on those dependent template names returns no target.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/feature/hover.cpp
Comment thread tests/snapshots/hover/snapshot/docs.cpp.snap.yml
@16bit-ykiko

Copy link
Copy Markdown
Member Author

Retrigger CI after release

@16bit-ykiko 16bit-ykiko closed this Jul 1, 2026
@16bit-ykiko 16bit-ykiko reopened this Jul 1, 2026
- Remove debug llvm::errs() from InjectedClassName USR test
- Fix stale comments: TransformDependentTemplateSPTType →
  TransformTemplateSpecializationType, remove ElaboratedType mention
- Use default case in NNS kind switches for forward compatibility

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

void VisitTemplateSpecializationType(const clang::TemplateSpecializationType* type) {

P2 Badge Restore dependent template-specialization resolution

In LLVM 22 the old DependentTemplateSpecializationType cases now arrive here as TemplateSpecializationType, but this visitor never falls back to HeuristicResolver::resolveTemplateSpecializationType(const TemplateSpecializationType*). For a dependent template-id such as typename MetaFun::template apply<T>/typename A<T>::template rebind<U>, getAsTemplateDecl() and getAsCXXRecordDecl() are null, so explicit_reference_targets() returns no declaration and hover/go-to-definition lose the target that the removed visitor used to resolve.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

EXPECT_SIZE(2);
EXPECT_HINT("0", ": S1");
EXPECT_HINT("1", ": S2::Inner<int>");
EXPECT_HINT("1", ": Inner<int>");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve nested-class qualifiers in type hints

Accepting this expectation means class-member nested return types are now rendered without the owning class when only namespace qualifiers were meant to be suppressed. In this test auto y = bar(); is in namespace A::B, but Inner<int> is not a valid or unambiguous spelling there without S2::, so type inlay hints for nested types returned outside their parent class become misleading.

Useful? React with 👍 / 👎.

Comment on lines +759 to +760
bool TraverseTypeLoc(clang::TypeLoc X, bool traverse_qualifier = true) {
return traverse_node(&X, [&] { return Base::TraverseTypeLoc(X, traverse_qualifier); });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Traverse explicit qualifiers in selections

When Clang calls this override with traverse_qualifier=false for declarations such as using enum ns::A, the selection tree no longer records the explicit NestedNameSpecifierLoc; the updated selection test now falls back from the ns:: qualifier to the whole UsingEnumDecl. That makes hover/go-to-definition on the ns token resolve the enum/using declaration rather than the namespace, so explicit qualifiers still need to be traversed or handled for this case.

Useful? React with 👍 / 👎.

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