BinaryOperatorExpression
's try to handle pointer arithmetic is problematic
#516
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
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:
BinaryOperatorExpression
is essentially incorrect, or at least doesn't correspond to the internal model of how the calculation is represented.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 is0 + 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.The text was updated successfully, but these errors were encountered: