Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppci-cc: wrong initialization of nested structs #79

Closed
tstreiff opened this issue Jun 9, 2020 · 6 comments
Closed

ppci-cc: wrong initialization of nested structs #79

tstreiff opened this issue Jun 9, 2020 · 6 comments
Assignees
Labels

Comments

@tstreiff
Copy link
Contributor

tstreiff commented Jun 9, 2020

With the following declarations:

struct S1 {
int a;
int b;
};

struct S2 {
int a;
int b;
union {
int c;
int d;
};
struct S1 s;
};

struct S2 v = {1, 2, 3, {4, 5}};

v.a is 1, v.b is 2, v.c and v.d are 3, but v.s.a and v.s.b contains garbage.

@windelbouwman
Copy link
Owner

This is correct, right, since the union has superfluous initializers, and the last 5 is discarded. What do you expect here?

@tstreiff
Copy link
Contributor Author

We should get:
v.a = 1, v.b = 2, v.c (and v.d which memory with v.c) = 3, v.s.a = 4, v.s.b = 5

@windelbouwman
Copy link
Owner

Ah, yes, I see, sorry, I misread the example, you are absolutely right here!

@windelbouwman
Copy link
Owner

My fear was that the parsing and semantics was wrong, but actually it was a simple fix in the codegenerator for this code. See commit 81b66a1

Example 00050.c now passes.

@windelbouwman
Copy link
Owner

@tstreiff do you think this bug can be closed?

@tstreiff
Copy link
Contributor Author

Yes, the test is now OK!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants