-
Notifications
You must be signed in to change notification settings - Fork 19
Bounds widening for _Nt_array_ptr's #724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Comment from @mgrang: Dataflow equations: Let
|
Comment from @mgrang: Please review this PR as WIP. I am currently testing it out. Will add unit tests soon. |
Comment from @mgrang:
Yes, the goal is ultimately to have a common base. We can do that in a separate clean-up PR. |
Comment from @mgrang: Thanks for your review, David. If we change Gen to be an expression instead of a constant offset how would we compute the intersection of sets? One option is to assign a number to each expression in Gen. Numbers would increase from entry to exit for a particular V. Then to compute intersection we choose the expr with the smaller number. This would represent the LUB of the sets. |
Comment from @mgrang:
Thanks David. I think we still have a complication. Let's say we have a case like: and then we encounter I think a simpler option is to keep the implementation we have now as is, meaning the bounds widened by this algorithm are not relative to the declared upper bound. Instead we "adjust" the widened bounds at the call site of this algorithm. Let's say the widened bounds for If For example:
|
Comment from @dtarditi: I agree it could get complicated quickly. The way we will handle this is by putting expressions in a standard form, such that the constant is on the outside. We already face similar problems when checking bounds declarations. The problem with the approach that you propose is that we cannot handle simple cases like widening bounds of a variable v with bounds(v, v + len). I think it would be appropriate to address additional cases and using standard forms in separate PRs, and finish this PR. How about you add a check that the upper bound is the variable v? This would bring it into agreement with what I am proposing, and let us finish the current PR. |
Comment from @mgrang: < How about you add a check that the upper bound is the variable v? |
Comment from @dtarditi: I am suggesting that in this PR, we only widen bounds for nt_array_ptr variables whose bounds are bounds(v, v) or count(0). I am suggesting that in a future PR, we generalize this to widen bounds for dereferences involving constant offsets from the declared upper bound of a variable. |
Comment from @mgrang: Done. Latest PR widens bounds only when the declared bounds are count(0) or bounds(v, v). Also removed the more generic tests and replaced them with only tests specific to count(0) bounds. |
Comment from @mgrang: ADO Validations Passed: |
This issue was copied from checkedc/checkedc-clang#728
_Nt_array_ptr
's are terminated by a null terminator. If we determine that the dereference of a_Nt_array_ptr
is non-null then we can widen the bounds of the pointer by 1 because there will always be at least the null terminator in the string.Formally we can state the problem as:
∀ p | p ∈ _Nt_array_ptr & bounds(p) = [l, u)
*p != 0 => bounds(p) = [l, u + 1)
Example:
_Nt_array_ptr<char> p : count(0) = "abc"; // bounds = [0, 0]
if (*p) { // bounds = [0, 1) }
The text was updated successfully, but these errors were encountered: