[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++)
From: |
Dmitry K. |
Subject: |
[avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++) |
Date: |
Tue, 6 Mar 2007 17:25:56 +1000 |
User-agent: |
KMail/1.5 |
Hi,
wrong code by avr-gcc 4.1.1:
Program:
~~~~~~~
/* This program is compiled as endless loop: condition `c1 != 0'
is not tested. In original (real) program there was an another
error: in conditional expression based on c1 and c2 inside the
loops (here this is removed).
Compiler: avr-gcc 4.1.1
Options: -W -Wall -Os -S */
void foo (const char *s1, const char *s2);
int main ()
{
unsigned char c1, c2;
char s1[2] = ".";
char s2[2] = ".";
for (c1 = 1; c1; c1++) {
for (c2 = 1; c2; c2++) {
s1[0] = c1;
s2[0] = c2;
foo (s1, s2);
}
}
return 0;
}
Result:
~~~~~~
...
main:
/* prologue: frame size=4 */
ldi r28,lo8(__stack - 4)
ldi r29,hi8(__stack - 4)
out __SP_H__,r29
out __SP_L__,r28
/* prologue end (size=4) */
lds r24,.LC0
lds r25,(.LC0)+1
std Y+2,r25
std Y+1,r24
std Y+4,r25
std Y+3,r24
ldi r16,lo8(1)
rjmp .L2
.L3:
std Y+1,r16
std Y+3,r17
mov r22,r28
mov r23,r29
subi r22,lo8(-(3))
sbci r23,hi8(-(3))
mov r24,r28
mov r25,r29
adiw r24,1
rcall foo
subi r17,lo8(-(1))
brne .L3
subi r16,lo8(-(1))
.L2:
ldi r17,lo8(1)
rjmp .L3
/* epilogue: frame size=4 */
/* epilogue: noreturn */
Dmitry.
- [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++),
Dmitry K. <=
Re: [avr-gcc-list] Endless loop: uchar c; for (c=1; c; c++), Shaun Jackman, 2007/03/07