| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target hwaddress_exec } */ |
| 3 |
/* { dg-shouldfail "hwasan" } */ |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
|
| 7 |
/* Testing that a function with outgoing arguments correctly decrements the |
| 8 |
stack pointer when a vararray goes out of scope. */ |
| 9 |
|
| 10 |
const char * |
| 11 |
other (int argc, int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) |
| 12 |
{ |
| 13 |
const char ** other; |
| 14 |
{ |
| 15 |
const char * test_array[argc]; |
| 16 |
test_array[0] = "test string"; |
| 17 |
test_array[argc - 1] = "hello"; |
| 18 |
/* To prevent optimisation. */ |
| 19 |
printf("While the value stored in our test_array is: %s\n", |
| 20 |
test_array[argc - 1]); |
| 21 |
other = test_array; |
| 22 |
} |
| 23 |
/* With the below function call (the one with many arguments), some of the |
| 24 |
arguments have to be put on the stack, which means we have to reserve some |
| 25 |
space on the stack for these arguments and that the VLA is stored at a |
| 26 |
position that is not the stack pointer. */ |
| 27 |
printf("Hello there!\nOur numbers today are: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", |
| 28 |
a, b, c, d, e, f, g, h, i, j, k, l); |
| 29 |
/* This should fail due to a bad read access. */ |
| 30 |
return other[0]; |
| 31 |
} |
| 32 |
|
| 33 |
int |
| 34 |
main () |
| 35 |
{ |
| 36 |
int a, b, c, d, e, f, g, h, i, j, k, l; |
| 37 |
const char * retval = other (1, a, b, c, d, e, f, g, h, i, j, k, l); |
| 38 |
/* Numbers don't matter here, just want to ensure the program is reading them |
| 39 |
so we know they won't be optimised out. */ |
| 40 |
if (retval) |
| 41 |
return 1; |
| 42 |
return 10; |
| 43 |
} |