aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/struct12.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2015-07-08 11:42:39 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2015-07-08 11:42:39 +0200
commitf869da75c970aec78975f7154c806f29e3012b7a (patch)
tree32bd1fc3fc05e51d7d339956b04196f80e0f2116 /test/regression/struct12.c
parent3eb2b3b7bb464d9844f7c161fbcff53f597348b9 (diff)
downloadcompcert-kvx-f869da75c970aec78975f7154c806f29e3012b7a.tar.gz
compcert-kvx-f869da75c970aec78975f7154c806f29e3012b7a.zip
Turn off copy optimization when returning a composite by reference.
The copy optimization is not correct in case of overlap between destination and source. We would need to use an hypothetical __builtin_memmove_aligned that can cope with overlap to implement the copy at return of callee.
Diffstat (limited to 'test/regression/struct12.c')
-rw-r--r--test/regression/struct12.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/regression/struct12.c b/test/regression/struct12.c
new file mode 100644
index 00000000..39e62b28
--- /dev/null
+++ b/test/regression/struct12.c
@@ -0,0 +1,39 @@
+/* This is was originally a regression test for bug 43784 of gcc.
+ See ISO/IEC 9899:TC3 ยง6.8.6.4p4 and footnote 139. */
+
+#include <stdio.h>
+
+struct s {
+ unsigned char a[256];
+};
+union u {
+ struct { struct s b; int c; } d;
+ struct { int c; struct s b; } e;
+};
+
+static union u v;
+static struct s *p = &v.d.b;
+static struct s *q = &v.e.b;
+
+static struct s __attribute__((noinline)) rp(void)
+{
+ return *p;
+}
+
+static void qp(void)
+{
+ *q = rp();
+}
+
+int main()
+{
+ int i;
+ for (i = 0; i < 256; i++)
+ p->a[i] = i;
+ qp();
+ for (i = 0; i < 256; i++)
+ if (q->a[i] != i)
+ printf("ERROR at %d: %d\n", i, q->a[i]);
+ return 0;
+}
+