|
| 1 | + |
| 2 | +/* test struct assignment, of structs with a length of 3, which happen to be |
| 3 | + a special case eg when passing/returning structs |
| 4 | + related to bugs #2022, #2079 */ |
| 5 | + |
| 6 | +#include <stdio.h> |
| 7 | +#include <stdlib.h> |
| 8 | + |
| 9 | +int failures = 0; |
| 10 | + |
| 11 | +struct foo { char a; char b; char c; }; |
| 12 | +struct foo foo, bar; |
| 13 | +void f3(void) |
| 14 | +{ |
| 15 | + foo.a = 6; |
| 16 | + foo.b = 6; |
| 17 | + foo.c = 6; |
| 18 | + bar.a = 1; |
| 19 | + bar.b = 2; |
| 20 | + bar.c = 3; |
| 21 | + foo = bar; |
| 22 | + printf("%d %d %d, %d %d %d (1,2,3 1,2,3)\n", |
| 23 | + foo.a, foo.b, foo.c, |
| 24 | + bar.a, bar.b, bar.c); |
| 25 | + if ((foo.a != 1) || (foo.b != 2) || (foo.c != 3) || |
| 26 | + (bar.a != 1) || (bar.b != 2) || (bar.c != 3)) { |
| 27 | + failures++; |
| 28 | + } |
| 29 | + foo.a = 3; |
| 30 | + foo.b = 2; |
| 31 | + foo.c = 1; |
| 32 | + printf("%d %d %d, %d %d %d (3,2,1 1,2,3)\n", |
| 33 | + foo.a, foo.b, foo.c, |
| 34 | + bar.a, bar.b, bar.c); |
| 35 | + if ((foo.a != 3) || (foo.b != 2) || (foo.c != 1) || |
| 36 | + (bar.a != 1) || (bar.b != 2) || (bar.c != 3)) { |
| 37 | + failures++; |
| 38 | + } |
| 39 | + bar.a = 5; |
| 40 | + bar.b = 6; |
| 41 | + bar.c = 7; |
| 42 | + printf("%d %d %d, %d %d %d (3,2,1 5,6,7)\n", |
| 43 | + foo.a, foo.b, foo.c, |
| 44 | + bar.a, bar.b, bar.c); |
| 45 | + if ((foo.a != 3) || (foo.b != 2) || (foo.c != 1) || |
| 46 | + (bar.a != 5) || (bar.b != 6) || (bar.c != 7)) { |
| 47 | + failures++; |
| 48 | + } |
| 49 | + bar = foo; |
| 50 | + foo.a = 6; |
| 51 | + foo.b = 6; |
| 52 | + foo.c = 6; |
| 53 | + printf("%d %d %d, %d %d %d (6,6,6 3,2,1)\n", |
| 54 | + foo.a, foo.b, foo.c, |
| 55 | + bar.a, bar.b, bar.c); |
| 56 | + if ((foo.a != 6) || (foo.b != 6) || (foo.c != 6) || |
| 57 | + (bar.a != 3) || (bar.b != 2) || (bar.c != 1)) { |
| 58 | + failures++; |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +int main(void) |
| 63 | +{ |
| 64 | + f3(); |
| 65 | + return failures; |
| 66 | +} |
0 commit comments