#219 An Issue in genAnd of STM8

None
closed-accepted
None
5
2014-02-19
2014-02-18
Ben Shi
No

It is not a bug, since right code is generated, however, line 4574 - 4586 are problemtical, since the auther's intention is not fullfilled.

For the following 2 functions,

char f1(char a)
{
if (a & 0x80)
return a - 1;
else
return a + 1;
}

unsigned char f2(unsigned char a)
{
if (a & 0x80)
return a - 1;
else
return a + 1;
}

The same serials of code should be generated, but actually not. Since i-code for (unsigned char) a & 0x80 is a & 0x80, but (char ) a & 0x80 is a & 0xffffff80.

So this patch is to fix that.

1 Attachments

Discussion

  • Am 18.02.2014 09:11, schrieb Ben Shi:


    [patches:#219] http://sourceforge.net/p/sdcc/patches/219/ An Issue in
    genAnd of STM8

    Status: open
    Created: Tue Feb 18, 2014 08:11 AM UTC by Ben Shi
    Last Updated: Tue Feb 18, 2014 08:11 AM UTC
    Owner: nobody

    It is not a bug, since right code is generated, however, line 4574 -
    4586 are problemtical, since the auther's intention is not fullfilled.

    For the following 2 functions,

    char f1(char a)
    {
    if (a & 0x80)
    return a - 1;
    else
    return a + 1;
    }

    unsigned char f2(unsigned char a)
    {
    if (a & 0x80)
    return a - 1;
    else
    return a + 1;
    }

    The same serials of code should be generated, but actually not. Since
    i-code for (unsigned char) a & 0x80 is a & 0x80, but (char ) a & 0x80 is
    a & 0xffffff80.

    So this patch is to fix that.

    I see the issue. It seems the path tracker is down, so I couldn't see
    the patch, but did write a fix for the issue anyway. I tested it, it
    seems okay, but I currently can't commit to the svn either.

    Philipp

     
  • I used byteOfVal() instead of ulFromVal() & 0xff.

    Revision #8949 now generates the same code for both functions.

    Philipp

     
    • status: open --> closed-accepted
    • assigned_to: Philipp Klaus Krause
    • Group: -->