#812 Problem with pointers as arguments

closed-fixed
None
5
2013-05-25
2004-09-17
No

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

Discussion

  • Erik Petrich

    Erik Petrich - 2004-09-19
    • status: open --> closed
     
  • Erik Petrich

    Erik Petrich - 2004-09-19
    • labels: 608414 -->
    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: closed --> closed-fixed
     
  • Erik Petrich

    Erik Petrich - 2004-09-19

    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)

     
  • Vangelis Rokas

    Vangelis Rokas - 2004-09-19

    Logged In: YES
    user_id=770505

    Thanks Erik. I thought initially that this might have been a
    problem in the live range estimator. But it was elsewhere.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks