#1181 Bad code generated for *x = 0 where x is an xdata short ptr

closed-fixed
5
2013-05-25
2006-08-08
No

sdcc svn4321, command line:
sdcc -c -mmcs51 --model-small --debug -I. --xram-size
1024 --code-size 16384 -o t.rel t.c

See the attached test case. I could not slim it down
more, as removing any of the remaining element
apparently causes the register pressure to drop to
the point where this bug is not exhibited.

The problem lies in the s.c->s = 0; statement, where
the compiler stomps itself over the dptr (dpl)
register.

119 ; t.c:26:
s.c->s = 0;
120 ; genAssign
121 ; genPlus
0008 90s00r00 122 mov
dptr,#_s
000B E0 123 movx
a,@dptr
000C 24 03 124 add
a,#0x03
000E F5 82 125 mov dpl,a
0010 A3 126 inc dptr
0011 E0 127 movx
a,@dptr
0012 34 00 128 addc
a,#0x00
0014 F5 83 129 mov dph,a
130 ; genPointerSet
131 ;
genFarPointerSet
132 ; Peephole 181
changed mov to clr
0016 E4 133 clr a
0017 F0 134 movx
@dptr,a

Discussion

  • Thomas Sailer

    Thomas Sailer - 2006-08-08

    Testcase

     
  • Thomas Sailer

    Thomas Sailer - 2006-08-08

    Logged In: YES
    user_id=976704

    actually, on closer inspection, sdcc even confuses address
    spaces, _s is supposed to be in internal memory, but sdcc
    tries to access _s+1 with movx.

     
  • Frieder Ferlemann

    to be copied into support/regression/tests/

     
  • Frieder Ferlemann

    Logged In: YES
    user_id=589052
    Originator: NO

    the attached file "bug1536762.c" allows
    to reproduce the bug within the regression
    test suite.

    Targets mcs51, mcs51-stack-auto and
    mcs51-xstack-auto fail.

    File Added: bug1536762.c

     
  • Robert Larice

    Robert Larice - 2007-07-16

    Logged In: YES
    user_id=1840151
    Originator: NO

    For debugging purpose, the offending piece of c
    can be reduced to :

    ---------------------------------------

    struct d { char dummy, element; };

    struct ma { xdata struct d *ptr;} glo;

    void blurb() {
    glo.ptr->element = 0;
    }

    ---------------------------------------

    compilation with
    sdcc #4882 options "-c -mmcs51" results in

    ; bug-10.c:14: glo.ptr->element = 0;
    mov dptr,#_glo
    movx a,@dptr
    add a,#0x01
    mov dpl,a
    inc dptr
    movx a,@dptr
    addc a,#0x00
    mov dph,a
    clr a
    movx @dptr,a
    ret

    which overwrites dpl with a new value, though dptr is
    still needed.

    -----------------------------------

    option --dumpall reveals:

    dumppack:

    (l12:s1:k0:d0:s0) _entry($2) :
    (l12:s2:k1:d0:s0) proc _blurb [k1 lr0:0 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{void function ( ) }
    (l14:s3:k2:d0:s0) iTemp0 [k3 lr3:4 so:0]{ ia0 a2p0 re0 rm1 nos0 ru0 dp0}{struct d xdata* near* } = &[_glo [k2 lr0:0 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{struct ma}]
    (l14:s4:k4:d0:s0) iTemp2 [k6 lr4:5 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{struct d xdata* } = @[iTemp0 [k3 lr3:4 so:0]{ ia1 a2p0 re0 rm1 nos0 ru0 dp0}{struct d xdata* near* }]
    (l14:s5:k5:d0:s0) iTemp3 [k8 lr5:6 so:0]{ ia1 a2p0 re0 rm0 nos0 ru1 dp0}{char xdata* } = iTemp2 [k6 lr4:5 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{struct d xdata* } + 0x1 {literal-unsigned-char}
    (l14:s6:k6:d0:s0) *(iTemp3 [k8 lr5:6 so:0]{ ia1 a2p0 re0 rm0 nos0 ru1 dp0}{char xdata* }) := 0x0 {literal-char}

    but dumprassgn is

    (l12:s1:k0:d0:s0) _entry($2) :
    (l12:s2:k1:d0:s0) proc _blurb [k1 lr0:0 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{void function ( ) }
    (l14:s3:k2:d0:s0) iTemp0 [k3 lr3:4 so:0]{ ia0 a2p0 re0 rm1 nos0 ru0 dp0}{struct d xdata* near* }[remat] = &[_glo [k2 lr0:0 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{struct ma}]
    (l14:s4:k4:d0:s0) iTemp2 [k6 lr4:5 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{struct d xdata* }{ sir@ _glo} := iTemp2 [k6 lr4:5 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{struct d xdata* }{ sir@ _glo}
    (l14:s5:k5:d0:s0) iTemp3 [k8 lr5:6 so:0]{ ia1 a2p0 re0 rm0 nos0 ru1 dp0}{char xdata* } = iTemp2 [k6 lr4:5 so:0]{ ia0 a2p0 re0 rm0 nos0 ru0 dp0}{struct d xdata* }{ sir@ _glo} + 0x1 {literal-unsigned-char}
    (l14:s6:k6:d0:s0) *(iTemp3 [k8 lr5:6 so:0]{ ia1 a2p0 re0 rm0 nos0 ru1 dp0}{char xdata* }) := 0x0 {literal-char}

    the iTemp2 := iTemp2 looks a bit strange.
    and i can't see register allokation

    ------------------------------------------------------------

    in src/mcs51/ralloc.c, funktion static void regTypeNum (eBBlock *ebbs)
    i see the following snipplet

    /* if the symbol has only one definition &
    that definition is a get_pointer */

    if (bitVectnBitsOn (sym->defs) == 1 &&
    (ic = hTabItemWithKey (iCodehTab,
    bitVectFirstBit (sym->defs))) &&
    POINTER_GET (ic) &&
    !IS_BITVAR (sym->etype) &&
    (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER))
    {
    if (ptrPseudoSymSafe (sym, ic))
    {
    ptrPseudoSymConvert (sym, ic, rematStr (OP_SYMBOL (IC_LEFT (ic))));
    continue;
    }

    /* if in data space or idata space then try to
    allocate pointer register */
    }

    -------------

    if i force the predicate
    ptrPseudoSymSafe()
    to return FALSE, then correct code is produced

    -------------

    Robert Larice

     
  • Maarten Brock

    Maarten Brock - 2008-03-04

    Logged In: YES
    user_id=888171
    Originator: NO

    Fixed in SDCC 2.7.5 #5067.

     
  • Maarten Brock

    Maarten Brock - 2008-03-04
    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Maarten Brock

    Maarten Brock - 2008-03-04
    • assigned_to: nobody --> maartenbrock
     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks