#1343 bit returned in dpl

closed-fixed
5
2013-05-25
2007-06-16
No

The following code still generates code that returns a bit in dpl for the mcs51.

bit Ternary(unsigned char status)
{
return (status == 0) ? 0 : 1;
}

_Ternary:
ar2 = 0x02
ar3 = 0x03
ar4 = 0x04
ar5 = 0x05
ar6 = 0x06
ar7 = 0x07
ar0 = 0x00
ar1 = 0x01
; genReceive
; heaters.c:6: return (status == 0) ? 0 : 1;
; genNot
; peephole 177.g optimized mov sequence
mov a,dpl
mov r2,a
cjne a,#0x01,00105$
00105$:
clr a
rlc a
; genNot
mov r2,a
; Peephole 105 removed redundant mov
cjne a,#0x01,00106$
00106$:
clr a
rlc a
mov dpl,a
; genRet
; Peephole 500 removed redundant label 00101$
ret

Not to mention the unoptimized code.

Discussion

  • Maarten Brock

    Maarten Brock - 2007-06-16
    • milestone: --> 100457
    • status: open --> closed-fixed
     
  • Maarten Brock

    Maarten Brock - 2007-06-16

    Logged In: YES
    user_id=888171
    Originator: YES

    Fixed in SDCC 2.7.2 #4854.

     
  • Maarten Brock

    Maarten Brock - 2007-06-16

    Logged In: YES
    user_id=888171
    Originator: YES

    Seems it was not fixed at all. The following still fails:

    return (status == 0) ? (bit)0 : (bit)1;

     
  • Maarten Brock

    Maarten Brock - 2007-06-16
    • milestone: 100457 -->
    • status: closed-fixed --> open
     
  • Frieder Ferlemann

    Logged In: YES
    user_id=589052
    Originator: NO

    These would fail too:

    return (status == 0) ? 1 : 0;
    return !status ? 1 : 0;
    return status ? 0 : 1;

     
  • Frieder Ferlemann

    to be copied into sdcc/support/regression/tests/

     
  • Frieder Ferlemann

    Logged In: YES
    user_id=589052
    Originator: NO

    I'm attaching a file which allows to reproduce the bug
    within the regression test suite.

    Note, older versions of SDCC (I tested with SDCC 2.7.1 #4827)
    pass the test whereas uptodate versions do not.

    Greetings,
    Frieder
    File Added: bug1738367.c

     
  • Nobody/Anonymous

    Logged In: NO

    SDCC : mcs51 2.7.2 # (Jun 28 2007) (UNIX)
    svn #4870

    still produces incorrect code, for the slightly modified function

    bit foo(char arg) {
    return arg & 1;
    }

    ==>

    0000 E5 82 108 mov a,dpl
    0002 54 01 109 anl a,#0x01
    0004 F5 82 110 mov dpl,a
    0006 22 111 ret

    thus, the function still returns a char in dpl, instead of a bit
    in the carry flag

    greetings,
    Robert Larice

    larice 0x40 vidisys 0x2e de

     
  • Nobody/Anonymous

    Logged In: NO

    i've proposed a patch in the bug track
    [ 1745717 ] bit returned in dpl #2

    it seems that patch works around this bug
    "[ 1738367 ] bit returned in dpl"
    as well

    said patch will pass the regression test file from frief bug1738367.c
    (which is by the way longer and more extensive than another allready contained
    and unfortunatly identically named test file)

    greetings,
    Robert Larice

    larice 0x40 vidisys 0x2e de

     
  • Maarten Brock

    Maarten Brock - 2007-07-11

    Logged In: YES
    user_id=888171
    Originator: YES

    Thanks, your patch indeed fixes both bugs.
    Applied in SDCC 2.7.2 #4879.

     
  • Maarten Brock

    Maarten Brock - 2007-07-11
    • milestone: --> fixed
    • status: open --> closed-fixed
     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks