-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Assembly generated for the following code does not currently produce consistent offsets for variable i which is stored after the dynamic array int array[] on the stack.
int i = 0;
int f() { return i++; }
int main() {
int array[f()];
int i;
// ...
}Issue is that the offset of variable is recalculated every time it is referenced and the offset of i is dependent on the size of array[]. And in this case the array's size was calculated from the result of function f() which returns different values for each call. Thus the first time i is referenced it will be 4 bytes lower in the stack than the second time.
Possible solution is to calculate the dynamic array once and embed the size on the stack in front of the array space. Then each subsequent reference to later variables in the stack (e.g. i in the above example) would use the value stored on the stack to calculate the size of dynamic or static sized arrays.