Skip to content
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

Correctly widen bounds for exprs not containing addition or multiplication #933

Closed
mgrang opened this issue Nov 4, 2020 · 1 comment · Fixed by #944
Closed

Correctly widen bounds for exprs not containing addition or multiplication #933

mgrang opened this issue Nov 4, 2020 · 1 comment · Fixed by #944
Assignees
Labels
bug This labels issues that are bugs.

Comments

@mgrang
Copy link
Contributor

mgrang commented Nov 4, 2020

Handle the following case in bounds widening:

void f(int i) {
  _Nt_array_ptr<char> p : bounds(p, p - i + 0) = "a";

  if (*(p - i))
  {}
}

We call the function NormalizeExprsWithoutConst which adds 0 constant to expressions not containing an integer constant. But the problem is we only add + 0 to an expression which contains addition and * 1 to an expression which contains multiplication. In the above case, we do not have addition or multiplication in the deref expression. This results in the bounds not getting widened.

The proper fix for this is to always add + 0 to every expression without checking the operator. This 0 constant would anyway be constant folded. So it should not be a problem.

@mgrang mgrang self-assigned this Nov 4, 2020
@mgrang mgrang added the bug This labels issues that are bugs. label Nov 4, 2020
mgrang pushed a commit that referenced this issue Nov 17, 2020
Previously, in order to normalize exprs we added zero only to exprs not
containing any other constants. Also, for binary nodes with + operator we added
+0 and for nodes with * operator we added *1. This resulted in exprs like "p -
i" which do not contain constants but also do not have + or * operator to not
get normalized. So we simply the logic to add zero. Now we simply add a binary
node with the + operator and a 0 child at the root of the AST. This makes the
logic simpler and handles a wider variety of cases.

This fixes issue #933
@mgrang mgrang linked a pull request Nov 17, 2020 that will close this issue
@mgrang
Copy link
Contributor Author

mgrang commented Nov 17, 2020

Fixed in #944

mgrang pushed a commit that referenced this issue Nov 18, 2020
Previously, in order to normalize exprs we added zero only to exprs not
containing any other constants. Also, for binary nodes with + operator we added
+0 and for nodes with * operator we added *1. This resulted in exprs like "p -
i" which do not contain constants but also do not have + or * operator to not
get normalized. So we simply the logic to add zero. Now we simply add a binary
node with the + operator and a 0 child at the root of the AST. This makes the
logic simpler and handles a wider variety of cases.

This fixes issue #933
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This labels issues that are bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant