This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Fix offset calculation off the base pointer with stack realignment and no reserved call frame
Needs ReviewPublic

Authored by ssijaric on May 22 2018, 1:50 PM.

Details

Summary

The offset calculation in ARMFrameLowering::ResolveFrameIndexReference for accessing local variables off a base pointer when both stack realignment and stack adjustment are needed looks to be incorrect. The stack adjustment is added onto the offset from the base pointer, which is already calculated and is fixed.

Compiling the following example (using -mcpu=cortex-a9 -fno-inline-functions) and running it will print out

1 2

instead of

1 1023.

#include <cstdio>

struct A {
  int arr[2000];
};

struct alignas(16) B {
  int val;
};

void bar(int &c, struct A) {
  c = 1023;
}

void init(A &a) {
  for (int i = 0; i < 2000; ++i)
    a.arr[i] = 0;
}

void init(B &b) {
  b.val = 2;
}

int main() {
  struct A big_struct;
  struct B small_struct = {2};
  int val = 1;
  init(big_struct);
  init(small_struct);
  bar(val, big_struct);
  printf("%d %d\n", val, small_struct.val);
  return 0;
}

Diff Detail

Event Timeline

ssijaric created this revision.May 22 2018, 1:50 PM
ssijaric edited the summary of this revision. (Show Details)May 22 2018, 1:52 PM
ssijaric edited the summary of this revision. (Show Details)