Repository navigation
fix(ci): rebuild PCH when a header is touched (stale-PCH pragma once redefinitions) - #4839
Conversation
…ts content changes clang 21 (-fpch-validate-input-files-content) accepts a PCH whose inputs are byte-identical but have a newer mtime, then fails to tie those headers to the PCH copies, so #pragma once stops deduping them and every consumer TU dies with 'redefinition of ...'. compile_pch.py skipped the rebuild on a content-hash match, which is exactly that case. Rebuild whenever any input is newer than the PCH, in both the skip path and invalidate_stale_pch.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
* docs(skills): add /pch-debug skill and pch_probe.py
A skill that auto-activates on PCH failures ('redefinition of',
'redefines default argument', 'modified since the precompiled header',
tests that pass only after --clean). It explains the identity model
(#pragma once fails early; include guards hide the double read), the two
mechanisms in FastLED's history (path-spelling drift: #2685/zccache#619,
#3813; stale PCH accepted: #4839, #4437, #2995/zccache#710), and a
probe-before-clean procedure.
pch_probe.py: 'inputs' dumps what the PCH recorded (falls back to scanning
the PCH bytes when clang refuses a stale PCH) and flags odd spellings,
duplicate spellings and stale inputs; 'tu' runs a real compile_commands
entry with -H (optionally through zccache) and lists project headers
re-opened from disk next to their PCH spelling.
* pch_probe: llvm-bcanalyzer input records; repo-root-based project-header check (#4860 review)
- inputs: read the PCH with llvm-bcanalyzer -dump when available (PATH or
LLVM_BCANALYZER): exact recorded spelling, size and mtime per input,
without clang's stale-PCH validation; stale = size/mtime differ from the
record (clang's own check). Falls back to -module-file-info / byte scan.
- Project headers are now classified by resolving under the repo root
(derived from the script location), not by matching /src/ or /tests/ in
the raw spelling: relative recorded entries like tests/... count, and any
--build-dir location works.
* pch_probe: resolve relative recorded inputs against the build dir (#4860 review)
Root cause
This is not a zccache bug. clang (reproduced on 21.1.5 through ctc-clang++, and on a standalone 21.1.8) with
-fpch-validate-input-files-contentaccepts a PCH whose inputs are byte-identical but have a newer mtime. It then fails to match those headers to the copies inside the PCH, so#pragma oncedoes not stop the second include and the header is parsed again. You getmalloc.h:20:36: error: template parameter redefines default argumentandredefinition of 'malloc'.ci/compile_pch.pyskipped the PCH rebuild whenever the hash of the input contents matched. A touched header with unchanged bytes is exactly that case. Any TU that really recompiled (a zccache miss) then hit the clang bug, and only--cleanfixed it.Minimal repro without FastLED: build a PCH from a header that has
#pragma once,touchthe header, then compile a TU that includes it with-include-pch ... -fpch-validate-input-files-content. The compile fails with redefinition errors.Fix
Added
inputs_newer_than(). The skip path inmain()andinvalidate_stale_pch()now both rebuild the PCH when any depfile input is newer than it. Unit tests are inci/tests/test_pch_staleness_guards.py.Validation (local,
.build/meson-quick)touch src/fl/stl/malloc.h, plus an edit to adl_barrier.cpp to force a cache miss.bash test adl_barrierfails with the same malloc.h redefinition errors.PCH inputs changed — removing stale test_pch.h.pch to force rebuildand all tests pass.cmpconfirms the file is byte-identical), plus a forced miss: passes.All tests passed (1/1 cached). Nothing rebuilds, so there is no rebuild loop.pytest ci/tests/test_pch_staleness_guards.py: 12 passed.Cost: touching a header that is in the PCH now costs one PCH rebuild instead of a broken build.
Summary by CodeRabbit