Skip to content

Conversation

@kkjeer
Copy link
Contributor

@kkjeer kkjeer commented Sep 7, 2021

This PR fixes an issue with bounds checking member expressions across multiple assignments.

Consider an example:

struct S {
  int len;
  _Array_ptr<int> p : count(len);
};

void f(struct S *s, _Array_ptr<int> arr : count(3)) {
  s->p = arr, s->len = 3;
}

After the assignment s->p = arr, the observed bounds of s->p are bounds(arr, arr + 3). At the assignment s->len = 3, we synthesize the member expression s->p whose target bounds bounds(s->p, s->p + s->len) use the value of s->len. However, since s->p already has observed bounds recorded in State.ObservedBounds, we do not update the observed bounds of s->p to its target bounds. Therefore, the assignment to s->len does not modify the observed bounds of s->p. At the end of this statement, the observed bounds of s->p are bounds(arr, arr + 3) and we have equality between s->p and arr and between s->len and 3. The observed bounds bounds(arr, arr + 3) imply the target bounds bounds(s->p, s->p + s->len). No errors or warnings are emitted.

kakje added 3 commits September 3, 2021 22:31
…set the observed bounds of A to its target bounds if it does not already have observed bounds recorded
Copy link
Contributor

@sulekhark sulekhark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!


void multiple_assignments2(struct S *s) {
// Observed bounds context after statement: { s->a => bounds(s->a - 1, (s->a - 1) + 2) }
s->a = s->b, s->a++; // expected-warning {{cannot prove declared bounds for 's->a' are valid after increment}} \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: at the assignment s->a++, the observed bounds of the RHS s->a + 1 of the assignment should be bounds(s->b, s->b + 2), not bounds(s->a, s->a + 2). This can be done in a follow-up PR.

@kkjeer kkjeer merged commit 82b7208 into master Sep 7, 2021
@kkjeer kkjeer deleted the member-exprs-multiple-assignments branch September 7, 2021 22:44
sulekhark added a commit that referenced this pull request Sep 8, 2021
sulekhark added a commit that referenced this pull request Sep 8, 2021
* Parsing support for bundled statements.

* Semantic actions to support bundled statements.

* The bundled block functionality as per the Checked C specification.

* Test cases in checkedc-clang repository for bundled block support.

* Added more tests and fixed a minor issue.

* Incorporated review comments.

* Moved test case file to a more appropriate directory.

* Incorporated a missed review comment.

* Removed bounds checking error messages which are no longer expected by virtue of the fix in PR #1181.
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.

3 participants