aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorCyril SIX <cyril.six@kalray.eu>2019-03-13 13:07:24 +0100
committerCyril SIX <cyril.six@kalray.eu>2019-03-13 13:07:24 +0100
commit41c895850f75e3084fc8efdb7c9b1f7c8ec4fa5d (patch)
tree3126fa4af7ba97dbc4f4f841a81820c95a2e35a3 /test
parent8f972659841ad38f6f548161b5ca3cfcbdd135cb (diff)
parent72ba1c282e2a8bfd0e826352a251fa71bfb71e05 (diff)
downloadcompcert-kvx-41c895850f75e3084fc8efdb7c9b1f7c8ec4fa5d.tar.gz
compcert-kvx-41c895850f75e3084fc8efdb7c9b1f7c8ec4fa5d.zip
Merge branch 'master' into mppa_postpass
Conflicts: .gitignore runtime/include/stdbool.h
Diffstat (limited to 'test')
-rw-r--r--test/regression/Makefile2
-rw-r--r--test/regression/Results/aligned12
-rw-r--r--test/regression/aligned.c115
-rw-r--r--test/regression/varargs3.c52
4 files changed, 180 insertions, 1 deletions
diff --git a/test/regression/Makefile b/test/regression/Makefile
index 191a2285..760ee570 100644
--- a/test/regression/Makefile
+++ b/test/regression/Makefile
@@ -23,7 +23,7 @@ TESTS=int32 int64 floats floats-basics \
TESTS_COMP=attribs1 bitfields1 bitfields2 bitfields3 bitfields4 \
bitfields5 bitfields6 bitfields7 bitfields8 \
builtins-$(ARCH) packedstruct1 packedstruct2 alignas \
- varargs1 varargs2 sections alias
+ varargs1 varargs2 varargs3 sections alias aligned
# Can run, both in compiled mode and in interpreter mode,
# but produce processor-dependent results, so no reference output in Results
diff --git a/test/regression/Results/aligned b/test/regression/Results/aligned
new file mode 100644
index 00000000..c42a5c40
--- /dev/null
+++ b/test/regression/Results/aligned
@@ -0,0 +1,12 @@
+a: size 1, offset mod 16 = 0
+b: size 3, offset mod 16 = 0
+c: size is that of a pointer, offset mod 16 is good
+d: size 1, offset mod 16 = 0
+f: size is that of a pointer, offset mod 16 is good
+g: size 32, offset mod 16 = 0
+h: size 16, offset mod 16 = 0
+i: size 16, offset mod 16 = 0
+j: size 16, offset mod 16 = 0
+T2: size 112, alignment 16
+T4: size is that of a pointer, alignment is that of a pointer
+t2: size 9, alignment 1
diff --git a/test/regression/aligned.c b/test/regression/aligned.c
new file mode 100644
index 00000000..bd16d513
--- /dev/null
+++ b/test/regression/aligned.c
@@ -0,0 +1,115 @@
+/* The "aligned" attribute */
+
+#include <stdio.h>
+
+#define ALIGNED __attribute((aligned(16)))
+#define ALIGNED1 __attribute((aligned(1)))
+
+typedef ALIGNED char c16;
+
+struct s {
+ char y;
+ char ALIGNED x;
+};
+
+typedef struct { char y; } ALIGNED u;
+
+struct {
+ char filler1;
+
+ /* Base type */
+ char ALIGNED a;
+ /* Array */
+ /* Expected: array of 3 naturally-aligned chars -> size = 3 */
+ ALIGNED char b[3];
+ /* Pointer */
+ /* Expected: 16-aligned pointer to naturally-aligned char */
+ ALIGNED char * c;
+
+/* Typedef */
+
+ c16 d;
+ /* Expected: like char ALIGNED d */
+ // c16 e[3] = {2, 3, 4};
+ /* Expected: unclear. This one is rejected by gcc.
+ clang says size = 16, alignment = 16, but initializes first 3 bytes only.
+ compcert says size = 3, alignment = 16. */
+ char filler2;
+ c16 * f;
+ /* Expected: naturally-aligned pointer to 16-aligned char */
+
+/* Struct */
+
+ struct s g;
+ /* Expected: alignment 16, size 17
+ (1 byte, padding to mod 16, 1 bytes) */
+
+ char filler3;
+
+ struct t {
+ char y;
+ } ALIGNED h;
+ /* Expected: type struct t and variable h have alignment 16 and size 1 */
+
+ char filler4;
+
+ struct t i;
+ /* Expected: alignment 16 and size 1. This checks that the ALIGNED
+ attribute is attached to "struct t". */
+
+ char filler5;
+
+ u j;
+ /* Expected: type u and variable j have alignment 16 and size 1. */
+} x;
+
+typedef char T1[100];
+
+typedef struct { T1 mess[1]; } ALIGNED T2;
+/* Expected: alignment 16, size 112 = 100 aligned to 16 */
+
+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",
+ msg, sz, (unsigned long) ((char *) addr - (char *) &x) % 16);
+}
+
+void checkptr(const char * msg, void * addr, size_t sz, size_t al)
+{
+ printf("%s: size %s that of a pointer, offset mod 16 %s\n",
+ msg,
+ sz == sizeof(void *) ? "is" : "IS NOT",
+ (((char *) addr - (char *) &x) % 16) == al ?
+ "is good" : "IS BAD");
+}
+
+int main()
+{
+ check("a", &(x.a), sizeof(x.a));
+ check("b", &(x.b), sizeof(x.b));
+ checkptr("c", &(x.c), sizeof(x.c), 0);
+ check("d", &(x.d), sizeof(x.d));
+ checkptr("f", &(x.f), sizeof(x.f), _Alignof(void *));
+ check("g", &(x.g), sizeof(x.g));
+ check("h", &(x.h), sizeof(x.h));
+ check("i", &(x.i), sizeof(x.i));
+ check("j", &(x.j), sizeof(x.j));
+
+ printf("T2: size %zu, alignment %zu\n", sizeof(T2), _Alignof(T2));
+ printf("T4: size %s that of a pointer, alignment %s that of a pointer\n",
+ 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;
+}
diff --git a/test/regression/varargs3.c b/test/regression/varargs3.c
new file mode 100644
index 00000000..a46d81e3
--- /dev/null
+++ b/test/regression/varargs3.c
@@ -0,0 +1,52 @@
+#include <stdarg.h>
+#include <stdio.h>
+
+void initialize(int first, ...)
+{
+ va_list ap;
+ va_start(ap, first);
+ while (1) {
+ int * p = va_arg(ap, int *);
+ if (p == NULL) break;
+ *p = first;
+ first++;
+ }
+}
+
+void test(void)
+{
+ int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
+ initialize(42, &a, &b, &c, &d, &e, &f, &g, &h, &i, &j,
+ &k, &l, &m, &n, &o, &p, &q, NULL);
+ printf("a = %d\n", a);
+ printf("b = %d\n", b);
+ printf("c = %d\n", c);
+ printf("d = %d\n", d);
+ printf("e = %d\n", e);
+ printf("f = %d\n", f);
+ printf("g = %d\n", g);
+ printf("h = %d\n", h);
+ printf("i = %d\n", i);
+ printf("j = %d\n", j);
+ printf("k = %d\n", k);
+ printf("l = %d\n", l);
+ printf("m = %d\n", m);
+ printf("n = %d\n", n);
+ printf("o = %d\n", o);
+ printf("p = %d\n", p);
+ printf("q = %d\n", q);
+}
+
+void wipestack(void)
+{
+ unsigned int b[100];
+ int i;
+ for (i = 0; i < 100; i++) ((volatile unsigned int *)b)[i] = 0xDEADBEEFU;
+}
+
+int main()
+{
+ wipestack();
+ test();
+ return 0;
+}