| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target hwaddress_exec } */ |
| 3 |
|
| 4 |
/* Alloca is given a different tag to other variables. |
| 5 |
vararray should behave in the same way. */ |
| 6 |
|
| 7 |
#define alloca __builtin_alloca |
| 8 |
#define assert(x) if (!(x)) __builtin_abort () |
| 9 |
|
| 10 |
struct two_values { |
| 11 |
int left; |
| 12 |
int right; |
| 13 |
}; |
| 14 |
|
| 15 |
/* Require default hwasan tag ABI. |
| 16 |
Know we're using AArch64 since that's the only architecture we run hwasan |
| 17 |
tests on. */ |
| 18 |
char tag_of (void * x) { return ((unsigned long long)x) >> 56; } |
| 19 |
|
| 20 |
int __attribute__ ((noinline)) |
| 21 |
alloca_different_tag (int num) |
| 22 |
{ |
| 23 |
struct two_values tmp_object = { |
| 24 |
.left = 100, |
| 25 |
.right = num, |
| 26 |
}; |
| 27 |
int *big_array = (int *)alloca (num * sizeof (int)); |
| 28 |
int other_array[100]; |
| 29 |
|
| 30 |
char first_tag = tag_of (&tmp_object); |
| 31 |
char second_tag = tag_of (big_array); |
| 32 |
char other_tag = tag_of (other_array); |
| 33 |
assert (first_tag != second_tag); |
| 34 |
assert (second_tag != other_tag); |
| 35 |
assert (first_tag != other_tag); |
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
int __attribute__ ((noinline)) |
| 40 |
vararray_different_tag (int num) |
| 41 |
{ |
| 42 |
struct two_values tmp_object = { |
| 43 |
.left = 100, |
| 44 |
.right = num, |
| 45 |
}; |
| 46 |
int big_array[num]; |
| 47 |
int other_array[100]; |
| 48 |
|
| 49 |
char first_tag = tag_of (&tmp_object); |
| 50 |
char second_tag = tag_of (big_array); |
| 51 |
char other_tag = tag_of (other_array); |
| 52 |
assert (first_tag != second_tag); |
| 53 |
assert (second_tag != other_tag); |
| 54 |
assert (first_tag != other_tag); |
| 55 |
return 0; |
| 56 |
} |
| 57 |
|
| 58 |
int __attribute__ ((noinline)) |
| 59 |
main () |
| 60 |
{ |
| 61 |
alloca_different_tag (10); |
| 62 |
vararray_different_tag (8); |
| 63 |
return 0; |
| 64 |
} |
| 65 |
|