From a9a6d92cbf3371de82aa81595564c23986b4da89 Mon Sep 17 00:00:00 2001 From: xleroy Date: Sat, 17 Apr 2010 07:41:39 +0000 Subject: __builtin_memcpy, continued. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1320 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- test/regression/Results/struct7 | 4 +++ test/regression/Results/struct8 | 2 ++ test/regression/struct7.c | 59 +++++++++++++++++++++++++++++++++++++++++ test/regression/struct8.c | 23 ++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 test/regression/Results/struct7 create mode 100644 test/regression/Results/struct8 create mode 100644 test/regression/struct7.c create mode 100644 test/regression/struct8.c (limited to 'test/regression') diff --git a/test/regression/Results/struct7 b/test/regression/Results/struct7 new file mode 100644 index 00000000..ae630bf1 --- /dev/null +++ b/test/regression/Results/struct7 @@ -0,0 +1,4 @@ +A2 = { 1234, 3.141590, { 'H', ... , 'o' } } +B2 = { 1, ..., 5, ..., 0 } +C2.c = 'z' +D2.v = { 0, ..., 4, ..., 0 } diff --git a/test/regression/Results/struct8 b/test/regression/Results/struct8 new file mode 100644 index 00000000..a2151938 --- /dev/null +++ b/test/regression/Results/struct8 @@ -0,0 +1,2 @@ +a = { 123, 2.718000, 'a' } +b = { 125, 5.436000, 'f' } diff --git a/test/regression/struct7.c b/test/regression/struct7.c new file mode 100644 index 00000000..136602bf --- /dev/null +++ b/test/regression/struct7.c @@ -0,0 +1,59 @@ +/* Assignment between structs and unions */ + +#include + +struct small { + int x; + double d; + char c[5]; +}; + +struct big { + int x[100]; +}; + +union u1 { + char c; + short s; +}; + +union u2 { + struct small u; + struct big v; +}; + +struct small A = { 1234, 3.14159, { 'H', 'e', 'l', 'l', 'o' }}; +struct big B = { 1, 2, 3, 4, 5 }; +union u1 C; +union u2 D; + +int main() +{ + struct small A2; + struct big B2; + union u1 C2; + union u2 D2; + int i; + + C.c = 'z'; + for (i = 0; i < 99; i++) D.v.x[i] = i; + + A2 = A; + printf("A2 = { %d, %f, { '%c', ... , '%c' } }\n", + A2.x, A2.d, A2.c[0], A2.c[4]); + + B2 = B; + printf("B2 = { %d, ..., %d, ..., %d }\n", + B2.x[0], B2.x[4], B2.x[99]); + + C2 = C; + printf("C2.c = '%c'\n", C2.c); + + D2 = D; + printf("D2.v = { %d, ..., %d, ..., %d }\n", + D2.v.x[0], D2.v.x[4], D2.v.x[99]); + + return 0; +} + + diff --git a/test/regression/struct8.c b/test/regression/struct8.c new file mode 100644 index 00000000..989c3524 --- /dev/null +++ b/test/regression/struct8.c @@ -0,0 +1,23 @@ +/* Passing structs by value */ + +#include + +struct S { int x; double d; char c; }; + +struct S f(struct S s, int scale) +{ + struct S r; + r.x = s.x + scale; + r.d = s.d * scale; + r.c = 'f'; + return r; +} + +int main() +{ + struct S a = { 123, 2.718, 'a' }; + struct S b = f(a, 2); + printf("a = { %d, %f, '%c' }\n", a.x, a.d, a.c); + printf("b = { %d, %f, '%c' }\n", b.x, b.d, b.c); + return 0; +} -- cgit