Handle non-byte-sized array element types in bounds_check_index#8843
Handle non-byte-sized array element types in bounds_check_index#8843tautschnig wants to merge 1 commit intodiffblue:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes a crash in bounds_check_index that occurs when checking bounds for arrays with element types that have no computable byte size, such as arrays of __CPROVER_integer (mathematical integers) or unbounded arrays used in heap models.
The crash occurred because object_descriptor_exprt::build calls size_of_expr on the element type, and when that returns std::nullopt, the resulting ID_unknown offset causes a precondition violation in from_integer downstream.
Changes:
- Modified
bounds_check_indexto check if the element type has a computable size before building the object descriptor - Introduced a simplified index-based lower-bound check when element size is unavailable
- Wrapped
object_descriptor_exprtinstd::optionalto conditionally build and use it - Added defensive
DATA_INVARIANTto catch unexpected array expression types with unsized elements - Added regression test for arrays with mathematical integer element types
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/ansi-c/goto-conversion/goto_check_c.cpp | Modified bounds_check_index to handle unsized array element types with conditional object descriptor building and simplified bounds checks |
| regression/cbmc/bounds_check_integer_index1/main.c | Added test case with __CPROVER_integer array to verify bounds checking doesn't crash |
| regression/cbmc/bounds_check_integer_index1/test.desc | Test configuration verifying both lower and upper bound checks are generated |
| regression/validate-trace-xml-schema/check.py | Registered new test in validation exclusion list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3b0c6d1 to
1a1502c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8843 +/- ##
===========================================
+ Coverage 80.01% 80.03% +0.02%
===========================================
Files 1700 1700
Lines 188342 188376 +34
Branches 73 73
===========================================
+ Hits 150710 150776 +66
+ Misses 37632 37600 -32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I would change the terminology from "unsized" to "dynamically sized". These arrays do have a size, it's just not a constant. |
Hmm, when the element type is |
If you mean the index type (not element type), then simply call them "unbounded"? |
1a1502c to
add1701
Compare
No, this genuinely is about the element type. I have updated both the title and the commit message (and PR description) to use the term "non-byte-sized". |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
add1701 to
1982f1d
Compare
When the array element type has no byte size (e.g., arrays of __CPROVER_integer), object_descriptor_exprt::build cannot compute byte offsets. Fall back to a simple index-based lower-bound check instead of crashing. The upper bound check uses the array size directly and does not require byte offsets. A DATA_INVARIANT ensures that arrays with non-byte-sized element types are not accessed via pointer dereference, making explicit the assumption that these arise only from internal modeling constructs. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
1982f1d to
b796cbc
Compare
When the array element type has no byte size (e.g., arrays of __CPROVER_integer), object_descriptor_exprt::build cannot compute byte offsets. Fall back to a simple index-based lower-bound check instead of crashing. The upper bound check uses the array size directly and does not require byte offsets.
A DATA_INVARIANT ensures that arrays with non-byte-sized element types are not accessed via pointer dereference, making explicit the assumption that these arise only from internal modeling constructs.
Co-authored-by: Kiro kiro-agent@users.noreply.github.com