Skip to content

Fix clang 23 -Wlifetime-safety errors - #106197

Merged
azat merged 1 commit into
ClickHouse:masterfrom
azat:fix/clang-23-lifetime-safety
Jun 9, 2026
Merged

azat merged 1 commit into
ClickHouse:masterfrom
azat:fix/clang-23-lifetime-safety

Conversation

@azat

@azat azat commented May 31, 2026 •

Copy link
Copy Markdown
Member

Fix:

  • -Wlifetime-safety-dangling-global-moved in ReplicasReconnector,
  • -Wlifetime-safety-dangling-field-moved in MergeTreeReaderStream and TTLTransform
  • -Wlifetime-safety-return-stack-addr-moved in BackupsWorker (move first, alias later)
  • -Wunused-but-set-variable for inside_main in keeper.
  • -Wlifetime-safety-use-after-scope-moved in ProfileEvents

Disable -Wlifetime-safety-invalidation: too many false positives, it treats mutation of a container captured by reference in a lambda as invalidating the reference to the container variable itself.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Version info

  • Merged into: 26.6.1.581

@clickhouse-gh

clickhouse-gh Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [39807ec]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_tsan, 4/6) FAIL
test_library_bridge/test.py::test_server_restart_bridge_might_be_still_alive FAIL cidb
BuzzHouse (amd_debug) FAIL
Logical error: 'Inconsistent AST formatting: the original AST: (STID: 1941-1bfa) FAIL cidb
Performance Comparison (arm_release, master_head, 6/6) FAIL Performance dashboard
array_reduce #1::old FAIL query history
array_reduce #1::new FAIL query history
array_reduce #2::old FAIL query history
array_reduce #2::new FAIL query history
fuse_sumcount #0::old FAIL query history
fuse_sumcount #0::new FAIL query history
logical_functions_medium #0::old FAIL query history
logical_functions_medium #0::new FAIL query history
logical_functions_medium #3::old FAIL query history
logical_functions_medium #3::new FAIL query history
10 more test cases not shown

AI Review

Summary

This PR makes narrowly scoped build-warning fixes for clang 23 lifetime-safety diagnostics by deriving aliases after ownership transfer, giving inside_main external linkage in the keeper entrypoint, and disabling the noisy lifetime-safety-invalidation warning. I found no correctness, safety, or rollout issues in the changed lines.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 31, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

it treats mutation of a container captured by reference in a lambda as invalidating the reference to the container variable itself

We can annotate these cases in a subsequent PR and enable the warnings. I don't mind doing it in 1000 places :)

@azat

azat commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

We can annotate these cases in a subsequent PR and enable the warnings. I don't mind doing it in 1000 places :)

There are not too many (AFAFIR around 63), but not sure that it worth it, since looks like it is a bug in the clang analysis

Fix:
- -Wlifetime-safety-dangling-global-moved in `ReplicasReconnector`,
- -Wlifetime-safety-dangling-field-moved in `MergeTreeReaderStream` and `TTLTransform`
- -Wlifetime-safety-return-stack-addr-moved in `BackupsWorker` (move first, alias later)
- -Wunused-but-set-variable for `inside_main` in keeper.
- -Wlifetime-safety-use-after-scope-moved in ProfileEvents

Disable -Wlifetime-safety-invalidation: too many false positives, it treats
mutation of a container captured by reference in a lambda as invalidating the
reference to the container variable itself.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@azat
azat force-pushed the fix/clang-23-lifetime-safety branch from b9d2d91 to 39807ec Compare June 9, 2026 07:58
@azat
azat enabled auto-merge June 9, 2026 07:58
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.20% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 34/38 (89.47%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@azat
azat added this pull request to the merge queue Jun 9, 2026
Merged via the queue into ClickHouse:master with commit c71bec3 Jun 9, 2026
162 of 166 checks passed
@azat
azat deleted the fix/clang-23-lifetime-safety branch June 9, 2026 20:34
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants