Skip to content

Use llvm-project 22.1.1 - #98882

Merged
alexey-milovidov merged 12 commits into
masterfrom
update-llvm-22
Apr 9, 2026
Merged

alexey-milovidov merged 12 commits into
masterfrom
update-llvm-22

Conversation

@thevar1able

@thevar1able thevar1able commented Mar 5, 2026 •

Copy link
Copy Markdown
Member

Linked issues

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Use llvm-project 22.1.1

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.691-master (included in 26.4 and later)
  • Backported to: 26.3.37.2

Update the `contrib/llvm-project` submodule from LLVM 21 (release/21.x)
to LLVM 22 (release/22.x). All 11 ClickHouse-specific patches were
cherry-picked onto the new `ClickHouse/release-22.x` branch in the fork;
the e2k `config.guess` patch was already upstream and skipped.

Changes in the main repo:
- Bump `LLVM_VERSION` to `22.1.1bundled`
- Add `_LIBCPP_ASSERTION_SEMANTIC_DEFAULT` to `__config_site` (new
  requirement in LLVM 22 hardening framework)
- Remove `common_constants.cpp` from `libllvmlibc` sources (moved to
  header-only in LLVM 22)

Assisted-by: Claude Opus 4.6 via GitHub Copilot
@clickhouse-gh

clickhouse-gh Bot commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [929733e]

Summary: ✅


AI Review

Summary

This PR upgrades bundled llvm-project to 22.1.1 (plus thrift bump) and applies compatibility fixes, including a deterministic-order fix in text-index prewhere handling. I did not find any high-confidence correctness, safety, or performance regressions in the touched code. High-level verdict: looks safe to merge.

Missing context
  • ⚠️ No CI logs/results were provided in this review context, so runtime/build verification here is limited to code inspection.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR. labels Mar 5, 2026
LLVM 22 libc++ removed transitive includes that older versions
provided. Code relying on `<map>` being transitively included
now needs an explicit include.

Assisted-by: Claude Opus 4.6 via GitHub Copilot
- `StorageFile.cpp`: suppress `[[nodiscard]]` warning on `fs::canonical`
  called only for its side-effect (throwing if file does not exist)
- `StorageMergeTree.cpp`: suppress thread-safety analysis on
  `movePartitionToTable` where `std::lock` + `std::adopt_lock` pattern
  for two mutexes is correct but opaque to the analyzer

Assisted-by: Claude Opus 4.6 via GitHub Copilot
LLVM 22 libc++ removed implicit `operator==` synthesis for types
that only define `operator!=`. The `TEnumIterator` class in thrift
0.16.0 only had `operator!=`, causing build failures with the new
`__tree::__insert_range_unique` that requires `operator==`.

Upstream fixed this in apache/thrift PR #2633 (THRIFT-5603),
included in v0.22.0. Cherry-picked the ClickHouse locale patch
(`std::locale::classic()` instead of `std::locale("C")`) on top.

Assisted-by: Claude Opus 4.6 via GitHub Copilot
- `Intrinsic::getDeclaration` renamed to `Intrinsic::getOrInsertDeclaration`
  in LLVM 22 (abs.cpp, bitCount.cpp)
- `createTargetMachine` first argument changed from `StringRef` to
  `const Triple&` — construct `llvm::Triple` explicitly (CHJIT.cpp)
- `std::__gcd` internal removed from libc++ — use `std::gcd` from
  `<numeric>` (AggregateFunctionKolmogorovSmirnovTest.cpp)
- Added `(void)` casts for new `[[nodiscard]]` on `std::stod`,
  `std::filesystem::is_directory`, and `future.get()`
  (KQLGeneralFunctions.cpp, LocalServer.cpp,
  ZooKeeperRemoveByList.cpp, EphemeralLockInZooKeeper.cpp)

Assisted-by: Claude Opus 4.6 via GitHub Copilot
Construct DataTypeQBit on the stack instead of using std::make_shared,
avoiding the unused-result warning on the discarded shared_ptr.
@rschu1ze rschu1ze self-assigned this Mar 6, 2026
The LLVM 22 libc++ upgrade changed std::unordered_map behavior such that
a copy no longer preserves iteration order. This exposed two latent bugs
in the text index prewhere machinery:

1. `IndexReadTasks` (`std::unordered_map`) is copied into
   `MergeTreeReadPoolBase` and then iterated independently in
   `getPrewhereActions` / `getReadTaskColumns`.  When the copy has a
   different iteration order, prewhere readers and actions get paired by
   index incorrectly, producing either LOGICAL_ERROR (column count
   mismatch) or ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER (String in a filter
   position).  Fixed by switching to `std::map` for deterministic order.

2. The `MergeTreeRangeReader` constructor executed prewhere step actions
   on `result_sample_block` for `None`-type steps (text index read
   steps), but `executePrewhereActionsAndFilterColumns` skips them at
   runtime.  This caused the sample block column order to diverge from
   the actual data, leading to wrong query results when two text indexes
   are present.  Fixed by skipping action execution on the sample block
   for `None`-type steps, matching the runtime behavior.
@clickhouse-gh

clickhouse-gh Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.10% +0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 73.81% (62/84) | lost baseline coverage: 17 line(s) · Uncovered code

Full report · Diff report

