aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/aligned.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2019-02-15 10:57:54 +0100
committerXavier Leroy <xavierleroy@users.noreply.github.com>2019-02-25 17:15:36 +0100
commit4fb8df8cd1df4552e937d02fa78fc4993af81e63 (patch)
tree512eb6f4a383243ea372b9729cc7776998851cfb /test/regression/aligned.c
parenteec6d60b5fa43fa8cf011747d6b98322dcdaaae8 (diff)
downloadcompcert-kvx-4fb8df8cd1df4552e937d02fa78fc4993af81e63.tar.gz
compcert-kvx-4fb8df8cd1df4552e937d02fa78fc4993af81e63.zip
Revised attachment of name attributes to structs, unions, enums
Consider: ``` struct s { ... } __attribute((aligned(N))); struct t { ... } __attribute((aligned(N))) struct t x; ``` In the first case, the aligned attribute should be attached to struct s, so that further references to struct s are aligned. In the second case, the aligned attribute should be attached to the variable x, because if we attach it to struct t, it will be ignored and cause a warning. This commit changes the attachment rule so that it treats both cases right. Extend regression test for "aligned" attribute accordingly, by testing aligned attribute applied to a name of struct type.
Diffstat (limited to 'test/regression/aligned.c')
-rw-r--r--test/regression/aligned.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/regression/aligned.c b/test/regression/aligned.c
index 3b5a9374..bd16d513 100644
--- a/test/regression/aligned.c
+++ b/test/regression/aligned.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#define ALIGNED __attribute((aligned(16)))
+#define ALIGNED1 __attribute((aligned(1)))
typedef ALIGNED char c16;
@@ -72,6 +73,10 @@ typedef T2 T3[];
typedef struct { T3 *area; } T4;
/* Expected: size of a pointer, alignment of a pointer */
+struct t1 { double d; };
+struct t2 { char c; ALIGNED1 struct t1 d; };
+/* Expected: size = 1 + 8, alignment 1 */
+
void check(const char * msg, void * addr, size_t sz)
{
printf("%s: size %zu, offset mod 16 = %lu\n",
@@ -104,5 +109,7 @@ int main()
sizeof(T4) == sizeof(void *) ? "is" : "IS NOT",
_Alignof(T4) == _Alignof(void *) ? "is" : "IS NOT");
+ printf("t2: size %zu, alignment %zu\n",
+ sizeof(struct t2), _Alignof(struct t2));
return 0;
}