[prev in list] [next in list] [prev in thread] [next in thread]
List: pcc-list
Subject: Re: [Pcc] Wrong code generation with anon structs
From: Anders Magnusson <ragge () ludd ! ltu ! se>
Date: 2019-04-14 20:19:39
Message-ID: 163c9256-e368-8c61-0a2a-3f861064fd2b () ludd ! ltu ! se
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
So, fixed now. It was a really simple fix when found; just change the
return variable in one place.
The trick is to keep also anon structs in the init stack to get the
offsets correct.
Thanks for the bug report!
-- Ragge
Den 2019-04-14 kl. 16:58, skrev Anders Magnusson:
> Hi,
>
> Den 2019-04-11 kl. 14:14, skrev Pitr Kaye:
>>
>>
>> Hallo,
>>
>> doing some experiments about compiler support for anon structs, i
>> found an erroneous assignment in pcc
>>
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <string.h>
>>
>>
>> struct a {
>> int x;
>> };
>>
>> struct b {
>> int y;
>> struct a;
>> } p1,p2;
>>
>> struct c {
>> int y;
>> struct a ax;
>> } pc1,pc2;
>>
>>
>> int main() {
>> p1 = (struct b) { .y=5, .x=3 }; // this doesn't work
>> printf("p1.y=%d p1.x=%d\n",p1.y,p1.x);
>> p2 = (struct b) { 5, 3 }; // this works
>> printf("p2.y=%d p2.x=%d\n",p2.y,p2.x);
>>
>> pc1 = (struct c) { .y=5, .ax.x=3 }; // this works
>> printf("pc1.y=%d pc1.x=%d\n",pc1.y,pc1.ax.x);
>> pc2 = (struct c) { 5, 3 }; // this works
>> printf("pc2.y=%d pc2.x=%d\n",pc2.y,pc2.ax.x);
>> }
>>
>>
>> /* output:
>>
>> p1.y=3 p1.x=0 <-- wrong output
>> p2.y=5 p2.x=3
>> pc1.y=5 pc1.x=3
>> pc2.y=5 pc2.x=3
>>
>>
>> */
> This also fails using static init:
>
> struct a {
> int x;
> };
>
> struct b {
> int y;
> struct a;
> } p1 = { .y=5, .x=3 };
>
> which gives the same (wrong) result. Hm, something in the init stack
> setup seems to not work.
> I'll look at it.
>
> -- R
[Attachment #5 (text/html)]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
So, fixed now. It was a really simple fix when found; just change
the return variable in one place.<br>
The trick is to keep also anon structs in the init stack to get the
offsets correct.<br>
<br>
Thanks for the bug report!<br>
<br>
-- Ragge<br>
<br>
<div class="moz-cite-prefix">Den 2019-04-14 kl. 16:58, skrev Anders
Magnusson:<br>
</div>
<blockquote type="cite"
cite="mid:522b68fe-f37f-9021-6a16-224a222e818e@ludd.ltu.se">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Hi,<br>
<br>
<div class="moz-cite-prefix">Den 2019-04-11 kl. 14:14, skrev Pitr
Kaye:<br>
</div>
<blockquote type="cite"
cite="mid:bd7c69b6-2d22-88af-298e-2b4041d61d9b@gmail.com"> <br>
<br>
Hallo, <br>
<br>
doing some experiments about compiler support for anon structs,
i found an erroneous assignment in pcc <br>
<br>
<br>
#include <stdio.h> <br>
#include <stdlib.h> <br>
#include <string.h> <br>
<br>
<br>
struct a { <br>
int x; <br>
}; <br>
<br>
struct b { <br>
int y; <br>
struct a; <br>
} p1,p2; <br>
<br>
struct c { <br>
int y; <br>
struct a ax; <br>
} pc1,pc2; <br>
<br>
<br>
int main() { <br>
p1 = (struct b) { .y=5, .x=3 }; // this doesn't work <br>
printf("p1.y=%d p1.x=%d\n",p1.y,p1.x); <br>
p2 = (struct b) { 5, 3 }; // this works <br>
printf("p2.y=%d p2.x=%d\n",p2.y,p2.x); <br>
<br>
pc1 = (struct c) { .y=5, .ax.x=3 }; // this works <br>
printf("pc1.y=%d pc1.x=%d\n",pc1.y,pc1.ax.x); <br>
pc2 = (struct c) { 5, 3 }; // this works <br>
printf("pc2.y=%d pc2.x=%d\n",pc2.y,pc2.ax.x); <br>
} <br>
<br>
<br>
/* output: <br>
<br>
p1.y=3 p1.x=0 <-- wrong output <br>
p2.y=5 p2.x=3 <br>
pc1.y=5 pc1.x=3 <br>
pc2.y=5 pc2.x=3 <br>
<br>
<br>
*/ <br>
</blockquote>
This also fails using static init:<br>
<br>
<font face="Courier New, Courier, monospace">struct a {<br>
int x;<br>
};<br>
<br>
struct b {<br>
int y;<br>
struct a;<br>
} p1 = { .y=5, .x=3 };</font><br>
<br>
which gives the same (wrong) result. Hm, something in the init
stack setup seems to not work.<br>
I'll look at it.<br>
<br>
-- R<br>
</blockquote>
<br>
</body>
</html>
[Attachment #6 (text/plain)]
_______________________________________________
Pcc mailing list
Pcc@lists.ludd.ltu.se
https://lists.ludd.ltu.se/cgi-bin/mailman/listinfo/pcc
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic