From: SourceForge.net <no...@so...> - 2004-04-23 05:52:37
|
Bugs item #777768, was opened at 2003-07-25 14:45 Message generated for change (Comment added) made by epetrich You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=777768&group_id=599 Category: msc51(8051) target >Group: fixed >Status: Closed >Resolution: Fixed Priority: 5 Submitted By: Josef Pavlik (jetset) >Assigned to: Erik Petrich (epetrich) Summary: compiler makes buggy code for 8051 Initial Comment: Hello, I found that the compiler makes bad code in some situation. The following piece of asm result describes the situation. You can found entire source code in the attachment. $sdcc --version SDCC : mcs51/gbz80/z80/avr/ds390/pic14/pic16/TININative/xa51/ds400 2.3.5 (Jul 25 2003) (UNIX) $sdcc bug_xor.c -c bug_xor.asm: ;bug_xor.c:145: *(data unsigned int*)(&msg[2])^=x; ; genAssign ; genXor mov a,0x0001 + _msg xrl a,0x0002 + _msg mov r2,a mov a,(0x0001 + _msg + 1) xrl a,(0x0002 + _msg + 1) mov r3,a ; genPointerSet ; genNearPointerSet ; genDataPointerSet mov (_msg + 0x0002),r2 mov ((_msg + 0x0002) + 1),r3 ---------------------------------------------------------------------- >Comment By: Erik Petrich (epetrich) Date: 2004-04-23 00:52 Message: Logged In: YES user_id=635249 Fixed; see ChangeLog 1.711 for the list of updated files ---------------------------------------------------------------------- Comment By: Bernhard Held (bernhardheld) Date: 2003-07-25 17:07 Message: Logged In: YES user_id=203539 Thanks for the short report :-> These 11 lines ar enough to expose the problem: char msg[3]; int foo (void) { int x; x=*(data int *)(&msg[1]); *(data int *)(&msg[0])^=x; return x; } I'm not sure, if SDCC is guilty with all these typecasts from (char *) to (int *), but I'll think about it. > This occures when msg is declared as volatile too. Here SDCC's behaviour is correct. Define x as volatile, and it'll work as you expect. ---------------------------------------------------------------------- Comment By: Josef Pavlik (jetset) Date: 2003-07-25 15:32 Message: Logged In: YES user_id=756222 in the meantime I found the origin of the problem. The compiler tries to optimize the following sequence x=msg[1]; //some code in the middle msg[1]^=x; to msg[1]^=msg[1]; the problem is that the code in the middle changes the array msg This occures when msg is declared as volatile too. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=777768&group_id=599 |