Skip to content

feat(safety): safety manifest generator (--emit-manifest) - #290

Merged
godofecht merged 3 commits into
mainfrom
safety-manifest
Aug 10, 2026
Merged

godofecht merged 3 commits into
mainfrom
safety-manifest

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Summary

  • New --emit-manifest flag emits a structured safety compliance report to stderr
  • Collects facts from AST, type checker, and C generator into a unified manifest
  • Three categories: PROVEN, REJECTED, REQUIRES EVIDENCE
  • Call graph analysis: recursion detection, heap usage propagation, RT-safe verification
  • Properties: overflow, div0, shift UB, RT-safety, dynamic allocation, recursion, loops, null deref
  • Output formats: text (default) and JSON (--manifest-format json)

Example

$ FLOW_PROFILE=safety flow transpile program.flow --c --emit-manifest -o program.c

Flow Safety Manifest
============================================================
Source:    program.flow
Profile:   safety
Functions: 4

Properties
------------------------------------------------------------
  Integer overflow                    PROVEN             MISRA 12.1 / CERT INT32-C
  Division by zero                    PROVEN             MISRA 12.5 / CERT INT33-C
  Shift undefined behaviour           PROVEN             MISRA 12.2 / CERT INT34-C
  RT-safety                           PROVEN             Flow @rt_safe policy
  Dynamic allocation                  REQUIRES EVIDENCE  MISRA 21.3
  Unbounded recursion                 REQUIRES EVIDENCE  MISRA 17.2
  Unbounded loops                     PROVEN             MISRA 17.4
  Null pointer dereference            REQUIRES EVIDENCE  MISRA 11.8 / CERT ERR33-C

Summary
------------------------------------------------------------
  Proven:            5
  Rejected:          0
  Requires evidence: 3
  Deviations:        0

Test plan

  • 13 unit tests in test_safety_manifest.py
  • All 1189 unit tests pass
  • Ruff lint clean
  • Manifest correctly detects recursion, heap usage, RT-safety
  • JSON format valid
  • CI passes

Generated with Devin

godofecht and others added 3 commits August 10, 2026 09:58
MISRA Phase 1: emit FLOW_CHECKED_ADD/SUB/MUL macros for signed integer
+,-,* operations. Uses __builtin_{add,sub,mul}_overflow on Clang/GCC
with a portable fallback for other compilers. Calls flow_overflow_handler
(abort + stderr message, overridable via FLOW_OVERFLOW_HANDLER) on trap.

Float and unsigned arithmetic are excluded: float overflow is IEEE
(Inf/NaN, not UB), unsigned wraparound is well-defined modular arithmetic.

Also fixes _infer_expr_type to unwrap memref_ prefix so memref_f32 array
accesses resolve to f32, not the i32 fallback.

Closes #263

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Overflow-checked +,-,* broke existing tests and the flowc self-host
roundtrip because the macros were always emitted. Now they only appear
under FLOW_PROFILE=safety/flight or FLOW_OVERFLOW_CHECK=1, matching
the -Werror pattern from MISRA Phase 0.

- Add overflow_check parameter to CGenerator and flow_to_c
- Auto-enable from FLOW_PROFILE env var
- Move FLOW_CHECKED_ADD/SUB/MUL macros and flow_overflow_handler
  inside the overflow_checks_enabled guard
- Add test_default_profile_no_overflow_check
- Update existing overflow tests to use _c_overflow helper

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Add `flow transpile --c --emit-manifest` that collects safety facts
from the AST, type checker, and C generator into a structured
compliance report. The manifest has three categories per the safety
profile design: PROVEN, REJECTED, REQUIRES EVIDENCE.

Properties reported:
- Integer overflow (MISRA 12.1 / CERT INT32-C)
- Division by zero (MISRA 12.5 / CERT INT33-C)
- Shift UB (MISRA 12.2 / CERT INT34-C)
- RT-safety / @rt_safe call graph (Flow policy)
- Dynamic allocation (MISRA 21.3)
- Unbounded recursion (MISRA 17.2)
- Unbounded loops (MISRA 17.4)
- Null pointer dereference (MISRA 11.8 / CERT ERR33-C)

Call graph analysis detects:
- Recursive functions (cycle detection via DFS)
- Heap-using functions (fixed-point propagation from malloc/calloc/etc)
- RT-safe function verification (transitive banned-API reachability)

Output formats: text (default) and JSON (--manifest-format json).
Manifest goes to stderr so stdout stays clean for C output.

13 unit tests in test_safety_manifest.py covering recursion, heap,
loops, RT-safety, overflow, div0, text/JSON output.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@cursor

cursor Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@godofecht
godofecht merged commit e612d0a into main Aug 10, 2026
15 checks passed
@godofecht
godofecht deleted the safety-manifest branch August 10, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant