| 1 |
/* Test AAPCS64 layout and __builtin_va_arg. |
| 2 |
|
| 3 |
This test covers a corner case where a composite type parameter fits in one |
| 4 |
register: we do not need a double-word alignment when accessing it in the |
| 5 |
va_arg stack area. */ |
| 6 |
|
| 7 |
/* { dg-do run { target aarch64*-*-* } } */ |
| 8 |
|
| 9 |
#ifndef IN_FRAMEWORK |
| 10 |
#define AAPCS64_TEST_STDARG |
| 11 |
#define TESTFILE "va_arg-17.c" |
| 12 |
#include "type-def.h" |
| 13 |
|
| 14 |
enum E6 { e6_0, e6_1, e6_2, e6_3, e6_65533 = 65533, e6_65534, e6_65535 }; |
| 15 |
typedef enum E6 Tal16E6 __attribute__((aligned (16))); |
| 16 |
typedef unsigned int Tuint; |
| 17 |
|
| 18 |
int fails; |
| 19 |
|
| 20 |
union S2844 { |
| 21 |
Tuint a:((((10) - 1) & 31) + 1); |
| 22 |
Tal16E6 __attribute__((aligned (2), packed)) b:31; |
| 23 |
struct{}c[0]; |
| 24 |
} ; |
| 25 |
union S2844 s2844; |
| 26 |
union S2844 a2844[5]; |
| 27 |
|
| 28 |
#define HAS_DATA_INIT_FUNC |
| 29 |
void init_data () |
| 30 |
{ |
| 31 |
__builtin_memset (&s2844, '\0', sizeof (s2844)); |
| 32 |
__builtin_memset (a2844, '\0', sizeof (a2844)); |
| 33 |
s2844.a = 799U; |
| 34 |
a2844[2].a = 586U; |
| 35 |
} |
| 36 |
|
| 37 |
#include "abitest.h" |
| 38 |
#else |
| 39 |
ARG (int , 1 , W0 , LAST_NAMED_ARG_ID) |
| 40 |
DOTS |
| 41 |
ANON_PROMOTED (float , 1.0f, double, 1.0, D0, 1) |
| 42 |
ANON (union S2844 , s2844 , X1 , 2) |
| 43 |
ANON (long long , 2LL , X2 , 3) |
| 44 |
ANON (union S2844 , a2844[2] , X3 , 4) |
| 45 |
LAST_ANON (union S2844 , a2844[2] , X4 , 5) |
| 46 |
#endif |
| 47 |
|
| 48 |
#if 0 |
| 49 |
/* This test is derived from a case generated by struct-layout-1.exp: */ |
| 50 |
|
| 51 |
enum E6 { e6_0, e6_1, e6_2, e6_3, e6_65533 = 65533, e6_65534, e6_65535 }; |
| 52 |
typedef enum E6 Tal16E6 __attribute__((aligned (16))); |
| 53 |
typedef unsigned int Tuint; |
| 54 |
|
| 55 |
int fails; |
| 56 |
|
| 57 |
union S2844 { |
| 58 |
Tuint a:((((10) - 1) & 31) + 1); |
| 59 |
Tal16E6 __attribute__((aligned (2), packed)) b:31; |
| 60 |
struct{}c[0]; |
| 61 |
} ; |
| 62 |
union S2844 s2844; |
| 63 |
union S2844 a2844[5]; |
| 64 |
|
| 65 |
typedef __builtin_va_list __gnuc_va_list; |
| 66 |
typedef __gnuc_va_list va_list; |
| 67 |
|
| 68 |
void check2844va (int z, ...) { |
| 69 |
union S2844 arg, *p; |
| 70 |
va_list ap; |
| 71 |
|
| 72 |
__builtin_va_start(ap,z); |
| 73 |
if (__builtin_va_arg(ap,double) != 1.0) |
| 74 |
printf ("fail %d.%d\n", 2844, 0), ++fails; |
| 75 |
|
| 76 |
p = &s2844; |
| 77 |
arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ |
| 78 |
if (p->a != arg.a) |
| 79 |
printf ("fail %d.%d\n", 2844, 1), ++fails; |
| 80 |
|
| 81 |
if (__builtin_va_arg(ap,long long) != 3LL) |
| 82 |
printf ("fail %d.%d\n", 2844, 2), ++fails; |
| 83 |
|
| 84 |
p = &a2844[2]; |
| 85 |
arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ |
| 86 |
if (p->a != arg.a) |
| 87 |
printf ("fail %d.%d\n", 2844, 3), ++fails; |
| 88 |
|
| 89 |
arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ |
| 90 |
if (p->a != arg.a) |
| 91 |
printf ("fail %d.%d\n", 2844, 4), ++fails; |
| 92 |
|
| 93 |
__builtin_va_end(ap); |
| 94 |
} |
| 95 |
|
| 96 |
int main (void) { |
| 97 |
int i, j; |
| 98 |
memset (&s2844, '\0', sizeof (s2844)); |
| 99 |
memset (a2844, '\0', sizeof (a2844)); |
| 100 |
s2844.a = 799U; |
| 101 |
a2844[2].a = 586U; |
| 102 |
check2844va (1, 1.0, s2844, 2LL, a2844[2], a2844[2]); |
| 103 |
exit (fails != 0); |
| 104 |
} |
| 105 |
#endif /* 0 */ |