Skip to content

chore(lint): ban decayed C array parameters with clang-query #3233

Closed

Description

@zackees

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 extent

For 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 valid T (&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> value

For 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 recommends T (&value)[N] for ISR / FL_IRAM APIs, or fl::span<T, N> / T (&value)[N] for non-ISR APIs.
  • Update the FastLED code review agent/skill guidance so /code-review and FastLED agents check this explicitly during PR review. The repo-local target is agents/docs/cpp-standards.md, especially the existing fl::span fixed-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] and T 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_IRAM findings recommend T (&value)[N] as the preferred replacement.
  • Non-ISR findings recommend either fl::span<T, N> or T (&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.md and any repo-local /code-review prompt/config, so agent reviews catch the pattern even before the clang-query lint runs.
  • Tests or fixtures cover at least:
    • float out[2] is rejected
    • float out[] is rejected
    • float matrix[2][3] is rejected
    • float (&out)[2] is allowed
    • fl::span<float, 2> out is allowed
    • local float tmp[2] is allowed
    • class member float tmp[2]; is allowed
    • an FL_IRAM function produces the ISR-specific recommendation

Open questions

  • Should this be integrated into ci/lint_cpp_rs, or added beside ci/tools/check_noexcept.py as 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> with FASTLED_FORCE_INLINE FL_IRAM accessors, 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.

Activity

  1. moved this from Triage to Done in FastLED Trackeron Jun 18, 2026
  2. added a commit that references this issue on Jun 19, 2026
    a5715da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions