Skip to content

fix(ci): rebuild PCH when a header is touched (stale-PCH pragma once redefinitions) - #4839

Merged
zackees merged 1 commit into
masterfrom
fix/pch-mtime-pragma-once
Oct 15, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/pch-mtime-pragma-once

Conversation

@zackees

@zackees zackees commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

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-content accepts 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 once does not stop the second include and the header is parsed again. You get malloc.h:20:36: error: template parameter redefines default argument and redefinition of 'malloc'.

ci/compile_pch.py skipped 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 --clean fixed it.

Minimal repro without FastLED: build a PCH from a header that has #pragma once, touch the 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 in main() and invalidate_stale_pch() now both rebuild the PCH when any depfile input is newer than it. Unit tests are in ci/tests/test_pch_staleness_guards.py.

Validation (local, .build/meson-quick)

  • Old code: touch src/fl/stl/malloc.h, plus an edit to adl_barrier.cpp to force a cache miss. bash test adl_barrier fails with the same malloc.h redefinition errors.
  • New code, same steps: it prints PCH inputs changed — removing stale test_pch.h.pch to force rebuild and all tests pass.
  • Appended and then removed a line in malloc.h (cmp confirms the file is byte-identical), plus a forced miss: passes.
  • A real content change to malloc.h: the PCH is rebuilt and the test passes.
  • Running again with no changes prints 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

  • Bug Fixes
    • Fixed cases where cached precompiled headers could be reused after their source inputs changed, leading to outdated or incorrect builds.
    • Builds now refresh the precompiled header when an input is newer or cannot be checked.

…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.
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: FastLED/FastLED/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 12ad7014-4f70-4104-8213-cff1e3d553a4
📥 Commits

Reviewing files that changed from the base of the PR and between abf9463 and efdd9ec.

📒 Files selected for processing: 2
  • ci/compile_pch.py
  • ci/tests/test_pch_staleness_guards.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

PCH reuse now requires matching input hashes and input timestamps that are not newer than the PCH. The compile path removes stale PCH files or recompiles when either check fails. Tests cover older inputs, newer inputs, and missing inputs.

Changes: PCH staleness checks

Layer / File(s) Summary
Timestamp-based PCH invalidation
ci/compile_pch.py, ci/tests/test_pch_staleness_guards.py
inputs_newer_than reports newer or unstatable inputs. Stale-PCH invalidation and the compile cache use this check alongside hash comparisons. Tests cover older, newer, and missing inputs.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to efdd9

The precompiled header is now rebuilt whenever an input header is newer than it. This prevents stale-PCH redefinition errors, and the only cost is an occasional extra rebuild. No concrete merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: rebuilding the PCH when a header is touched to prevent stale-PCH pragma once redefinitions.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit 55909ef into master Oct 15, 2026
119 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Oct 15, 2026
@zackees
zackees deleted the fix/pch-mtime-pragma-once branch October 15, 2026 23:32
zackees added a commit that referenced this pull request Oct 16, 2026
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant