Skip to content

[MISRA-CERT-21] Implicit function declarations possible via extern (MISRA Rule 17.3) #283

Closed

Description

@godofecht

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

  1. Verify every function in stdlib_functions has a matching #include in the generated C preamble.
  2. Add a codegen check: every function call in generated C must have a visible declaration (either from a header or a Flow-generated prototype).
  3. Run with -Wimplicit-function-declaration -Werror in CI.
  4. 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

  1. added
    MISRA
    CERT
    on Aug 9, 2026
  2. added 2 commits that reference this issue on Aug 10, 2026
  3. godofecht commented on Aug 10, 2026

    @godofecht
    ContributorAuthor

    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.

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

    CERTMISRAcompilersecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions