diff options
author | Wilco Dijkstra <wdijkstr@arm.com> | 2017-09-06 16:34:54 +0000 |
---|---|---|
committer | Wilco Dijkstra <wilco@gcc.gnu.org> | 2017-09-06 16:34:54 +0000 |
commit | 260da991920f7cd05a38216e19894882a359362b (patch) | |
tree | 72e5ed596ac4dba29645a91623384eb83e335fab | |
parent | 4a40b308ef56696a3a33dc8dc8bce31895681897 (diff) | |
download | gcc-260da991920f7cd05a38216e19894882a359362b.zip gcc-260da991920f7cd05a38216e19894882a359362b.tar.gz gcc-260da991920f7cd05a38216e19894882a359362b.tar.bz2 |
PR78468 - add alloca alignment test
Add an alignment test to check that aligned alloca's really do get
correctly aligned. Some targets may not ensure SP is always a multiple
of STACK_BOUNDARY (particularly with outgoing arguments), which means
aligned alloca does not get correctly aligned. This can be fixed either
by aligning the outgoing arguments or setting STACK_BOUNDARY correctly.
testsuite/
PR middle-end/78468
* gcc.dg/pr78468.c: Add alignment test.
From-SVN: r251811
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr78468.c | 102 |
2 files changed, 107 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cd283c0..3b850fb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-09-06 Wilco Dijkstra <wdijkstr@arm.com> + + PR middle-end/78468 + * gcc.dg/pr78468.c: Add alignment test. + 2017-09-06 Wish Wu <wishwu007@gmail.com> Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/testsuite/gcc.dg/pr78468.c b/gcc/testsuite/gcc.dg/pr78468.c new file mode 100644 index 0000000..a882d9a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr78468.c @@ -0,0 +1,102 @@ +/* { dg-do run } */ +/* { dg-require-effective-target alloca } */ +/* { dg-options "-O2 -fno-inline" } */ + +/* Test that targets correctly round the size of the outgoing arguments + to a multiple of STACK_BOUNDARY. There is a serious alignment bug if + aligned alloca does not get aligned! */ + +__extension__ typedef __UINTPTR_TYPE__ uintptr_t; +extern void abort (void); + +volatile int xx; +volatile int x = 16; + +void +t1 (int x0, int x1, int x2, int x3, int x4, int x5, int x6, int x7, + void *p, int align) +{ + xx = x0 + x1 + x2 + x3 + x4 + x4 + x6 + x7; + if ((int)(uintptr_t)p & (align-1)) + abort (); +} + +void +t2 (int x0, int x1, int x2, int x3, int x4, int x5, int x6, int x7, + void *p, int align, int dummy) +{ + xx = x0 + x1 + x2 + x3 + x4 + x4 + x6 + x7; + if ((int)(uintptr_t)p & (align-1)) + abort (); +} + +void +t1_a4 (int size) +{ + void *p = __builtin_alloca_with_align (size, 32); + t1 (0, 0, 0, 0, 0, 0, 0, 0, p, 4); +} + +void +t2_a4 (int size) +{ + void *p = __builtin_alloca_with_align (size, 32); + t2 (0, 0, 0, 0, 0, 0, 0, 0, p, 4, 0); +} + +void +t1_a8 (int size) +{ + void *p = __builtin_alloca_with_align (size, 64); + t1 (0, 0, 0, 0, 0, 0, 0, 0, p, 8); +} + +void +t2_a8 (int size) +{ + void *p = __builtin_alloca_with_align (size, 64); + t2 (0, 0, 0, 0, 0, 0, 0, 0, p, 8, 0); +} + +void +t1_a16 (int size) +{ + void *p = __builtin_alloca_with_align (size, 128); + t1 (0, 0, 0, 0, 0, 0, 0, 0, p, 16); +} + +void +t2_a16 (int size) +{ + void *p = __builtin_alloca_with_align (size, 128); + t2 (0, 0, 0, 0, 0, 0, 0, 0, p, 16, 0); +} + +void +t1_a32 (int size) +{ + void *p = __builtin_alloca_with_align (size, 256); + t1 (0, 0, 0, 0, 0, 0, 0, 0, p, 32); +} + +void +t2_a32 (int size) +{ + void *p = __builtin_alloca_with_align (size, 256); + t2 (0, 0, 0, 0, 0, 0, 0, 0, p, 32, 0); +} + + +int +main () +{ + t1_a4 (x); + t2_a4 (x); + t1_a8 (x); + t2_a8 (x); + t1_a16 (x); + t2_a16 (x); + t1_a32 (x); + t2_a32 (x); + return 0; +} |