Skip to content

Simple normalizations for +1/-1 bounds scenarios #1128

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

Merged
merged 22 commits into from
Jul 20, 2021

Conversation

kkjeer
Copy link
Contributor

@kkjeer kkjeer commented Jul 13, 2021

This PR implements some transformation functions to enable the bounds checker to validate some additional bounds.

These normalization functions attempt to express a given upper bound expression as ((E1 + E2) +/- A) +/- B, where E1 has pointer type and A and B are integer constants. The bounds checker can use the variable part E1 + E2 and the constant part A + B to compare bounds expressions.

This enables the bounds checker to validate certain bounds that can arise in bounds widening scenarios. For example:

void f(_Nt_array_ptr<char> p : count(len), unsigned int len) {
  if (*(p + len)) {
    ++len;
  }
}

The bounds checker can express the inferred upper bound (p + (len - 1)) + 1) as ((p + len) - 1) + 1and extract the variable partp + lenand the constant part-1 + 1 == 0. The bounds checker can then use these to prove that the inferred upper bound is equivalent to the declared upper bound p + len`.

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!

Copy link

@mgrang mgrang left a comment

Choose a reason for hiding this comment

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

LGTM.

@kkjeer kkjeer merged commit 446a9be into master Jul 20, 2021
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