From: SourceForge.net <no...@so...> - 2004-09-19 01:16:15
|
Bugs item #1029883, was opened at 2004-09-17 08:51 Message generated for change (Comment added) made by epetrich You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1029883&group_id=599 >Category: None >Group: fixed >Status: Closed >Resolution: Fixed Priority: 5 Submitted By: ccsporters (tecodev) >Assigned to: Erik Petrich (epetrich) Summary: Problem with pointers as arguments Initial Comment: Have a look at: void test1(unsigned int a) { } void test2(unsigned int * a) { } int test(signed int target) { test1(target); test2(&target); return target; } The resulting asm code for test (pic16, but may be a general problem) is: ************************************** _test: #LINE 13; reftest.c test(signed int target) MOVFF FSR2L, POSTDEC1 MOVFF FSR1L, FSR2L MOVFF r0x00, POSTDEC1 MOVFF r0x01, POSTDEC1 ;;ic:3: _test_target_1_1 [...]{...}{int} = recv BANKSEL (_test_target_1_1 + 1) MOVWF (_test_target_1_1 + 1), B MOVLW 0x02 MOVFF PLUSW2, _test_target_1_1 ;;ic:4: iTemp0 [.. lr4:10 ..]{...}{unsigned-int}{ sir@ <_test_target_1_1}[r0x00 r0x01 ] := _test_target_1_1 [...]{...}{int} #LINE 15; reftest.c test1(target); MOVFF _test_target_1_1, r0x00 MOVFF (_test_target_1_1 + 1), r0x01 ;;ic:5: send iTemp0 [...]{...}{unsigned-int}{ sir@ _test_target_1_1}[r0x00 r0x01 ]{argreg = 1} ;;ic:6: iTemp1 [...]{...}{void} = call _test1 [...]{...}{void function ( unsigned-int) } MOVF r0x00, W MOVWF POSTDEC1 MOVF r0x01, W CALL _test1 MOVLW 0x01 ADDWF FSR1L, F ;;ic:7: iTemp2 [...]{...}{int near* }[remat] = &[_test_target_1_1 [...]{...}{int}] ;;ic:8: send iTemp2 [...]{...}{int near* }[remat]{argreg = 1} ;;ic:9: iTemp4 [...]{...}{void} = call _test2 [...]{...}{void function ( unsigned-int generic* ) } #LINE 16; reftest.c test2(&target); MOVLW LOW(_test_target_1_1) MOVWF POSTDEC1 MOVLW HIGH(_test_target_1_1) CALL _test2 MOVLW 0x01 ADDWF FSR1L, F ;;ic:10: ret iTemp0 [.. lr4:10 ..]{...}{unsigned-int}{ sir@ _test_target_1_1}[r0x00 r0x01 ] #LINE 17; reftest.c return target; MOVFF r0x01, PRODL MOVF r0x00, W ;;ic:11: _return($1) : ;;ic:12: eproc _test [...]{...}{int function ( int) } MOVFF PREINC1, r0x01 MOVFF PREINC1, r0x00 MOVFF PREINC1, FSR2L RETURN ************************************** Result: Instead of returning the value of "target", sdcc thinks it can reuse the old target and ignores the possibility that test2 changes "target". But: everything works fine if variable and parameter are of the same type (twice signed int or twice unsigned int) or if target is global. We included the iCode output because the life range of (ic:4) [lr4:10] seems to be a bit too long. Why not [lr:4:9]? SDCC : pic16 2.4.3 #843 (Sep 16 2004) (UNIX) called with: sdcc -mpic16 -p18f452 --no-crt Raphael Neider & Daniel Winkler ---------------------------------------------------------------------- >Comment By: Erik Petrich (epetrich) Date: 2004-09-18 20:16 Message: Logged In: YES user_id=635249 This was a GCSE problem common to all ports. Fixed with src/SDCCcse.c 1.96 and src/SDCCcse.h 1.11 (SDCC 2.4.4 #845) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1029883&group_id=599 |