From: SourceForge.net <no...@so...> - 2007-04-14 23:13:50
|
Bugs item #1292721, was opened at 2005-09-16 11:30 Message generated for change (Comment added) made by spth You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1292721&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: z80 port Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Thomas Tensi (ttensi) Assigned to: Nobody/Anonymous (nobody) Summary: variable load wrongly optimized away Initial Comment: Dear all, I am not sure if this is Z80 port related at all, but for the following code SDCC#1076 produces wrong code: ==================== #include <string.h> typedef unsigned char UINT8; typedef signed char INT8; void globalReplace (char *st, char *pattern, char *replacement) /* replaces all occurrences of <pattern> in <st> by <replacement> */ { UINT8 replacementLength = strlen(replacement); INT8 shiftOffset = replacementLength - strlen(pattern); for (;;) { /* find the first position of pattern */ char *ptr = strstr(st, pattern); if (ptr == NULL) { break; } else { /* do an in-place character shift by shiftOffset */ if (shiftOffset == 0) { /* no shift */ } else { ... } ... } ... } ... } ==================== The Z80 assembler code (with the i-code wrapped around for clarity) looks like this: ==================== ;sdcc-bug3.c:17: if (ptr == NULL) { ; ;ic:20: iTemp12 [k22 lr19:20 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0} ; {char} = iTemp8 [k15 lr18:50 so:0]{ ia0 a2p0 re1 rm0 nos0 ; ru0 dp0}{char generic* }{ sir@ _globalReplace_ptr_2_2} ; [_globalReplace_ptr_2_2] == 0x0 {void literal- generic* } ; ; genCmpEq ; AOP_STK for _globalReplace_ptr_2_2 ; genCmpEq: left 2, right 2, result 0 ld a,-4(ix) or a,-3(ix) jp z,00113$ 00121$: ;ic:21: if iTemp12 [k22 lr19:20 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{char} != 0 goto _return($13) ;sdcc-bug3.c:21: if (shiftOffset == 0) { ; ;ic:28: if iTemp13 [k23 lr13:52 so:0]{ ia0 a2p0 re0 rm0 ; nos0 ru0 dp0}{char} != 0 goto _ifend_1($6) ; ; genIfx or a,a jp nz,00106$ ==================== This means that the variable <shiftOffset> is not loaded, but the compiler seems to assume it is already in the accumulator. Any ideas on that? Best regards Thomas ---------------------------------------------------------------------- Comment By: Philipp Krause (spth) Date: 2007-04-15 01:13 Message: Logged In: YES user_id=564030 Originator: NO I can not reproduce this problem in sdcc 2.6.5 #4749. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1292721&group_id=599 |