Closed
Description
Description
The C generator has a stdlib_functions set (line 645) that lists C functions whose declarations are skipped (assumed provided by headers). If a Flow program calls a C function not in this set and not declared in an extern block, the generated C may have an implicit function declaration, which is UB in C11 (removed from the standard).
The stdlib_functions set is manually maintained and may be incomplete.
Standards
- MISRA C:2024 Rule 17.3 (Required): Functions shall not be declared implicitly.
- CERT C DCL31-C: Declare identifiers before using them.
Fix
- Verify every function in
stdlib_functionshas a matching#includein the generated C preamble. - Add a codegen check: every function call in generated C must have a visible declaration (either from a header or a Flow-generated prototype).
- Run with
-Wimplicit-function-declaration -Werrorin CI. - Consider generating explicit prototypes for all stdlib functions used, rather than relying on headers.
Audit ID: MISRA-CERT-21
Severity: Medium | Category: C generator - declaration safety
Activity
feat(safety): Phase 2 — certification docs, @safe/@unsafe, analyze
Merge pull request #394 from flooooooooooow/cursor/misra-phase2-b994
godofecht commentedon Aug 10, 2026
Implemented: --profile safety now passes -Werror=implicit-function-declaration to clang, promoting implicit function declarations to a hard error. The stdlib_functions set in c_generator.py controls which C functions have their declarations skipped, and extern blocks require explicit declarations.