Repository navigation
feat(safety): overflow-checked signed integer arithmetic (#263) - #289
Merged
Merged
Conversation
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>
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. |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FLOW_CHECKED_ADD/SUB/MULmacros for signed integer+,-,*operations (MISRA Rule 12.1 / CERT INT32-C)__builtin_{add,sub,mul}_overflowon Clang/GCC with portable fallback for other compilersflow_overflow_handler(abort + stderr, overridable viaFLOW_OVERFLOW_HANDLER) on overflow_infer_expr_typeto unwrapmemref_prefix somemref_f32array accesses resolve tof32, not thei32fallbackTest plan
test_arith_safety.py(overflow handler emitted, float excluded, unsigned excluded)2147483647 + 1) triggers handler at runtime100 + 200 * 2 - 50) produces correct resultCloses #263
Generated with Devin