Skip to content

Fix JIT miscompile of 0 / x after the update to LLVM 23 - #132041

Merged
Algunenano merged 2 commits into
masterfrom
fix-jit-fdiv-zero-llvm
Nov 17, 2026
Merged

Algunenano merged 2 commits into
masterfrom
fix-jit-fdiv-zero-llvm

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

LLVM 23 SimplifyDemandedUseFPClass folds +0.0 / x to copysign(0.0, x) when x is known to be not NaN, ignoring that 0 / 0 is NaN. Since the update to LLVM 23, JIT-compiled expressions over integer columns (sitofp is never NaN, but can be zero) return wrong results:

SELECT c0 * (0 / c0) FROM values('c0 Int32', 0) SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0;
-- 0 on master, nan with this change (and without JIT)

The upstream fix llvm/llvm-project#202482 is not in upstream release/23.x; it is cherry-picked into the fork in ClickHouse/llvm-project#156, and this PR points the submodule at that commit (on top of the current fork tip, so it also includes the ExtendedLLT race fix from #131685 and the CFI fixes of ClickHouse/llvm-project#155). The pointer should be moved to the merge commit once the fork PR is merged.

Verified locally on aarch64: an LLVM 23 O3 pipeline (as in CHJIT) turns fdiv 0.0, sitofp(x) into copysign, and does not with the patch; the new test fails on a master build and passes with the patched LLVM linked in.

Found by SQLancer (Parallelism oracle; the third run of the same expression reaches min_count_to_compile_expression) on master: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=fdc4389b67de6aa94e602b884e1c403306184af7&name_0=NightlySQLancer&name_1=SQLancer%20%28arm_release%29

Caused by: #117346
Related: #128538
Related: #131685

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/132041]

Version info

  • Merged into: 26.11.1.2623-master (included in 26.11 and later)

LLVM 23 `SimplifyDemandedUseFPClass` folded `+0.0 / x` to `copysign(0.0, x)`
when `x` is known to be not NaN, ignoring that `0 / 0` is NaN. JIT-compiled
expressions like `c0 * (0 / c0)` over an integer column returned `0` instead of
`nan` for `c0 = 0` since the update to LLVM 23. Cherry-pick the upstream fix
llvm/llvm-project#202482 into the fork:
ClickHouse/llvm-project#156

Found by SQLancer (`Parallelism` oracle) on master:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=fdc4389b67de6aa94e602b884e1c403306184af7&name_0=NightlySQLancer&name_1=SQLancer%20%28arm_release%29

Caused by: #117346

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2481497]

Summary: ✅


AI Review

Summary

The LLVM update fixes incorrect results for JIT-compiled 0 / x expressions when x = 0, incorporates runtime and CFI fixes, and adds regression coverage for zero and signed nonzero inputs with compilation enabled and disabled. Reviewed head 24814973c02b9dc31be812db8294e64debf75d87, including the underlying submodule delta and all prior discussion. No actionable findings. The new regression test passes in the current Fast test report.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog submodule changed At least one submodule changed in this PR. comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. labels Nov 16, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@thevar1able thevar1able self-assigned this Nov 16, 2026
@alexey-milovidov alexey-milovidov self-assigned this Nov 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 24814973c with master 180384b06 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

453 object files changed (+71.04 KiB total), 0 added.

Object file Master PR Δ
contrib/compiler-rt-cmake/CMakeFiles/clang_rt_xray.dir/__/llvm-project/compiler-rt/lib/xray/xray_in… 22.91 KiB 81.59 KiB +58.68 KiB (+256.17%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

11301 translation units recompiled, 40024 s compile time in total, 11301 of them have a recent master baseline.

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse __xray::XRayArgLogger new 64.00 KiB +64.00 KiB
programs/clickhouse-keeper __xray::XRayPatchedTypedEvent new 64.00 KiB +64.00 KiB
programs/clickhouse __xray::XRayPatchedFunction new 64.00 KiB +64.00 KiB
programs/clickhouse __xray::XRayPatchedCustomEvent new 64.00 KiB +64.00 KiB
programs/clickhouse-keeper __xray::XRayPatchedFunction new 64.00 KiB +64.00 KiB
programs/clickhouse __xray::XRayPatchedTypedEvent new 64.00 KiB +64.00 KiB
programs/clickhouse-keeper __xray::XRayPatchedCustomEvent new 64.00 KiB +64.00 KiB
programs/clickhouse-keeper __xray::XRayArgLogger new 64.00 KiB +64.00 KiB

Job report

The previous bump pulled in the `thread_local` destructor secret change in
`libcxxabi`, which calls `getentropy` without including `<sys/random.h>` on
macOS. Move to the tip of `ClickHouse/release-23.x`, which adds that include
(ClickHouse/llvm-project#157).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=132041&sha=dbd91ed5a46a8ceaaaafc6c0c0075458f86e5cad&name_0=PR&name_1=Build%20%28arm_darwin%29
Related: #132041

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Algunenano
Algunenano added this pull request to the merge queue Nov 17, 2026
Merged via the queue into master with commit b5e1712 Nov 17, 2026
193 checks passed
@Algunenano
Algunenano deleted the fix-jit-fdiv-zero-llvm branch November 17, 2026 19:47
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants