Skip to content

Get variable and constant from upper bounds#1135

Merged
kkjeer merged 33 commits into
masterfrom
get-variable-and-constant
Jul 24, 2021
Merged

Get variable and constant from upper bounds#1135
kkjeer merged 33 commits into
masterfrom
get-variable-and-constant

Conversation

@kkjeer

@kkjeer kkjeer commented Jul 22, 2021

Copy link
Copy Markdown
Contributor

This PR adds a GetVariableAndConstant method to NormalizeUtil in order to compare two upper bound expressions. This enables the bounds checker to validate bounds that have been widened multiple times.

For example:

void f(_Nt_array_ptr<char> p : count(len), unsigned int len) {
  if (*(p + len)) {
    if (*(p + len + 1)) {
      // Widened bounds before increment: bounds(p, ((p + len) + 1) + 1)
      // Inferred bounds after increment: bounds(p, (((p + (len - 1)) + 1)) + 1)
     ++len;
    }
  }
}

GetVariableAndConstant separates an input expression E into a pointer-typed expression E1 and an integer constant C for as long as possible. It adds up each constant found this way and, if the result does not overflow, sets the out parameter Constant to the result of adding up all the constants and sets the out parameter Variable to the final pointer-typed subexpression of E.

kakje added 30 commits July 7, 2021 15:53
…dths methods from BaseRange and call utility methods instead

@sulekhark sulekhark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you!

@mgrang mgrang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM.

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