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

BinaryOperatorExpression's try to handle pointer arithmetic is problematic #516

Open
ForNeVeR opened this issue Jan 16, 2024 · 0 comments
Open
Labels
area:compiler Related to code compilation or type checking good-first-issue An issue considered simple enough for new contributors kind:bug Something isn't working status:help-wanted Open for contributors

Comments

@ForNeVeR
Copy link
Owner

ForNeVeR commented Jan 16, 2024

In BinaryOperatorExpression::LowerPointerArithmetics, we are trying to essentially multiply the pointer operands by pointer size. Note that the expressions still keep the same pointer type.

This means that:

  1. Initial arithmetics that's getting into the BinaryOperatorExpression is essentially incorrect, or at least doesn't correspond to the internal model of how the calculation is represented.
  2. Lower().Lower() called twice on the same node would give incorrect results, since it'd lower the pointer arithmetics twice.

For example, let's consider that we are lowering the expression of (int*)0 + 4. In C's pointer arithmetic, this means that the result is 0 + 4 * sizeof(int*).

BinaryOperatorExpression::LowerPointerArithmetics essentially converts this to (int*)0 + sizeof(int*) * 4, which looks correct w.r.t. runtime code gen (.NET runtime doesn't do any pointer arithmetics under the cover), but doesn't change the types of the arguments, which is not how it should work.

Please see the code marked by number 516 in the compiler code, and fix that, either by introducing some new model, or removing this lowering somewhere else.

@ForNeVeR ForNeVeR added kind:bug Something isn't working status:help-wanted Open for contributors area:compiler Related to code compilation or type checking good-first-issue An issue considered simple enough for new contributors labels Jan 16, 2024
ForNeVeR added a commit that referenced this issue Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:compiler Related to code compilation or type checking good-first-issue An issue considered simple enough for new contributors kind:bug Something isn't working status:help-wanted Open for contributors
Projects
None yet
Development

No branches or pull requests

1 participant