Skip to content

Suppress lifetime-safety-return-stack-addr-moved from clang 23, not 24 - #118005

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
navneet83:fix-lifetime-safety-warning-gate-clang23
Sep 13, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
navneet83:fix-lifetime-safety-warning-gate-clang23

Conversation

@navneet83

@navneet83 navneet83 commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

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

Fixed the build with clang 23, which failed on a lifetime-safety diagnostic whose suppression was gated one major version too high.

Documentation entry for user-facing changes

cmake/warnings.cmake gates the suppression of lifetime-safety-return-stack-addr-moved on clang >= 24, on the assumption that nothing below that emits it. Clang 23 emits it, and since the warning is on by default and WERROR is on by default, the build fails:

src/Parsers/Prometheus/PrometheusQueryTree.cpp:165:22: error: stack memory associated with
local variable 'new_node' may be returned later. This could be a false positive as the storage
may have been moved. Consider moving first and then aliasing later to resolve the issue
[-Werror,-Wlifetime-safety-return-stack-addr-moved]

ten times, once per template instantiation. The three related lifetime-safety diagnostics immediately above are already gated on 23 and suppressed correctly, so the compile command carries -Wno-lifetime-safety-intra-tu-suggestions, -Wno-lifetime-safety-cross-tu-suggestions and -Wno-lifetime-safety-invalidation - but not this one.

Nothing about the code is wrong: the unique_ptr payload is on the heap and outlives the local, which the existing comment already explains. Only the version gate is off by one.

Verified by A/B on the same file and compiler (Homebrew clang 23.1.0, macOS arm64, CMAKE_BUILD_TYPE=Release):

gate result
VERSION_GREATER_EQUAL 24 (current) fails, as above
VERSION_GREATER_EQUAL 23 (this PR) compiles

With the change, a full native build completes: 15074/15075 targets, no failures, working binary.

This is reachable today rather than hypothetical - Homebrew's default llvm is currently 23.1.0, so a fresh native macOS build hits it. A box with clang 22 builds fine, which bounds the problem to clang 23 exactly.

I also dropped the now-stale note saying clang 24 is only reached by the Emscripten build, since that assumption is what put the gate one version too high.

Minor: this leaves two consecutive blocks with the same VERSION_GREATER_EQUAL 23 condition. I kept the diff to one line rather than merging them, but happy to merge if you prefer.


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

Version info

  • Merged into: 26.9.1.1365 (included in 26.9 and later)

The suppression was gated on clang 24 on the assumption that nothing below it
emits the diagnostic. Clang 23 emits it, so a build with clang 23 fails: the
warning is on by default, `WERROR` is on by default, and
`src/Parsers/Prometheus/PrometheusQueryTree.cpp:165` trips it ten times, once per
template instantiation.

    error: stack memory associated with local variable 'new_node' may be returned
    later. This could be a false positive as the storage may have been moved.
    [-Werror,-Wlifetime-safety-return-stack-addr-moved]

The three related `lifetime-safety` diagnostics are already gated on 23 and are
suppressed correctly; only this one is not, so the compile command carries
`-Wno-lifetime-safety-intra-tu-suggestions`,
`-Wno-lifetime-safety-cross-tu-suggestions` and
`-Wno-lifetime-safety-invalidation` but not this one.

Nothing about the code is wrong - the `unique_ptr` payload is on the heap and
outlives the local, which the comment already says. Lower the gate to match the
compiler that actually emits it, and drop the stale note about clang 24 being
Emscripten-only.
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [17b5613]

Summary: ✅


AI Review

Summary

This PR lowers the suppression gate for -Wlifetime-safety-return-stack-addr-moved from Clang 24 to Clang 23 in cmake/warnings.cmake, matching the compiler version that now emits the diagnostic. I did not find a correctness or build-system regression in the change: ClickHouse supports only Clang >= 21, the neighboring lifetime-safety-* suppressions are already guarded at >= 23, and no_warning is intentionally version-gated in this file rather than probed at configure time.

Missing context / blind spots
  • ⚠️ The full Build matrix was still running at review time, so I could not independently confirm on CI that every supported Clang 23 toolchain accepts the flag. The change is nevertheless consistent with the project’s existing Clang-version gating model.
Final Verdict

✅ No findings. I would approve this as a targeted fix to the warning gate.

LLVM Coverage Report

Measured on commit 17b5613.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.10% -0.10%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +821 lines in 213 files (-938 lines lost coverage) · Details

Full report

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 17b56131b with master 8201c8238 (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.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-build-system Build system (CMake, compilation, platform builds). label Sep 4, 2026
@navneet83

Copy link
Copy Markdown
Member Author

I dug up where the 24 came from before opening this — b18b5a42a in #113404:

gated on clang >= 24, the way cmake/add_warning.cmake prescribes. That analysis is experimental, only exists in clang 24 (which nothing links today except Emscripten's bundled compiler)

No argument with the convention, just with the number. Clang 23 emits this one too. Building master with Homebrew clang 23 on macOS:

src/Parsers/Prometheus/PrometheusQueryTree.cpp:165:22: error: stack memory associated with
local variable 'new_node' may be returned later. This could be a false positive as the storage
may have been moved. Consider moving first and then aliasing later to resolve the issue
[-Werror,-Wlifetime-safety-return-stack-addr-moved]

Same idiom you described — pointer out of a unique_ptr, owner moved into a container — and clang 23 accepts the -Wno- form, so 23 looks like the right N. It also puts this with the three lifetime-safety suppressions directly above it.

Couple of caveats. This doesn't affect CI at all — that's on clang 22 and never sees the diagnostic, so it only helps local clang 23 builds. And I assumed 23 is supported because those three neighbours are gated there; if that's not the case, say so and I'll close it.

@alexey-milovidov you wrote the gate and the comment — any reason not to move it to 23? Emscripten links 24, so it stays suppressed there either way.

@alexey-milovidov alexey-milovidov self-assigned this Sep 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 13, 2026
Merged via the queue into ClickHouse:master with commit 64bddd3 Sep 13, 2026
175 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 13, 2026
@navneet83
navneet83 deleted the fix-lifetime-safety-warning-gate-clang23 branch September 23, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-build-system Build system (CMake, compilation, platform builds). pr-build Pull request with build/testing/packaging improvement 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