Skip to content

lint: exhaustive libc-name rule for fl:: mirrors (supersedes #4832) #4834

Closed

Description

@zackees

Problem

#4830 fixed the libc ambiguity from #4827 by making every fl:: copy of a libc function a template that loses ties to libc. Each wrapper looks like this:

template <typename FlLibcTag = void>
FASTLED_FORCE_INLINE void* memcpy(void* d, const void* s, size_t n) FL_NO_EXCEPT { return libc_impl::memcpy(d, s, n); }

Nothing enforces that pattern. If someone adds a plain, non-template fl::strdup (or any other libc name), an unqualified strdup(...) call with a CRGB* or other fl type argument is ambiguous again. tests/fl/stl/adl_barrier.cpp only covers names that exist today.

#4833 (the -76 B follow-up) also showed that the wrapper must be FASTLED_FORCE_INLINE. With plain inline, GCC on ESP32-S3 emitted out-of-line clones (+98 B).

Goal

Add a lint rule that fails whenever the pattern is broken, for any libc name. Once it lands, #4832 (rename to fl_memcpy) is superseded and can be closed.

Requirements

  1. A complete, fixed list of reserved names, kept as a table in ci/lint_cpp_rs/src/lint_core/:

    • every function in C11 <string.h>, <stdlib.h> and <strings.h>;
    • POSIX and newlib/glibc extras: strdup, strndup, strnlen, strcasecmp, strncasecmp, memccpy, mempcpy, bzero, bcopy, bcmp, index, rindex, strlcpy, strlcat, strtok_r, strerror_r, posix_memalign, memalign, reallocarray, strtoll, strtoull, strtof, strtold, atoll, abort, exit, setenv, unsetenv, srand, bsearch, etc.

    The list must not be derived from the names fl currently has.

  2. Declaration check (new checker in ci/lint_cpp_rs/src/checkers/, modelled on bare_legacy.rs):

    • Applies to every function declared or defined inside namespace fl or any sub-namespace, in src/**.
    • If the name is on the list, it must be preceded by template <typename FlLibcTag = void> and declared FASTLED_FORCE_INLINE.
    • The checker must handle multi-line signatures, attribute and inline macros, static, constexpr, and extern "C" blocks.
  3. Exemptions:

    • the implementation namespace fl::libc_impl (declarations in the headers, definitions in *.cpp.hpp);
    • global-scope platform shims (newlib stubs and the like), because they are not in fl.

    There is no per-file allowlist: an exemption has to be a namespace rule, not a path.

  4. Compile back-stop: extend tests/fl/stl/adl_barrier.cpp to call every wrapper in fl/stl/cstring.h, malloc.h and cstdlib.h unqualified, with a CRGB* or fl:: type argument, under no using-directive and under a using-directive for fl. That catches anything the text-based linter misses.

  5. Red-to-green evidence: linter tests (lint_core/tests_checkers.rs) that fail on:

    • a plain inline mirror;
    • a template wrapper missing FASTLED_FORCE_INLINE;
    • a mirror in a sub-namespace such as fl::detail;
    • a multi-line declaration.

    They must also pass on the current headers and on libc_impl.

Out of scope

  • Math functions (abs, sqrt, sin, …) take arithmetic types, so argument-dependent lookup never reaches fl.
  • printf and snprintf take const char*, so the same applies.
  • std::-colliding generics (swap, sort, move, begin, …) are handled by fl::adl_barrier from fix: CRGB and other fl types no longer make libc/std calls ambiguous (#4827) #4830. A matching rule that requires each overload of a barrier name to stay inside the barrier could be a follow-up.

Done when

  • bash lint enforces the rule on master with no allowlist entries.
  • The negative tests above fail as expected.
  • glibc lint for c++ #4832 is closed as superseded.

Refs #4827, #4830, #4832, #4833.

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