Repository navigation
Description
Context
C++ function parameters spelled as fixed arrays do not preserve their extent:
inline void cct_to_xy(int cct, float out[2]) FL_NOEXCEPT;This is adjusted by the language to a pointer parameter, so out[2] documents intent but does not enforce that callers pass a 2-element array. FastLED currently has examples of this pattern, including const float white_xy[2] in src/FastLED.h.
We want fixed-size output buffers to express their size in the actual type:
void f(float (&out)[2]) FL_NOEXCEPT; // ISR-safe, compile-time extent
void f(fl::span<float, 2> out) FL_NOEXCEPT; // general API, compile-time extentFor ISR / FL_IRAM callgraphs, prefer array references. Current fl::span<T, N> is header-inline and FL_NOEXCEPT, but its methods are not explicitly FASTLED_FORCE_INLINE or FL_IRAM, so using it in ISR paths can still risk an out-of-line flash call if optimization/codegen does not inline the wrapper.
The existing regex-based C++ linter is not a good fit for this rule because it must distinguish:
- function parameters from local arrays, fields, globals, and expressions
T out[N]from validT (&out)[N]- declarations, definitions, templates, member functions, and macro-adjacent signatures
- ISR-marked APIs from ordinary APIs
FastLED already has clang-query precedent in ci/tools/check_noexcept.py, and ci/docs/fbuild-static-analysis-research.md documents clang-tool-chain-query / compile database support.
Proposal
Add an AST-backed lint that detects decayed C array parameters in FastLED-owned C++ APIs.
The lint should flag function parameters originally spelled like:
T value[N]
T value[]
const T value[N]
T value[N][M]The lint should allow:
T (&value)[N]
const T (&value)[N]
fl::span<T, N> valueFor FL_IRAM / ISR-marked functions, the lint should recommend array reference output parameters, not fl::span, unless a future explicitly ISR-safe span type is introduced.
Suggested diagnostic:
Function parameter 'out[2]' decays to a pointer; the size is not enforced.
Use 'T (&out)[2]' for ISR-safe fixed output, or 'fl::span<T, 2>' for non-ISR APIs.
Suppress with '// ok array parameter' only for C ABI/platform compatibility.
Implementation should use clang-query or clang tooling AST matchers, not a broad text regex. The likely matcher target is parmVarDecl whose original/source-spelled type is an array parameter, with filtering for FastLED-owned source locations.
Reviewer guidance updates
The implementation should also teach the review surfaces that catch these patterns before CI or human review:
- Add this rule to CodeRabbit review instructions/config so CodeRabbit flags
T value[N]/T value[]function parameters and recommendsT (&value)[N]for ISR /FL_IRAMAPIs, orfl::span<T, N>/T (&value)[N]for non-ISR APIs. - Update the FastLED code review agent/skill guidance so
/code-reviewand FastLED agents check this explicitly during PR review. The repo-local target isagents/docs/cpp-standards.md, especially the existingfl::spanfixed-size array guidance, plus any code-review prompt/config that consumes those standards. - Keep CodeRabbit and agent guidance aligned with the lint diagnostic so reviewers, bots, and CI recommend the same replacements and the same suppression policy.
Acceptance criteria
- A new CI lint check detects
T value[N]andT value[]function parameters in FastLED-owned C++ sources. - The check does not flag local arrays, member fields, globals, array references, or
fl::span<T, N>parameters. - The check handles declarations and definitions, including multi-line signatures.
- ISR /
FL_IRAMfindings recommendT (&value)[N]as the preferred replacement. - Non-ISR findings recommend either
fl::span<T, N>orT (&value)[N]. - A suppression comment exists for intentional C ABI/platform cases, e.g.
// ok array parameter. - Existing known violations are either fixed or captured in a checked-in baseline/ratchet so new violations fail CI.
- CodeRabbit review instructions/config are updated to flag decayed fixed-size array parameters with the same ISR vs non-ISR replacement policy.
- FastLED code review agent/skill guidance is updated, including
agents/docs/cpp-standards.mdand any repo-local/code-reviewprompt/config, so agent reviews catch the pattern even before the clang-query lint runs. - Tests or fixtures cover at least:
float out[2]is rejectedfloat out[]is rejectedfloat matrix[2][3]is rejectedfloat (&out)[2]is allowedfl::span<float, 2> outis allowed- local
float tmp[2]is allowed - class member
float tmp[2];is allowed - an
FL_IRAMfunction produces the ISR-specific recommendation
Open questions
- Should this be integrated into
ci/lint_cpp_rs, or added besideci/tools/check_noexcept.pyas a second clang-query based Python lint? - Should the first landing use a baseline ratchet, or should it fix all current FastLED-owned violations immediately?
- Do we want a future
fl::isr::span<T, N>/fl::fixed_span<T, N>withFASTLED_FORCE_INLINE FL_IRAMaccessors, or should ISR APIs permanently use array references? - Where does the authoritative CodeRabbit instruction live for this repo if it is not checked in today? If it is external-only, the implementation should document that and update the available checked-in review guidance instead.
My recommended answers: put the clang-query runner beside ci/tools/check_noexcept.py, use a baseline ratchet for the first landing, keep ISR APIs on array references unless/until an explicitly ISR-safe span type exists, and update the checked-in FastLED agent docs even if CodeRabbit itself is configured outside this repository.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
chore(lint): ban decayed array parameters