@thevar1able
thevar1able marked this pull request as ready for review April 8, 2026 18:36

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 9, 2026
Merged via the queue into master with commit 4d79f6e Apr 9, 2026
163 checks passed
@alexey-milovidov
alexey-milovidov deleted the update-llvm-22 branch April 9, 2026 03:39
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 9, 2026
@watson-ch

watson-ch Bot commented May 19, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/ClickHouse/clickhouse-core-incidents/issues/1792

Labels added:

  • v26.2-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 19, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 19, 2026
thevar1able pushed a commit that referenced this pull request Jun 17, 2026
Manual backport of 1c1c031
("Fix text index prewhere mismatch with multiple indexes") from
#98882.

With `query_plan_direct_read_from_text_index` and `use_skip_indexes_on_data_read`,
the text index read is a `None`-type prewhere step. `MergeTreeRangeReader` executed
that step's actions on the sample block in its constructor, while
`executePrewhereActionsAndFilterColumns` skips `None`-type steps at runtime. When a
row-level filter (e.g. a `ROW POLICY`) reads a `String` column before the `None` step,
the sample-block column order diverged from the actual data, so the raw `String`
column landed in a filter position and the query raised
`ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER` ("Illegal type String of column for filter").

The fix skips executing step actions on the sample block for `None`-type steps, to
match the runtime behavior. It also switches `IndexReadTasks` / `IndexReadColumns` to
`std::map` for deterministic iteration order (the multiple-text-index variant of the
same class of mismatch).

Adds `04332_text_index_direct_read_row_policy` reproducing the single-index
`ROW POLICY` case. Verified against public builds bracketing the fix: it raised
`ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER` on 26.4.1.689 (commit c1225a6, before
PR #98882) and returns 1000 on 26.4.1.691 (commit 4d79f6e, the PR #98882 merge).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Jun 19, 2026
Manual backport of 1c1c031
("Fix text index prewhere mismatch with multiple indexes") from
ClickHouse#98882.

With `query_plan_direct_read_from_text_index` and `use_skip_indexes_on_data_read`,
the text index read is a `None`-type prewhere step. `MergeTreeRangeReader` executed
that step's actions on the sample block in its constructor, while
`executePrewhereActionsAndFilterColumns` skips `None`-type steps at runtime. When a
row-level filter (e.g. a `ROW POLICY`) reads a `String` column before the `None` step,
the sample-block column order diverged from the actual data, so the raw `String`
column landed in a filter position and the query raised
`ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER` ("Illegal type String of column for filter").

The fix skips executing step actions on the sample block for `None`-type steps, to
match the runtime behavior. It also switches `IndexReadTasks` / `IndexReadColumns` to
`std::map` for deterministic iteration order (the multiple-text-index variant of the
same class of mismatch).

Adds `04332_text_index_direct_read_row_policy` reproducing the single-index
`ROW POLICY` case. Verified against public builds bracketing the fix: it raised
`ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER` on 26.4.1.689 (commit c1225a6, before
PR ClickHouse#98882) and returns 1000 on 26.4.1.691 (commit 4d79f6e, the PR ClickHouse#98882 merge).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
 text index prewhere fix)

STOR: with query_plan_direct_read_from_text_index and use_skip_indexes_on_data_read, each text index read is a
None-type PREWHERE step. IndexReadTasks/IndexReadColumns were std::unordered_map: the map is copied into the read
pool and iterated again in getPrewhereActions and getReadTaskColumns, and a copy need not iterate in the same order,
so the PREWHERE readers and the PREWHERE actions of the index steps could be paired differently. In addition
MergeTreeRangeReader executed the actions of None-type steps on its sample block although
executePrewhereActionsAndFilterColumns skips them at run time, so the sample block and the data diverged.
Upstream switches both maps to std::map and skips None-type steps on the sample block (26.3 backport ClickHouse#107758 of
1c1c031 from ClickHouse#98882; 26.4+ have it through ClickHouse#98882).
Effect in the fork: with three partially materialized text indexes in one query (04411, third section) the backport
of ClickHouse#108607 (a6ab685) ran equals(a, 'alpha') on a column that was not the String column a and failed with
TOO_DEEP_RECURSION (KD-UP-TEXTINDEX-DIRECTREAD-3IDX); with a row policy on a String column the upstream test 04332
fails with ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER. Upstream patch unchanged (applies cleanly), with its test
04332_text_index_direct_read_row_policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim PedroTadim added v26.3-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR v26.2-must-backport labels Sep 29, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Backporting to 26.3 for #122836

PedroTadim added a commit that referenced this pull request Sep 29, 2026
Resolves the one conflict in the automated cherry-pick, `contrib/thrift`.

26.3 already carries Apache Thrift v0.24.0, backported as #111278, while
#98882 was the earlier step that moved master from v0.16.0 to v0.22.0.
Taking the cherry-picked side would downgrade the submodule, so ours is
kept: 26.3 and master both stay on 13d30d6a6cdf (v0.24.0).

Everything else merged cleanly. `MergeTreeRangeReader.cpp` and
`MergeTreeReadTask.h` come out unchanged because the text-index prewhere
fix that rides along with this PR is already on 26.3, so git recognised it
as applied rather than dropping it.

Original pull-request: #98882
Cherry-pick pull-request: #122872

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 29, 2026
robot-clickhouse added a commit that referenced this pull request Sep 29, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 29, 2026
Algunenano added a commit that referenced this pull request Sep 29, 2026
Backport #98882 to 26.3: Use `llvm-project` 22.1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-build Pull request with build/testing/packaging improvement pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR. v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants