aboutsummaryrefslogtreecommitdiff
path: root/tests/tests2
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2017-05-06 05:28:13 +0200
committerMichael Matz <matz@suse.de>2017-05-06 05:28:13 +0200
commitff998900b163e96c52a4fefc71736ed34626ed86 (patch)
tree919db5e9a3647e1131ec7bdb4f9e3993f7e7e11a /tests/tests2
parent075723456073bf7319805ce964a3f8a036eb7d27 (diff)
downloadtinycc-ff998900b163e96c52a4fefc71736ed34626ed86.tar.gz
tinycc-ff998900b163e96c52a4fefc71736ed34626ed86.tar.bz2
struct-init: Fix zero initialization with multi-level designators
See the added testcase. When one used designators like .a.x to initialize sub-members of members, and didn't then initialize all of them the required zero-initialization of the other sub-members wasn't done. The fix also enables tiny code cleanups.
Diffstat (limited to 'tests/tests2')
-rw-r--r--tests/tests2/90_struct-init.c34
-rw-r--r--tests/tests2/90_struct-init.expect3
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/tests2/90_struct-init.c b/tests/tests2/90_struct-init.c
index fd212ba..ab33812 100644
--- a/tests/tests2/90_struct-init.c
+++ b/tests/tests2/90_struct-init.c
@@ -217,7 +217,40 @@ void test_multi_relocs(void)
for (i = 0; i < sizeof(table)/sizeof(table[0]); i++)
table[i]();
}
+
+/* Following is from GCC gcc.c-torture/execute/20050613-1.c. */
+struct SEA { int i; int j; int k; int l; };
+struct SEB { struct SEA a; int r[1]; };
+struct SEC { struct SEA a; int r[0]; };
+struct SED { struct SEA a; int r[]; };
+
+static void
+test_correct_filling (struct SEA *x)
+{
+ static int i;
+ if (x->i != 0 || x->j != 5 || x->k != 0 || x->l != 0)
+ printf("sea_fill%d: wrong\n", i);
+ else
+ printf("sea_fill%d: okay\n", i);
+ i++;
+}
+
+int
+test_zero_init (void)
+{
+ /* The peculiarity here is that only a.j is initialized. That
+ means that all other members must be zero initialized. TCC
+ once didn't do that for sub-level designators. */
+ struct SEB b = { .a.j = 5 };
+ struct SEC c = { .a.j = 5 };
+ struct SED d = { .a.j = 5 };
+ test_correct_filling (&b.a);
+ test_correct_filling (&c.a);
+ test_correct_filling (&d.a);
+ return 0;
+}
+
int main()
{
print(ce);
@@ -244,5 +277,6 @@ int main()
//printf("q: %s\n", q);
test_compound_with_relocs();
test_multi_relocs();
+ test_zero_init();
return 0;
}
diff --git a/tests/tests2/90_struct-init.expect b/tests/tests2/90_struct-init.expect
index adda76d..e366121 100644
--- a/tests/tests2/90_struct-init.expect
+++ b/tests/tests2/90_struct-init.expect
@@ -38,3 +38,6 @@ flow: 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0
one
two
three
+sea_fill0: okay
+sea_fill1: okay
+sea_fill2: okay