[PATCH] D47227: [ARM] Fix offset calculation off the base pointer with stack realignment and no reserved call frame

Sanjin Sijaric via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 13:50:08 PDT 2018


ssijaric created this revision.
ssijaric added reviewers: MatzeB, t.p.northover.
Herald added a reviewer: javed.absar.
Herald added subscribers: chrib, kristof.beyls.

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.

- test start -------------

#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;

}

- test end ------


Repository:
  rL LLVM

https://reviews.llvm.org/D47227

Files:
  lib/Target/ARM/ARMFrameLowering.cpp
  test/CodeGen/ARM/alloca-align.ll
  test/CodeGen/ARM/stack_align_with_base_register.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47227.148058.patch
Type: text/x-patch
Size: 5843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180522/d2856ecc/attachment.bin>


More information about the llvm-commits mailing list