diff options
| author | Michael Matz <matz@suse.de> | 2017-05-06 05:28:13 +0200 |
|---|---|---|
| committer | Michael Matz <matz@suse.de> | 2017-05-06 05:28:13 +0200 |
| commit | ff998900b163e96c52a4fefc71736ed34626ed86 (patch) | |
| tree | 919db5e9a3647e1131ec7bdb4f9e3993f7e7e11a /tests/tests2/90_struct-init.c | |
| parent | 075723456073bf7319805ce964a3f8a036eb7d27 (diff) | |
| download | tinycc-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/90_struct-init.c')
| -rw-r--r-- | tests/tests2/90_struct-init.c | 34 |
1 files changed, 34 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; } |
