This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/14896] New: Fails to generate code for structure field assignment when assigning first field and assignment is within an infinite loop
- From: "aweiner at lsil dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Apr 2004 22:50:20 -0000
- Subject: [Bug c/14896] New: Fails to generate code for structure field assignment when assigning first field and assignment is within an infinite loop
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Version: powerpcle-440-eabi-gcc (GCC) 3.4.0 20040225 (prerelease)
When using the "-Os" compiler option, the optimizer will improperly optimize-
out the assignment of a structure field if that field is the FIRST field within
the structure AND the assignemnt is within an infinite-loop block. Example:
typedef struct {
int a;
int b;
} TEST;
TEST t; /* also fails if 't' is local to foo() */
void foo(void) {
for (;;) { /* while (1) also fails */
t.a = 5;
}
}
Code generated:
00000000 <foo>:
0: 00 00 00 48 b 0 <foo>
Any of the following changes to the above source cause the compiler to generate
the proper code:
* Assign second field ('b') of structure rather than first ('a')
* Move assignemnt outside of "for(;;)" loop
* Access field through pointer rather than instance
* Call to a non-inlined function is made within loop block
* Compile without "-Os"
Below is the compiler output when the second field ('b') is assigned instead of
the first ("t.b = 5" vs. "t.a = 5"):
00000000 <foo>:
0: 00 00 20 3d lis r9,0
4: 05 00 00 38 li r0,5
8: 00 00 29 39 addi r9,r9,0
c: 04 00 09 90 stw r0,4(r9)
10: fc ff ff 4b b c <foo+0xc>
--
Summary: Fails to generate code for structure field assignment
when assigning first field and assignment is within an
infinite loop
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P1
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: aweiner at lsil dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14896